Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58257 - in trunk/boost/archive: . detail
From: ramey_at_[hidden]
Date: 2009-12-09 19:30:07


Author: ramey
Date: 2009-12-09 19:30:06 EST (Wed, 09 Dec 2009)
New Revision: 58257
URL: http://svn.boost.org/trac/boost/changeset/58257

Log:
1. Fixed memory leak in shared_ptr loading
2. Fixed error in polymorphic archive implementation
Text files modified:
   trunk/boost/archive/detail/basic_iarchive.hpp | 9 ++++---
   trunk/boost/archive/detail/common_iarchive.hpp | 7 ------
   trunk/boost/archive/detail/iserializer.hpp | 10 ++++++++
   trunk/boost/archive/detail/polymorphic_iarchive_route.hpp | 7 ++++-
   trunk/boost/archive/polymorphic_iarchive.hpp | 5 +++
   trunk/boost/archive/shared_ptr_helper.hpp | 45 +++++++++++++++++++++++++++++----------
   6 files changed, 56 insertions(+), 27 deletions(-)

Modified: trunk/boost/archive/detail/basic_iarchive.hpp
==============================================================================
--- trunk/boost/archive/detail/basic_iarchive.hpp (original)
+++ trunk/boost/archive/detail/basic_iarchive.hpp 2009-12-09 19:30:06 EST (Wed, 09 Dec 2009)
@@ -56,9 +56,6 @@
     virtual void vload(class_id_optional_type &t) = 0;
     virtual void vload(class_name_type &t) = 0;
     virtual void vload(tracking_type &t) = 0;
-
- virtual const basic_pointer_iserializer *
- find(const boost::serialization::extended_type_info & eti) const = 0;
 protected:
     basic_iarchive(unsigned int flags);
     // account for bogus gcc warning
@@ -79,7 +76,11 @@
     const basic_pointer_iserializer *
     load_pointer(
         void * & t,
- const basic_pointer_iserializer * bpis_ptr
+ const basic_pointer_iserializer * bpis_ptr,
+ const basic_pointer_iserializer * (*finder)(
+ const boost::serialization::extended_type_info & eti
+ )
+
     );
     // real public API starts here
     void

Modified: trunk/boost/archive/detail/common_iarchive.hpp
==============================================================================
--- trunk/boost/archive/detail/common_iarchive.hpp (original)
+++ trunk/boost/archive/detail/common_iarchive.hpp 2009-12-09 19:30:06 EST (Wed, 09 Dec 2009)
@@ -76,13 +76,6 @@
         basic_iarchive(flags),
         interface_iarchive<Archive>()
     {}
-public:
- virtual const basic_pointer_iserializer *
- find(const boost::serialization::extended_type_info & eti) const {
- return static_cast<const basic_pointer_iserializer *>(
- archive_serializer_map<Archive>::find(eti)
- );
- }
 };
 
 } // namespace detail

Modified: trunk/boost/archive/detail/iserializer.hpp
==============================================================================
--- trunk/boost/archive/detail/iserializer.hpp (original)
+++ trunk/boost/archive/detail/iserializer.hpp 2009-12-09 19:30:06 EST (Wed, 09 Dec 2009)
@@ -494,13 +494,21 @@
         check_pointer_tracking<T>();
     }
 
+ static const basic_pointer_iserializer *
+ find(const boost::serialization::extended_type_info & type){
+ return static_cast<const basic_pointer_iserializer *>(
+ archive_serializer_map<Archive>::find(type)
+ );
+ }
+
     template<class Tptr>
     static void invoke(Archive & ar, Tptr & t){
         load(ar, *t);
         const basic_pointer_iserializer * bpis_ptr = register_type(ar, *t);
         const basic_pointer_iserializer * newbpis_ptr = ar.load_pointer(
             * reinterpret_cast<void **>(&t),
- bpis_ptr
+ bpis_ptr,
+ find
         );
         // if the pointer isn't that of the base class
         if(newbpis_ptr != bpis_ptr){

Modified: trunk/boost/archive/detail/polymorphic_iarchive_route.hpp
==============================================================================
--- trunk/boost/archive/detail/polymorphic_iarchive_route.hpp (original)
+++ trunk/boost/archive/detail/polymorphic_iarchive_route.hpp 2009-12-09 19:30:06 EST (Wed, 09 Dec 2009)
@@ -63,9 +63,12 @@
     }
     virtual const basic_pointer_iserializer * load_pointer(
         void * & t,
- const basic_pointer_iserializer * bpis_ptr
+ const basic_pointer_iserializer * bpis_ptr,
+ const basic_pointer_iserializer * (*finder)(
+ const boost::serialization::extended_type_info & type
+ )
     ){
- return ArchiveImplementation::load_pointer(t, bpis_ptr);
+ return ArchiveImplementation::load_pointer(t, bpis_ptr, finder);
     }
     virtual void set_library_version(version_type archive_library_version){
         ArchiveImplementation::set_library_version(archive_library_version);

Modified: trunk/boost/archive/polymorphic_iarchive.hpp
==============================================================================
--- trunk/boost/archive/polymorphic_iarchive.hpp (original)
+++ trunk/boost/archive/polymorphic_iarchive.hpp 2009-12-09 19:30:06 EST (Wed, 09 Dec 2009)
@@ -159,7 +159,10 @@
     ) = 0;
     virtual const detail::basic_pointer_iserializer * load_pointer(
         void * & t,
- const detail::basic_pointer_iserializer * bpis_ptr
+ const detail::basic_pointer_iserializer * bpis_ptr,
+ const detail::basic_pointer_iserializer * (*finder)(
+ const boost::serialization::extended_type_info & type
+ )
     ) = 0;
 };
 

Modified: trunk/boost/archive/shared_ptr_helper.hpp
==============================================================================
--- trunk/boost/archive/shared_ptr_helper.hpp (original)
+++ trunk/boost/archive/shared_ptr_helper.hpp 2009-12-09 19:30:06 EST (Wed, 09 Dec 2009)
@@ -16,7 +16,7 @@
 
 // See http://www.boost.org for updates, documentation, and revision history.
 
-#include <map>
+#include <set>
 #include <list>
 #include <utility>
 #include <cstddef> // NULL
@@ -55,9 +55,17 @@
 // a common class for holding various types of shared pointers
 
 class shared_ptr_helper {
- typedef std::map<
- void *,
- boost::shared_ptr<const void>
+ struct collection_type_compare {
+ bool operator()(
+ const shared_ptr<const void> &lhs,
+ const shared_ptr<const void> &rhs
+ )const{
+ return lhs.get() < rhs.get();
+ }
+ };
+ typedef std::set<
+ boost::shared_ptr<const void>,
+ collection_type_compare
> collection_type;
     typedef collection_type::const_iterator iterator_type;
     // list of shared_pointers create accessable by raw pointer. This
@@ -71,6 +79,16 @@
         void operator()(void const *) const {}
     };
 
+ struct void_deleter {
+ const boost::serialization::extended_type_info * m_eti;
+ void_deleter(const boost::serialization::extended_type_info *eti) :
+ m_eti(eti)
+ {}
+ void operator()(void *vp) const {
+ m_eti->destroy(vp);
+ }
+ };
+
 #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
 public:
 #else
@@ -94,13 +112,11 @@
     std::list<boost_132::shared_ptr<void> > * m_pointers_132;
 // #endif
 
- typedef std::pair<const iterator_type, void *> result_type;
-
     // returns pointer to object and an indicator whether this is a
     // new entry (true) or a previous one (false)
- BOOST_ARCHIVE_DECL(result_type)
+ BOOST_ARCHIVE_DECL(shared_ptr<void>)
     get_od(
- void * od,
+ const void * od,
         const boost::serialization::extended_type_info * true_type,
         const boost::serialization::extended_type_info * this_type
     );
@@ -156,16 +172,21 @@
                     this_type->get_debug_info()
                 )
             );
- result_type r =
+ shared_ptr<void> r =
             get_od(
- static_cast<void *>(t),
+ static_cast<const void *>(t),
                 true_type,
                 this_type
             );
+
         s = shared_ptr<T>(
- r.first->second,
- static_cast<T *>(r.second)
+ r,
+ static_cast<T *>(r.get())
         );
+
+ //s = static_pointer_cast<T,void>(
+ // const_pointer_cast<void, const void>(*r)
+ //);
     }
 
 // #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk