Boost logo

Boost :

From: Martin Slater (mslater_at_[hidden])
Date: 2006-08-21 10:42:33


Jarl Lindrud wrote:

>Hi,
>
>RCF, a C++ middleware framework, supports using Boost Serialization for
>serialization of data structures. One of my user's reported a serialization bug
>to me, which I finally boiled down into the following piece of code:
>
>
>
I got curious and had a nose at this with vc8 and discovered a few
things but not tracked the exact cause yet. It does fail for a start.
The error seems to be in writing out the object id for the vector. If
your commented out line is uncommented this causes instantiation of the
pointer_oserializer for that type and when you subsequently serialize
out the vector and it ends up in basic_oarchive_impl::save_object
(basic_oarchive.cpp:241) the bpos parameter is non null and it takes one
code path, but if your line is commented out then bpos is null (as
pointer_oserializer::instantiate is never called) and it takes a
different path.

Down the path with your line commented in it then calls ar.vsave(oid)
(basic_oarchive:285) to save out the object id and things get weird, it
ends up writing an EOL to the stream which is what subsequently stuffs
up the deserialization back again and causes the test to fail. Why all
of this happens I dont know though and have run out of time for tonight ;)

hth

Martin

>#include <sstream>
>#include <string>
>#include <vector>
>
>#include <boost/archive/text_iarchive.hpp>
>#include <boost/archive/text_oarchive.hpp>
>#include <boost/serialization/vector.hpp>
>
>template<typename Archive>
>struct X
>{
> template<typename T>
> void operator<<(const T &t)
> {
> Archive &archive = (*(Archive *) NULL);
> archive << t;
> }
>};
>
>void dummy()
>{
> typedef boost::archive::text_oarchive Archive;
> X<Archive> &x = * (X<Archive> *) NULL;
> std::vector<char> *pt = NULL;
>
> // uncomment this line to cause the test to fail
> //x << pt;
>}
>
>int main(int argc, char* argv[])
>{
> std::vector<char> v0(25, '%');
> std::vector<char> v1;
>
> std::ostringstream ostr;
> boost::archive::text_oarchive(ostr) & v0;
>
> std::istringstream istr(ostr.str());
> boost::archive::text_iarchive(istr) & v1;
>
> bool ok = (v0 == v1);
> return 0;
>}
>
>
>I find this odd, to say the least! I've tried it on Visual C++ 7.1, using boost
>1.33.0 and 1.33.1.
>
>Regards,
>Jarl.
>
>http://www.codeproject.com/threads/Rcf_Ipc_For_Cpp.asp
>
>
>
>
>
>_______________________________________________
>Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
>
>
>

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.3/423 - Release Date: 18/08/2006

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk