Boost logo

Boost :

From: Sergey Skorniakov (s.skorniakov_at_[hidden])
Date: 2005-08-31 09:37:15


Also, this looks like that this error can't be corrected just by changing
member_displacement to signed type or doing something similar. Without
covering polymorhic classes execution of reset_object_address never goes
further than "if(i >= moveable_object_stack.size()) return;", in my
example it does.

"Sergey Skorniakov" <s.skorniakov_at_[hidden]> wrote:
news:df4cge$ogh$1_at_sea.gmane.org...
>
> Here are some code that illustrates problem. This crashes when
> deserializing
> 1.33 data, however. Programm faults with count >= 2946 on MS VC 7.1 debug
> build.
> Compilation options: /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS"
> /Gm
> /EHsc /RTC1 /MDd /GS /Zc:wchar_t /Zc:forScope /GR /Yu"stdafx.h"
> /Fp"Debug/reset_ptr_err.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo
> /c
> /Wp64 /Zi /TP
>
> #define BOOST_SERIALIZATION_DYN_LINK
> #include <boost/archive/polymorphic_iarchive.hpp>
> #include <boost/archive/polymorphic_oarchive.hpp>
> #include <boost/serialization/export.hpp>
>
> #include <sstream>
>
> #include <boost/archive/polymorphic_text_iarchive.hpp>
> #include <boost/archive/polymorphic_text_oarchive.hpp>
>
> #include <boost/archive/polymorphic_xml_iarchive.hpp>
> #include <boost/archive/polymorphic_xml_oarchive.hpp>
>
> #include <boost/archive/polymorphic_binary_iarchive.hpp>
> #include <boost/archive/polymorphic_binary_oarchive.hpp>
>
>
> #include <boost/serialization/vector.hpp>
>
> struct A
> {
> virtual ~A() = 0 {}
>
> void serialize(boost::archive::polymorphic_iarchive & ar, const unsigned
> int file_version) {}
> void serialize(boost::archive::polymorphic_oarchive & ar, const unsigned
> int file_version) {}
> };
>
> const int count = 100000;
>
> struct B : A
> {
> std::vector<int> v_;
> void serialize(boost::archive::polymorphic_iarchive & ar, const unsigned
> int file_version)
> {
> ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
> ar & BOOST_SERIALIZATION_NVP(v_);
> }
> void serialize(boost::archive::polymorphic_oarchive & ar, const unsigned
> int file_version)
> {
> ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
> ar & BOOST_SERIALIZATION_NVP(v_);
> }
> B()
> {
> for (int i = 0; i < count; ++i)
> v_.push_back(i);
> }
> };
>
> struct C : B
> {
> void serialize(boost::archive::polymorphic_iarchive & ar, const unsigned
> int file_version)
> {
> ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(B);
> }
> void serialize(boost::archive::polymorphic_oarchive & ar, const unsigned
> int file_version)
> {
> ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(B);
> }
> };
>
> BOOST_IS_ABSTRACT(A)
> BOOST_CLASS_EXPORT(B)
> BOOST_CLASS_EXPORT(C)
>
> int main(int argc, char* argv[])
> {
> C c;
>
> std::stringstream ss;
> {
> boost::archive::polymorphic_binary_oarchive oa(ss);
> oa & BOOST_SERIALIZATION_NVP(c);
> }
> {
> boost::archive::polymorphic_binary_iarchive ia(ss);
> ia >> BOOST_SERIALIZATION_NVP(c);
> }
> return 0;
> }
>
>
> "SourceForge.net" <noreply_at_[hidden]> wrote:
> news:E1E5O0t-0004my-Ng_at_sc8-sf-web1.sourceforge.net...
>> Bugs item #1262084, was opened at 2005-08-17 06:31
>> Message generated for change (Tracker Item Submitted) made by Item
>> Submitter
>> You can respond by visiting:
>> https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1262084&group_id=7586
>>
>> Please note that this message will contain a full copy of the comment
>> thread,
>> including the initial issue submission, for this request,
>> not just the latest update.
>> Category: serialization
>> Group: None
>> Status: Open
>> Resolution: None
>> Priority: 5
>> Submitted By: Nobody/Anonymous (nobody)
>> Assigned to: Robert Ramey (ramey)
>> Summary: crash deserializing 1.32 data (poly archive + stl container)
>>
>> Initial Comment:
>> Hello,
>>
>> i got a problem deserializing STL containers with
>> polymorphic archive interfaces.
>>
>> Serialization/Deserialization with boost 1.32 works fine.
>> Simple object trees with stl containers (maps) and base
>> class registration (no shared_ptr used).
>>
>> When i deserialize the data (xml) with boost 1.33 it
>> asserts/crashes in basic_iarchive.cpp (
>> basic_iarchive_impl::reset_object_address):
>>
>> --- snip ----
>>
>> inline void
>> basic_iarchive_impl::reset_object_address(
>> const void * new_address,
>> const void *old_address
>> ){
>> // if the this object wasn't tracked
>> std::size_t i = moveable_object_position;
>> if(i >= moveable_object_stack.size())
>> return;
>> if(old_address != object_id_vector[i].address)
>> // skip to any lower level ones
>> ++i;
>> while(i < moveable_object_stack.size()){
>> // calculate displacement from this level
>> assert(object_id_vector[i].address >=
>> old_address); <---- assert here !!!
>> // warning - pointer arithmetic on void * is in
>> herently non-portable
>> // but expected to work on all platforms in
>> current usage
>> std::size_t member_displacement
>> =
>> reinterpret_cast<std::size_t>(object_id_vector[i].address)
>> - reinterpret_cast<std::size_t>(old_address);
>>
>> ---- snip ----
>>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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