Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2005-09-26 10:19:03


This is a bug. Fixed in 1.33.1 Hopefully coming soon.

Robert Ramey

Sergey Filippov wrote:
> Hi, all.
>
> I'm using boost 1.33.0 and I have a problem deserializing from an
> archive (I'm using VC 7.1). To reproduce the problem I wrote a sample
> program listed below.
>
> #include <sstream>
> #include <boost/archive/binary_oarchive.hpp>
> #include <boost/archive/binary_iarchive.hpp>
> #include <boost/serialization/export.hpp>
> #include <boost/serialization/vector.hpp>
>
> struct A
> {
> virtual ~A() {}
>
> friend class boost::serialization::access;
> template<class Archive>
> void serialize(Archive & ar, const unsigned int version) {}
> };
>
> struct B: A
> {
> friend class boost::serialization::access;
> template<class Archive>
> void serialize(Archive & ar, const unsigned int version)
> {
> ar & boost::serialization::base_object<A>(*this);
> }
> };
>
> BOOST_CLASS_EXPORT(A);
> BOOST_CLASS_EXPORT(B);
>
> int main(int argc, char* argv[])
> {
> std::string str;
>
> {
> std::stringstream stream;
> boost::archive::binary_oarchive ar(stream);
> B b;
> std::vector<int> v(10);
>
> ar & b;
> ar & v;
>
> str = stream.rdbuf()->str();
> }
>
> {
> std::stringstream stream;
>
> stream.rdbuf()->str(str);
>
> boost::archive::binary_iarchive ar(stream);
> B b;
> std::vector<int> v;
>
> ar & b;
> ar & v; // causes an assert
> }
>
> return 0;
> }
>
> During deserialization of the vector (a line with "// causes an
> assert"), an assert occurs in the line 266 in basic_iarchive.cpp.
>
> I don't understand the library source code well, but it looks
> something strange for me. As far as I understood the
> reset_object_address function supposed to be called with addresses of
> tracked objects. In my case the new_address parameter is the address
> of an element in the vector. But the vector elements are of a
> primitive type and must not be tracked. Maybe reset_object_address
> supposed to handle such a situation, but in the provided sample
> something goes wrong.
>
> If I skip the line with reset_object_address in archive_input_seq
> (collections_load_impl.hpp, line 91) in debugger, the sample works as
> expected. Also with 1.32 (in which archive_input_seq almost identical
> with one in 1.33 except the call to reset_object_address) the sample
> works as well. So I'm considering to patch the library by commenting
> this line. What side effects will it have?
> I as understood from previous posts in this forum reset_object_address
> was added as a bugfix to loading of containers with pointers to
> trackable objects. Is it safe to comment out the reset_object_address
> call, if I do not serialize such containers?
>
> Or maybe I'm just using the serialization library in a wrong way? Then
> where is the problem in my code?
>
> Thanks in advance.
>
> Sergey


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