Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54752 - trunk/boost/archive
From: ramey_at_[hidden]
Date: 2009-07-07 00:00:11


Author: ramey
Date: 2009-07-07 00:00:10 EDT (Tue, 07 Jul 2009)
New Revision: 54752
URL: http://svn.boost.org/trac/boost/changeset/54752

Log:
Fixed misc bugs
Text files modified:
   trunk/boost/archive/archive_exception.hpp | 17 ++++++---
   trunk/boost/archive/basic_binary_oarchive.hpp | 19 ++++++++--
   trunk/boost/archive/polymorphic_text_wiarchive.hpp | 12 +++++-
   trunk/boost/archive/polymorphic_xml_wiarchive.hpp | 12 +++++-
   trunk/boost/archive/shared_ptr_helper.hpp | 69 ++++++++++++++++++++++++---------------
   5 files changed, 85 insertions(+), 44 deletions(-)

Modified: trunk/boost/archive/archive_exception.hpp
==============================================================================
--- trunk/boost/archive/archive_exception.hpp (original)
+++ trunk/boost/archive/archive_exception.hpp 2009-07-07 00:00:10 EDT (Tue, 07 Jul 2009)
@@ -39,11 +39,10 @@
         unsupported_version,// archive created with library version
                             // subsequent to this one
         pointer_conflict, // an attempt has been made to directly
- // serialization::detail an object
- // after having already serialzed the same
- // object through a pointer. Were this permited,
- // it the archive load would result in the
- // creation of an extra copy of the obect.
+ // serialize an object which has
+ // already been serialzed through a pointer.
+ // Were this permited, the archive load would result
+ // in the creation of an extra copy of the obect.
         incompatible_native_format, // attempt to read native binary format
                             // on incompatible platform
         array_size_too_short,// array being loaded doesn't fit in array allocated
@@ -53,9 +52,11 @@
                             // to insert virus via buffer overrun method.
         unregistered_cast, // base - derived relationship not registered with
                             // void_cast_register
- unsupported_class_version // type saved with a version # greater than the
+ unsupported_class_version, // type saved with a version # greater than the
                             // one used by the program. This indicates that the proggram
                             // needs to be rebuilt.
+ inconsistent_pointer_serialization // an object as been serialized
+ // more than once through pointers of different types.
     } exception_code;
     exception_code code;
     archive_exception(exception_code c) :
@@ -103,6 +104,10 @@
             // was sliced by passing by value in catch
             msg = "unknown derived exception";
             break;
+ case inconsistent_pointer_serialization:
+ // same object saved through different kinds of pointers
+ msg = "inconsistent_pointer_serialization";
+ break;
         default:
             assert(false);
             break;

Modified: trunk/boost/archive/basic_binary_oarchive.hpp
==============================================================================
--- trunk/boost/archive/basic_binary_oarchive.hpp (original)
+++ trunk/boost/archive/basic_binary_oarchive.hpp 2009-07-07 00:00:10 EDT (Tue, 07 Jul 2009)
@@ -23,6 +23,10 @@
 // IN GENERAL, ARCHIVES CREATED WITH THIS CLASS WILL NOT BE READABLE
 // ON PLATFORM APART FROM THE ONE THEY ARE CREATE ON
 
+#include <cassert>
+#include <boost/integer.hpp>
+#include <boost/integer_traits.hpp>
+
 #include <boost/config.hpp>
 #include <boost/serialization/pfto.hpp>
 
