Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71400 - in sandbox/shifted_ptr: boost boost/detail libs/smart_ptr/example
From: phil_at_[hidden]
Date: 2011-04-21 03:36:30


Author: pbouchard
Date: 2011-04-21 03:36:28 EDT (Thu, 21 Apr 2011)
New Revision: 71400
URL: http://svn.boost.org/trac/boost/changeset/71400

Log:
* Added is_from to malloc
Text files modified:
   sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp | 44 +++++++++++++++++++++++++++++++++++++--
   sandbox/shifted_ptr/boost/shifted_ptr.hpp | 4 --
   sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test3.cpp | 6 ++--
   3 files changed, 45 insertions(+), 9 deletions(-)

Modified: sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp (original)
+++ sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp 2011-04-21 03:36:28 EDT (Thu, 21 Apr 2011)
@@ -47,6 +47,8 @@
 #include <boost/detail/intrusive_stack.hpp>
 #include <boost/detail/sh_utility.h>
 
+#include <set>
+
 
 namespace boost
 {
@@ -68,7 +70,43 @@
         Pool where all pointee objects are allocated and tracks memory blocks for later enlisting & marking the @c set the pointee object belongs to.
 */
 
-struct pool : boost::pool<>
+struct malloc_pool
+{
+ std::set<void *> alloc;
+
+ void * ordered_malloc(size_t n)
+ {
+ void * p = malloc(n);
+
+ alloc.insert(p);
+
+ return p;
+ }
+
+ void ordered_free(void * p, size_t n)
+ {
+ std::set<void *>::iterator i = alloc.find(p);
+
+ if (i == alloc.end())
+ abort();
+ else
+ alloc.erase(i);
+
+ free(p);
+ }
+
+ bool is_from(void * p)
+ {
+ static char * upper = (char *) sbrk(0);
+ static char * lower = upper - 0x100000;
+
+ return lower <= p && p < upper;
+ }
+};
+
+
+////struct pool : boost::pool<>
+struct pool : malloc_pool
 {
         typedef std::list< numeric::interval<long>, fast_pool_allocator< numeric::interval<long> > > pool_lii; /**< Syntax helper. */
 
@@ -83,7 +121,7 @@
                 Initialization of a pool instance.
         */
         
- pool() : boost::pool<>(1)
+ pool() ////: boost::pool<>(1)
     {
         plii_.reset(new pool_lii());
     }
@@ -143,7 +181,7 @@
                 break;
 
         plii_->erase(i.base(), plii_->end());
- free(p, s);
+ ordered_free(p, s);
     }
 };
 

Modified: sandbox/shifted_ptr/boost/shifted_ptr.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/shifted_ptr.hpp (original)
+++ sandbox/shifted_ptr/boost/shifted_ptr.hpp 2011-04-21 03:36:28 EDT (Thu, 21 Apr 2011)
@@ -412,18 +412,16 @@
                         // iterate memory blocks
             for (intrusive_list::iterator<owned_base, & owned_base::init_tag_> i = p->inits_.begin(); i != p->inits_.end(); ++ i)
             {
+ i->init_ = true;
                 ps_->elements()->push_back(& i->set_tag_);
 
                                 // iterate shifted_ptr elements
                 for (intrusive_stack::iterator<shifted_ptr, & shifted_ptr::pn_> j = i->ptrs_.begin(), k; k = j, j != i->ptrs_.end(); j = k)
                                 {
                                         ++ k;
-
                     j->ps_ = ps_;
                                 }
             }
-
- p->init_ = true;
         }
     };
 

Modified: sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test3.cpp
==============================================================================
--- sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test3.cpp (original)
+++ sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test3.cpp 2011-04-21 03:36:28 EDT (Thu, 21 Apr 2011)
@@ -82,14 +82,14 @@
 };
 
 BOOST_AUTO_TEST_CASE(test_shifted_ptr) {
-
+
     count = 0;
     {
         shifted_ptr<vector> v = new shifted<vector>();
         v->elements.push_back(v);
     }
     BOOST_CHECK_EQUAL(count, 0);
-/*
+
     count = 0;
     {
         list l;
@@ -101,7 +101,7 @@
         }
     }
     BOOST_CHECK_EQUAL(count, 0);
-*/
+
     count = 0;
     {
         shifted_ptr<int> test = new shifted<int>(5);


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