Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#4394 closed Bugs (fixed)

assert in void_caster

Reported by: alexander@… Owned by: Robert Ramey
Milestone: Boost 1.44.0 Component: serialization
Version: Boost 1.43.0 Severity: Problem
Keywords: serialization assert Cc:

Description

There is the static library with two classes, "base" and "derived".

class base
{
public:
   base():a(0){};
   virtual ~base(){};

private:
   friend class boost::serialization::access;
   template<class Archive>
   void serialize(Archive & ar, const unsigned int version)
   {
      ar & a;
   }

private:
   int a;
};

class derived: public base
{
public:
   derived():b(0){};
   virtual ~derived(){};

private:
   friend class boost::serialization::access;
   template<class Archive>
   void serialize(Archive & ar, const unsigned int version)
   {
      ar & boost::serialization::base_object<base>(*this);
      ar & b;
   }

private:
   int b;
};

This static library is linked to two dynamic libraries. For example, dll_a.dll and dll_b.dll. When I try to load those dlls in my application (via LoadLibrary), I get assert in void_cast.cpp (225):

    std::pair<void_cast_detail::set_type::const_iterator, bool> result;
    result = s.insert(this);
    assert(result.second);

Sample project is available upon request.

Change History (3)

comment:1 by Robert Ramey, 12 years ago

For now I'm going to comment out the assert.

When I have time, I'll likely re-enable it with a way to override it.

The problem is that the way the code is structured, you'll have multiple instances of some functions. The best way would be eliminate the source of the problem by structuring code like this:

class base { public:

base():a(0){}; virtual ~base(){};

private:

friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version);

private:

int a;

};

class derived: public base { public:

derived():b(0){}; virtual ~derived(){};

private:

friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version);

private:

int b;

};

In dll_derived.cpp

template<class Archive> void serialize(Archive & ar, const unsigned int version){ {

ar & boost::serialization::base_object<base>(*this); ar & b;

}

instantiate for archives class used:

template derived::serialize<text_oarchive>(text_oarchive, const unsigned int version); ...

comment:2 by Robert Ramey, 12 years ago

Resolution: fixed
Status: newclosed

in reply to:  1 comment:3 by 0xcdcdcdcd@…, 11 years ago

Replying to ramey:

For now I'm going to comment out the assert.

When I have time, I'll likely re-enable it with a way to override it.

The problem is that the way the code is structured, you'll have multiple instances of some functions. The best way would be eliminate the source of the problem by structuring code like this:

Hopefully we can generate some additional info via here: http://permalink.gmane.org/gmane.comp.lib.boost.devel/226590

Note: See TracTickets for help on using tickets.