@@ -69,27 +73,32 @@
     void save_override(const version_type & t, int){
         // upto 255 versions
         // note:t.t resolves borland ambguity
- const unsigned char x = t.t;
+ assert(t.t <= boost::integer_traits<unsigned char>::const_max);
+ const unsigned char x = static_cast<const unsigned char>(t.t);
         * this->This() << x;
     }
     void save_override(const class_id_type & t, int){
         // upto 32K classes
- const int_least16_t x = t.t;
+ assert(t.t <= boost::integer_traits<boost::int_least16_t>::const_max);
+ const boost::int_least16_t x = static_cast<const boost::int_least16_t>(t.t);
         * this->This() << x;
     }
     void save_override(const class_id_reference_type & t, int){
         // upto 32K classes
- const int_least16_t x = t.t;
+ assert(t.t <= boost::integer_traits<boost::uint_least32_t>::const_max);
+ const boost::uint_least16_t x = t.t;
         * this->This() << x;
     }
     void save_override(const object_id_type & t, int){
         // upto 2G objects
- const uint_least32_t x = t.t;
+ assert(t.t <= boost::integer_traits<boost::uint_least32_t>::const_max);
+ const boost::uint_least32_t x = t.t;
         * this->This() << x;
     }
     void save_override(const object_reference_type & t, int){
         // upto 2G objects
- uint_least32_t x = t.t;
+ assert(t.t <= boost::integer_traits<boost::uint_least32_t>::const_max);
+ const boost::uint_least32_t x = t.t;
         * this->This() << x;
     }
     void save_override(const tracking_type & t, int){

Modified: trunk/boost/archive/polymorphic_text_wiarchive.hpp
==============================================================================
--- trunk/boost/archive/polymorphic_text_wiarchive.hpp (original)
+++ trunk/boost/archive/polymorphic_text_wiarchive.hpp 2009-07-07 00:00:10 EDT (Tue, 07 Jul 2009)
@@ -27,9 +27,15 @@
 namespace boost {
 namespace archive {
 
-typedef detail::polymorphic_iarchive_route<
- text_wiarchive_impl<naked_text_wiarchive>
-> polymorphic_text_wiarchive;
+class polymorphic_text_wiarchive :
+ public detail::polymorphic_iarchive_route<naked_text_wiarchive>
+{
+public:
+ polymorphic_text_wiarchive(std::wistream & is, unsigned int flags = 0) :
+ detail::polymorphic_iarchive_route<naked_text_wiarchive>(is, flags)
+ {}
+ ~polymorphic_text_wiarchive(){}
+};
 
 } // namespace archive
 } // namespace boost

Modified: trunk/boost/archive/polymorphic_xml_wiarchive.hpp
==============================================================================
--- trunk/boost/archive/polymorphic_xml_wiarchive.hpp (original)
+++ trunk/boost/archive/polymorphic_xml_wiarchive.hpp 2009-07-07 00:00:10 EDT (Tue, 07 Jul 2009)
@@ -27,9 +27,15 @@
 namespace boost {
 namespace archive {
 
-typedef detail::polymorphic_iarchive_route<
- xml_wiarchive_impl<naked_xml_wiarchive>
-> polymorphic_xml_wiarchive;
+class polymorphic_xml_wiarchive :
+ public detail::polymorphic_iarchive_route<naked_xml_wiarchive>
+{
+public:
+ polymorphic_xml_wiarchive(std::wistream & is, unsigned int flags = 0) :
+ detail::polymorphic_iarchive_route<naked_xml_wiarchive>(is, flags)
+ {}
+ ~polymorphic_xml_wiarchive(){}
+};
 
 } // namespace archive
 } // namespace boost

Modified: trunk/boost/archive/shared_ptr_helper.hpp
==============================================================================
--- trunk/boost/archive/shared_ptr_helper.hpp (original)
+++ trunk/boost/archive/shared_ptr_helper.hpp 2009-07-07 00:00:10 EDT (Tue, 07 Jul 2009)
@@ -9,7 +9,7 @@
 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
 // shared_ptr_helper.hpp: serialization for boost shared pointer
 
-// (C) Copyright 2004 Robert Ramey and Martin Ecker
+// (C) Copyright 2004-2009 Robert Ramey, Martin Ecker and Takatoshi Kondo
 // Use, modification and distribution is subject to the Boost Software
 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
@@ -18,10 +18,12 @@
 
 #include <map>
 #include <list>
+#include <utility>
 #include <cstddef> // NULL
 
 #include <boost/config.hpp>
 #include <boost/shared_ptr.hpp>
+
 #include <boost/serialization/type_info_implementation.hpp>
 #include <boost/serialization/shared_ptr_132.hpp>
 #include <boost/serialization/throw_exception.hpp>
@@ -54,7 +56,10 @@
 // a common class for holding various types of shared pointers
 
 class shared_ptr_helper {
- typedef std::map<const void *, shared_ptr<void> > collection_type;
+ typedef std::map<
+ const void *,
+ boost::shared_ptr<const void>
+ > collection_type;
     typedef collection_type::const_iterator iterator_type;
     // list of shared_pointers create accessable by raw pointer. This
     // is used to "match up" shared pointers loaded at different
@@ -74,6 +79,7 @@
     );
 #endif
 
+// #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
     // list of loaded pointers. This is used to be sure that the pointers
     // stay around long enough to be "matched" with other pointers loaded
     // by the same archive. These are created with a "null_deleter" so that
@@ -83,10 +89,17 @@
     // by a change in load_construct_data below. It makes this file suitable
     // only for loading pointers into a 1.33 or later boost system.
     std::list<boost_132::shared_ptr<void> > * m_pointers_132;
+// #endif
 
- // return a void pointer to the most derived type
+public:
     template<class T>
- const void * object_identifier(T * t) const {
+ void reset(shared_ptr<T> & s, T * t){
+ if(NULL == t){
+ s.reset();
+ return;
+ }
+ // get pointer to the most derived object. This is effectively
+ // the object identifer
         const boost::serialization::extended_type_info * true_type
             = boost::serialization::type_info_implementation<T>::type
                 ::get_const_instance().get_derived_extended_type_info(*t);
@@ -94,59 +107,61 @@
         // is either registered or exported.
         if(NULL == true_type)
             boost::serialization::throw_exception(
- boost::archive::archive_exception(
- boost::archive::archive_exception::unregistered_class
- )
+ archive_exception(archive_exception::unregistered_class)
             );
         const boost::serialization::extended_type_info * this_type
             = & boost::serialization::type_info_implementation<T>::type
                     ::get_const_instance();
- const void * vp = void_downcast(
+
+ // get void pointer to the most derived type
+ // this uniquely identifies the object referred to
+ const void * od = void_downcast(
             *true_type,
             *this_type,
             static_cast<const void *>(t)
         );
- return vp;
- }
-public:
- template<class T>
- void reset(shared_ptr<T> & s, T * r){
- if(NULL == r){
- s.reset();
- return;
- }
- // get pointer to the most derived object. This is effectively
- // the object identifer
- const void * od = object_identifier(r);
 
+ // make tracking array if necessary
         if(NULL == m_pointers)
             m_pointers = new collection_type;
 
         iterator_type it = m_pointers->find(od);
 
+ // create a new shared pointer to a void
         if(it == m_pointers->end()){
- s.reset(r);
- m_pointers->insert(collection_type::value_type(od,s));
- }
- else{
- s = static_pointer_cast<T>((*it).second);
+ s.reset(t);
+ shared_ptr<const void> sp(s, od);
+ m_pointers->insert(collection_type::value_type(od, sp));
+ return;
         }
+ t = static_cast<T *>(const_cast<void *>(void_upcast(
+ *true_type,
+ *this_type,
+ ((*it).second.get())
+ )));
+ s = shared_ptr<T>((*it).second, t); // aliasing
     }
+// #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
     void append(const boost_132::shared_ptr<void> & t){
         if(NULL == m_pointers_132)
             m_pointers_132 = new std::list<boost_132::shared_ptr<void> >;
         m_pointers_132->push_back(t);
     }
+// #endif
 public:
     shared_ptr_helper() :
- m_pointers(NULL),
- m_pointers_132(NULL)
+ m_pointers(NULL)
+ #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
+ , m_pointers_132(NULL)
+ #endif
     {}
     ~shared_ptr_helper(){
         if(NULL != m_pointers)
             delete m_pointers;
+ #ifdef BOOST_SERIALIZATION_SHARED_PTR_132_HPP
         if(NULL != m_pointers_132)
             delete m_pointers_132;
+ #endif
     }
 };
 


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