Boost logo

Boost Users :

From: lloyd.reed_at_[hidden]
Date: 2005-02-04 10:10:42


I have found a bug or undocumented limitation in the boost serialization
library.

I'm using VC++ 2003, which allows you to use variable names which include
dollar signs ($).

Variables with names containing dollar signs can be saved to an archive
using the boost::archive::xml_oarchive class.

When boost::archive::xml_iarchive is used to reload the variable, however,
the parsing of the variable name fails, and
basic_xml_iarchive<Archive>::load_start(const char *name) calls
boost::throw_exception( archive_exception(archive_exception::stream_error)
).

For example,

std::string filename( "C:\\dollar.txt" );
int $(0);
{
      std::ofstream archive_file( filename.c_str() );
      if( archive_file.good() )
      {
            boost::archive::xml_oarchive output_archive(archive_file);
            output_archive << BOOST_SERIALIZATION_NVP( $ );
      }
}

produces the following file:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="3">
<$>0</$>
</boost_serialization>

but trying to load the file causes a boost::archive::archive_exception to
be thrown:

{
      std::ifstream archive_file( filename.c_str() );
      if( archive_file.good() )
      {
            boost::archive::xml_iarchive input_archive(archive_file);
            input_archive >> BOOST_SERIALIZATION_NVP( $ ); // throws
      }
}

I think the spirit definitions for the names of variables are in
C:\boost_1_32_0\libs\serialization\src\basic_xml_grammar.ipp and
C:\boost_1_32_0\libs\serialization\src\xml_grammar.cpp.

Name = (Letter | '_' | ':') >> *(NameChar);

and

template<>
void xml_grammar::init_chset(){
    Char = chset_t("\x9\xA\xD\x20-\xFF");
    Letter = chset_t("\x41-\x5A\x61-\x7A\xC0-\xD6\xD8-\xF6\xF8-\xFF");
    Digit = chset_t("0-9");
    Extender = chset_t('\xB7');
    Sch = chset_t("\x20\x9\xD\xA");
    NameChar = Letter | Digit | chset_p("._:-") | Extender ;
}

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net