serialization, 1.34/1.35 difference: serializing a vector
I just tried serializing a simple vector, std::vector<unsigned int> vectortest; If I serialize out in 1.34, I can't read it in in 1.35. xml result from 1.35: <vectortest> <count>3</count> <item>1</item> <item>2</item> <item>3</item> </vectortest> from 1.34: <vectortest> <count>3</count> <item_version>0</item_version> <item>1</item> <item>2</item> <item>3</item> </vectortest> Notice the item_version, this causes an exception when reading it in with 1.35.... I need a way to get the behavior from 1.34 back.... Otherwise my files aren't readable anymore. small testprogram: #include <boost/config.hpp> #include <boost/archive/xml_oarchive.hpp> #include <boost/archive/xml_iarchive.hpp> //#include <boost/archive/binary_iarchive.hpp> //#include <boost/archive/binary_oarchive.hpp> #include <boost/serialization/vector.hpp> #include <boost/serialization/export.hpp> #include <fstream> #include <iomanip> int _tmain(int argc, _TCHAR* argv[]) { std::vector<unsigned int> testvector; testvector.push_back(1.); testvector.push_back(2.); testvector.push_back(3.); //this in 1.34 std::ofstream ofs( "testing2.txt", std::ios::binary ) ; boost::archive::xml_oarchive oa(ofs); oa << boost::serialization::make_nvp("vectortest", testvector); ofs.close(); //do this in 1.35 try{ std::ifstream ofs( "testing2.txt", std::ios::binary ) ; boost::archive::xml_iarchive ia(ofs); ia >> boost::serialization::make_nvp("vectortest", testvector2); ofs.close(); } catch(boost::archive::archive_exception testexception){ //reading a file from 1.34, will end up here std::string error = testexception.what(); } return 0; } ____________________________________________________________________________________ You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost. http://tc.deals.yahoo.com/tc/blockbuster/text5.com
Hmm I don't recal where that might have come from. Open a TRAK item. Robert Ramey "Filip Peters" <filippeters@yahoo.com> wrote in message news:859190.51711.qm@web30705.mail.mud.yahoo.com... I just tried serializing a simple vector, std::vector<unsigned int> vectortest; If I serialize out in 1.34, I can't read it in in 1.35. xml result from 1.35: <vectortest> <count>3</count> <item>1</item> <item>2</item> <item>3</item> </vectortest> from 1.34: <vectortest> <count>3</count> <item_version>0</item_version> <item>1</item> &n bsp; <item>2</item> <item>3</item> </vectortest> Notice the item_version, this causes an exception when reading it in with 1.35.... I need a way to get the behavior from 1.34 back.... Otherwise my files aren't readable anymore. small testprogram: #include <boost/config.hpp> #include <boost/archive/xml_oarchive.hpp> #include <boost/archive/xml_iarchive.hpp> //#include <boost/archive/binary_iarchive.hpp> //#include <boost/archive/binary_oarchive.hpp> #include <boost/serialization/vector.hpp> #include <boost/serialization/export.hpp> #include <fstream> #include <iomanip> int _tmain(int argc, _TCHAR* argv[]) { std::vector<unsigned int> testvector; testvector.push_back(1.); testvector.push_back (2.); testvector.push_back(3.); //this in 1.34 std::ofstream ofs( "testing2.txt", std::ios::binary ) ; boost::archive::xml_oarchive oa(ofs); oa << boost::serialization::make_nvp("vectortest", testvector); ofs.close(); //do this in 1.35 try{ std::ifstream ofs( "testing2.txt", std::ios::binary ) ; boost::archive::xml_iarchive ia(ofs); ia >> boost::serialization::make_nvp("vectortest", testvector2); ofs.close(); } catch(boost::archi ve::archive_exception testexception){ //reading a file from 1.34, will end up here std::string error = testexception.what(); } return 0; } You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I just ran some tests on Windows, and I can confirm the problem. Here is output from serialization of an std::vector<X*> where the class X has an empty serialization function. Boost 1.34.1: <v class_id="0" tracking_level="0" version="0"> <count>2</count> <item_version>0</item_version> <item class_id="1" tracking_level="1" version="0" object_id="_0"></item> <item class_id_reference="1" object_id="_1"></item> </v> Boost 1.35: <v class_id="0" tracking_level="0" version="0"> <count>2</count> <item class_id="1" tracking_level="1" version="0" object_id="_0"></item> <item class_id_reference="1" object_id="_1"></item> </v> This is a *major problem* for us, because we will release a new version of our app soon. The app has "Export" and "Import" functions that are implemented using Boost.Serialization. It is required that files that have been exported with one version of our app can be imported with a later version. Is there a patch for this problem yet? Thank you, Johan Råde
Johan Råde wrote:
I just ran some tests on Windows, and I can confirm the problem. [snip]
This is a *major problem* for us, because we will release a new version of our app soon. The app has "Export" and "Import" functions that are implemented using Boost.Serialization. It is required that files that have been exported with one version of our app can be imported with a later version.
Is there a patch for this problem yet?
Have you considered writing a patch yourself (or paying someone else to do it?) -- Sohail Somani http://uint32t.blogspot.com
Sohail Somani wrote:
Johan Råde wrote:
I just ran some tests on Windows, and I can confirm the problem. [snip]
This is a *major problem* for us, because we will release a new version of our app soon. The app has "Export" and "Import" functions that are implemented using Boost.Serialization. It is required that files that have been exported with one version of our app can be imported with a later version.
Is there a patch for this problem yet?
Have you considered writing a patch yourself (or paying someone else to do it?)
How much do you want? --Johan
Johan Råde wrote:
I just ran some tests on Windows, and I can confirm the problem. Here is output from serialization of an std::vector<X*> where the class X has an empty serialization function.
Boost 1.34.1:
<v class_id="0" tracking_level="0" version="0"> <count>2</count> <item_version>0</item_version> <item class_id="1" tracking_level="1" version="0" object_id="_0"></item> <item class_id_reference="1" object_id="_1"></item> </v>
Boost 1.35:
<v class_id="0" tracking_level="0" version="0"> <count>2</count> <item class_id="1" tracking_level="1" version="0" object_id="_0"></item> <item class_id_reference="1" object_id="_1"></item> </v>
This is a *major problem* for us, because we will release a new version of our app soon. The app has "Export" and "Import" functions that are implemented using Boost.Serialization. It is required that files that have been exported with one version of our app can be imported with a later version.
Is there a patch for this problem yet?
Thank you, Johan Råde
Does anyone know if the problem can be fixed by just replacing the file serialization/vector.hpp in Boost 1.35 with the Boost 1.34.1 version (but keeping the rest of 1.35)? --Johan
I looked into this it looks as thought the issue is occuring in collections_load_imp.hpp where the library version returned from .get_library_version() does not return a value greater than 3.... or never gets called. So in our case when loading a serialized vector item version is never deserialized even though it is in the incoming message. I also had one of our guys (my laptop died... long story) try calling "set_library_version(unsigned int archive_library_version);" from basic_iarchive on the archive such as ia.set_library_version(4) and I believe this crashed the app with and exception. I will try this workaround once my laptop is back as temporary work around for others until this gets fixed may be a good alternative to a patch. Hopfully a fix will be there by the time my laptop is resurrected. inline void load_collection(Archive & ar, Container &s) { s.clear(); // retrieve number of elements collection_size_type count; unsigned int item_version; ar >> BOOST_SERIALIZATION_NVP(count); if(3 < ar.get_library_version()) ar >> BOOST_SERIALIZATION_NVP(item_version); else item_version = 0; ... Also of note from basic_iarchive .. basic_iarchive::get_library_version() const{ return pimpl->m_archive_library_version; } m_archive_library_version is set in the constructor of basic_iarchive_impl .. basic_iarchive_impl(unsigned int flags) : m_archive_library_version(ARCHIVE_VERSION()), where ARCHIVE_VERSION is defined in basic_archive.cpp to to be 4 ARCHIVE_VERSION(){ return 4; } That's about all I know about the issue. I am curious to see if calling set_library_version on the archive before deserialization of the archive occurs works for anyone. Brian. On Fri, Jun 6, 2008 at 12:55 PM, Johan Råde <rade@maths.lth.se> wrote:
Johan Råde wrote:
I just ran some tests on Windows, and I can confirm the problem. Here is output from serialization of an std::vector<X*> where the class X has an empty serialization function.
Boost 1.34.1:
<v class_id="0" tracking_level="0" version="0"> <count>2</count> <item_version>0</item_version> <item class_id="1" tracking_level="1" version="0" object_id="_0"></item> <item class_id_reference="1" object_id="_1"></item> </v>
Boost 1.35:
<v class_id="0" tracking_level="0" version="0"> <count>2</count> <item class_id="1" tracking_level="1" version="0" object_id="_0"></item> <item class_id_reference="1" object_id="_1"></item> </v>
This is a *major problem* for us, because we will release a new version of our app soon. The app has "Export" and "Import" functions that are implemented using Boost.Serialization. It is required that files that have been exported with one version of our app can be imported with a later version.
Is there a patch for this problem yet?
Thank you, Johan Råde
Does anyone know if the problem can be fixed by just replacing the file serialization/vector.hpp in Boost 1.35 with the Boost 1.34.1 version (but keeping the rest of 1.35)?
--Johan
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (5)
-
Brian Davis
-
Filip Peters
-
Johan Råde
-
Robert Ramey
-
Sohail Somani