[Boost-bugs] [Boost C++ Libraries] #4044: reset_object_address with library-created objects

Subject: [Boost-bugs] [Boost C++ Libraries] #4044: reset_object_address with library-created objects
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-03-25 12:56:19


#4044: reset_object_address with library-created objects
-------------------------------------------------+--------------------------
 Reporter: Richard Hazlewood | Owner: ramey
     Type: Bugs | Status: new
Milestone: Boost 1.43.0 | Component: serialization
  Version: Boost 1.42.0 | Severity: Problem
 Keywords: reset_object_address heap allocated |
-------------------------------------------------+--------------------------
 The archive reset_object_address method does not work for objects created
 by the serialization library.

 This appears to be the issue as discussed here:
 http://lists.boost.org/boost-users/2008/11/42417.php
 It looks like the issue was never addressed.

 The code below demonstrates. Is this considered to be the desired
 behaviour?

 I would've thought the object tracking should be applicable, regardless of
 how the object is constructed.

 {{{
 #include <boost/archive/text_oarchive.hpp>
 #include <boost/archive/text_iarchive.hpp>
 #include <boost/serialization/serialization.hpp>
 #include <sstream>

 struct Ob
 {
     Ob() : m_(1) {}

     int m_;

     template <typename A>
     void serialize(A &a, const unsigned)
     {
         a & m_;
     }
 };

 int main(int, char *[])
 {
     std::string serText;
     {
         std::ostringstream str;
         boost::archive::text_oarchive oa(str);
         Ob *p = new Ob;
         oa & p & p; // Serialize two instances; serialization lib will
 track second
         delete p;
         serText = str.str();
     }

     {
         std::istringstream str(serText);
         boost::archive::text_iarchive ia(str);
         Ob *p = 0;
         ia & p;
         Ob *newp = new Ob(*p);
         ia.reset_object_address(newp, p); // newp should now be used for
 future p uses
         delete p; p = 0; // Let's explicitly get shot of this
         ia & p;
         assert(p == newp); // Traps
         delete newp;
     }

     return 0;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4044>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC