Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Polymorphic serialization withpolymorphic archives problem...
From: Martin Lederhilger (ml_at_[hidden])
Date: 2010-02-24 04:42:06


Hello Robert, hello Bogdan,

I have quite the same problem (Exception multiple_code_instantiation
thrown in basic_serializer_map.cpp at line 48) as Bogdan. It can be
reproduced by changing
the pointer type from polymorphic_base to polymorphic_derived2 in the
original test_dll_exported.cpp example, which comes with the library.

void save_exported(const char *testfile)
{
    test_ostream os(testfile, TEST_STREAM_FLAGS);
    test_oarchive oa(os, TEST_ARCHIVE_FLAGS);

    polymorphic_base *rb1 = new polymorphic_derived1;
    polymorphic_derived2 *rb2 = new polymorphic_derived2;

    // export will permit correct serialization
    // through a pointer to a base class
    oa << BOOST_SERIALIZATION_NVP(rb1);
    oa << BOOST_SERIALIZATION_NVP(rb2);

    delete rb1;
    delete rb2;
}

I think the problem is that when oa << BOOST_SERIALIZATION_NVP(rb2); is
called, that the system registers an type in oserializer.hpp, which
leads to creation of the singletons also in the executeable.

I have this problem when serializing a shared_ptr<A> in class B in B.dll
to an object of class A in A.dll.

I tried to simply comment out this check, but it seems that I get
problems with tracking later. I have a class hierarchy like this:
C derives from B derives from A. A has a weak_ptr<A> to itself
(something like boost::enable_shared_from_this). If I serialize an
object of type C via a base pointer of type B the serialization walks
like this: C::serialize, B::serialize, A::serialize, and again
C::serialize (with a wrong this pointer - and it should not do that).

Maybe my second problem depends on the first one. I hope that my report
can be of help.

Thanks in advance for your answers,

Martin Lederhilger


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