Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86156 - in trunk/libs/serialization: doc src test vc7ide
From: ramey_at_[hidden]
Date: 2013-10-03 20:36:37


Author: ramey
Date: 2013-10-03 20:36:37 EDT (Thu, 03 Oct 2013)
New Revision: 86156
URL: http://svn.boost.org/trac/boost/changeset/86156

Log:
fixed memory leak on load_object_ptr and other changes

Deleted:
   trunk/libs/serialization/vc7ide/
Text files modified:
   trunk/libs/serialization/doc/archive_reference.html | 6 +-
   trunk/libs/serialization/src/basic_iarchive.cpp | 2
   trunk/libs/serialization/src/basic_serializer_map.cpp | 5 +-
   trunk/libs/serialization/test/B.hpp | 1
   trunk/libs/serialization/test/test_delete_pointer.cpp | 67 ++++++++++++++++++---------------------
   trunk/libs/serialization/test/test_tools.hpp | 4 +-
   6 files changed, 41 insertions(+), 44 deletions(-)

Modified: trunk/libs/serialization/doc/archive_reference.html
==============================================================================
--- trunk/libs/serialization/doc/archive_reference.html Thu Oct 3 20:26:49 2013 (r86155)
+++ trunk/libs/serialization/doc/archive_reference.html 2013-10-03 20:36:37 EDT (Thu, 03 Oct 2013) (r86156)
@@ -57,7 +57,7 @@
     // serialization library
     typedef boost::mpl::bool_<true> is_saving;
     typedef boost::mpl::bool_<false> is_loading;
- template<class T> register_type(){}
+ template<class T> void register_type(){}
     template<class T> trivial_oarchive & operator<<(const T & t){
         return *this;
     }
@@ -140,7 +140,7 @@
 
 <dl>
 
-<dt><h4><code>void save_start()</code></h4></dt>
+<dt><h4><code>void save_start(char const *)</code></h4></dt>
 <dd>
 <strong>Default</strong>:Does nothing.<br>
 <strong>Purpose</strong>:To inject/retrieve an object name into the archive. Used
@@ -148,7 +148,7 @@
 </dd>
 <p>
 
-<dt><h4><code>void save_end()</code></h4></dt>
+<dt><h4><code>void save_end(char const *)</code></h4></dt>
 <dd>
 <strong>Default</strong>:Does nothing.<br>
 <strong>Purpose</strong>:To inject/retrieve an object name into the archive. Used

Modified: trunk/libs/serialization/src/basic_iarchive.cpp
==============================================================================
--- trunk/libs/serialization/src/basic_iarchive.cpp Thu Oct 3 20:26:49 2013 (r86155)
+++ trunk/libs/serialization/src/basic_iarchive.cpp 2013-10-03 20:36:37 EDT (Thu, 03 Oct 2013) (r86156)
@@ -453,9 +453,9 @@
         }
         BOOST_ASSERT(NULL != bpis_ptr);
         class_id_type new_cid = register_type(bpis_ptr->get_basic_serializer());
+ BOOST_VERIFY(register_type(bpis_ptr->get_basic_serializer()) == cid);
         int i = cid;
         cobject_id_vector[i].bpis_ptr = bpis_ptr;
- BOOST_ASSERT(new_cid == cid);
     }
     int i = cid;
     cobject_id & co = cobject_id_vector[i];

Modified: trunk/libs/serialization/src/basic_serializer_map.cpp
==============================================================================
--- trunk/libs/serialization/src/basic_serializer_map.cpp Thu Oct 3 20:26:49 2013 (r86155)
+++ trunk/libs/serialization/src/basic_serializer_map.cpp 2013-10-03 20:36:37 EDT (Thu, 03 Oct 2013) (r86156)
@@ -43,11 +43,12 @@
 BOOST_ARCHIVE_DECL(bool)
 basic_serializer_map::insert(const basic_serializer * bs){
     // attempt to insert serializer into it's map
- const std::pair<map_type::iterator, bool> result =
- m_map.insert(bs);
     // the following is commented out - rather than being just
     // deleted as a reminder not to try this.
 
+ // const std::pair<map_type::iterator, bool> result =
+ m_map.insert(bs);
+
     // At first it seemed like a good idea. It enforced the
     // idea that a type be exported from at most one code module
     // (DLL or mainline). This would enforce a "one definition rule"

Modified: trunk/libs/serialization/test/B.hpp
==============================================================================
--- trunk/libs/serialization/test/B.hpp Thu Oct 3 20:26:49 2013 (r86155)
+++ trunk/libs/serialization/test/B.hpp 2013-10-03 20:36:37 EDT (Thu, 03 Oct 2013) (r86156)
@@ -67,6 +67,7 @@
             ar >> BOOST_SERIALIZATION_NVP(v);
             ar >> BOOST_SERIALIZATION_NVP(w);
             ar >> BOOST_SERIALIZATION_NVP(x);
+ break;
         default:
             break;
         }

Modified: trunk/libs/serialization/test/test_delete_pointer.cpp
==============================================================================
--- trunk/libs/serialization/test/test_delete_pointer.cpp Thu Oct 3 20:26:49 2013 (r86155)
+++ trunk/libs/serialization/test/test_delete_pointer.cpp 2013-10-03 20:36:37 EDT (Thu, 03 Oct 2013) (r86156)
@@ -24,7 +24,6 @@
 
 #include <boost/serialization/nvp.hpp>
 #include <boost/serialization/split_member.hpp>
-#include <boost/serialization/vector.hpp>
 
 //A holds a pointer to another A, but doesn't own the pointer.
 //objCount
@@ -41,89 +40,85 @@
     {
         static int i = 0;
         ar >> BOOST_SERIALIZATION_NVP(next_);
- if(++i == 3)
- boost::serialization::throw_exception(boost::archive::archive_exception(
- boost::archive::archive_exception::no_exception
- ));
+ //if(++i == 3)
+ // boost::serialization::throw_exception(boost::archive::archive_exception(
+ // boost::archive::archive_exception::no_exception
+ // ));
+ ++loadcount;
     }
     BOOST_SERIALIZATION_SPLIT_MEMBER()
 public:
     A()
     {
+ if(test && objcount == 3)
+ boost::serialization::throw_exception(boost::archive::archive_exception(
+ boost::archive::archive_exception::no_exception
+ ));
         next_ = 0;
         ++objcount;
     }
- A(const A& a)
- {
- next_ = a.next_; ++objcount;
- }
- ~A()
- {
+ ~A(){
+ delete next_;
         --objcount;
     }
     A* next_;
     static int objcount;
+ static bool test;
+ static int loadcount;
 };
 
 
 int A::objcount = 0;
+int A::loadcount = 0;
+bool A::test = false;
 
 int
 test_main( int /* argc */, char* /* argv */[] )
 {
- std::vector<A*> vec;
- A* a = new A;
- a->next_ = 0;
- vec.push_back(a);
 
     //fill the vector with chained A's. The vector is assumed
     //to own the objects - we will destroy the objects through this vector.
+
+ A * head = new A;
+ A* last = head;
     unsigned int i;
- for(i = 1; i < 10; ++i)
+ for(i = 1; i < 9; ++i)
     {
- a = new A;
- vec[i - 1]->next_ = a;
- a->next_ = 0;
- vec.push_back(a);
+ A *a = new A;
+ last->next_ = a;
+ last = a;
     }
 
     const char * testfile = boost::archive::tmpnam(0);
     BOOST_REQUIRE(NULL != testfile);
 
- //output the vector
+ //output the list
     {
         test_ostream os(testfile, TEST_STREAM_FLAGS);
         test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
- oa << BOOST_SERIALIZATION_NVP(vec);
+ oa << BOOST_SERIALIZATION_NVP(head);
     }
 
- //erase the objects
- for(i = 0; i < vec.size(); ++i)
- delete vec[i];
- vec.clear();
+ delete head;
+ BOOST_CHECK(A::objcount == 0);
 
- //read the vector back
+ head = NULL;
+ A::test = true;
+ //read the list back
     {
         test_istream is(testfile, TEST_STREAM_FLAGS);
         test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
         BOOST_TRY {
- ia >> BOOST_SERIALIZATION_NVP(vec);
+ ia >> BOOST_SERIALIZATION_NVP(head);
         }
         BOOST_CATCH (...){
             ia.delete_created_pointers();
- vec.clear();
         }
         BOOST_CATCH_END
     }
 
- //delete the objects
- for(i = 0; i < vec.size(); ++i)
- delete vec[i];
- vec.clear();
-
     //identify the leaks
- BOOST_CHECK(A::objcount == 0);
+ BOOST_CHECK(A::loadcount == 0);
     std::remove(testfile);
     return EXIT_SUCCESS;
 }
-

Modified: trunk/libs/serialization/test/test_tools.hpp
==============================================================================
--- trunk/libs/serialization/test/test_tools.hpp Thu Oct 3 20:26:49 2013 (r86155)
+++ trunk/libs/serialization/test/test_tools.hpp 2013-10-03 20:36:37 EDT (Thu, 03 Oct 2013) (r86156)
@@ -63,9 +63,9 @@
 #include <direct.h>
 #include <boost/archive/tmpdir.hpp>
 
-#if defined(__COMO__)
+//#if defined(__COMO__)
     #define chdir _chdir
-#endif
+//#endif // defined win32
 
 #if defined(NDEBUG) && defined(__BORLANDC__)
     #define STRCPY strcpy


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