$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r79460 - in sandbox/pool: boost/pool libs/pool/test
From: svart.riddare_at_[hidden]
Date: 2012-07-12 16:43:50
Author: edupuis
Date: 2012-07-12 16:43:49 EDT (Thu, 12 Jul 2012)
New Revision: 79460
URL: http://svn.boost.org/trac/boost/changeset/79460
Log:
Restored BOOST_POOL_VALGRIND implementation of pool that disables pooling...
Text files modified: 
   sandbox/pool/boost/pool/object_pool.hpp       |     8 ++                                      
   sandbox/pool/boost/pool/pool.hpp              |   139 ++++++++++++++++++++++++++++++++++++++++
   sandbox/pool/libs/pool/test/Jamfile.v2        |    22 ++++++                                  
   sandbox/pool/libs/pool/test/test_bug_3789.cpp |     5 +                                       
   sandbox/pool/libs/pool/test/test_bug_6701.cpp |     2                                         
   sandbox/pool/libs/pool/test/test_bug_6865.cpp |    28 +++++++                                 
   6 files changed, 203 insertions(+), 1 deletions(-)
Modified: sandbox/pool/boost/pool/object_pool.hpp
==============================================================================
--- sandbox/pool/boost/pool/object_pool.hpp	(original)
+++ sandbox/pool/boost/pool/object_pool.hpp	2012-07-12 16:43:49 EDT (Thu, 12 Jul 2012)
@@ -259,6 +259,7 @@
 template <typename T, typename UserAllocator>
 bool object_pool<T, UserAllocator>::purge_memory()
 {
+#ifndef BOOST_POOL_VALGRIND
   // handle trivial case of invalid list.
   if (!this->list.valid())
     return false;
@@ -304,6 +305,13 @@
       iter = next;
     } while (iter.valid());
   }
+#else
+  // destruct all used elements:
+  for(std::set<void*>::iterator pos = this->used_list.begin(); pos != this->used_list.end(); ++pos)
+  {
+    static_cast<T*>(*pos)->~T();
+  }
+#endif  
 
   // Call inherited purge function
   return pool<UserAllocator>::purge_memory();
Modified: sandbox/pool/boost/pool/pool.hpp
==============================================================================
--- sandbox/pool/boost/pool/pool.hpp	(original)
+++ sandbox/pool/boost/pool/pool.hpp	2012-07-12 16:43:49 EDT (Thu, 12 Jul 2012)
@@ -43,6 +43,10 @@
 #include <iostream>
 #include<iomanip>
 #endif
+#ifdef BOOST_POOL_VALGRIND
+#include <set>
+#include <valgrind/memcheck.h>
+#endif
 
 #ifdef BOOST_NO_STDC_NAMESPACE
  namespace std { using ::malloc; using ::free; }
@@ -294,6 +298,7 @@
 }; // class PODptr
 } // namespace details
 
+#ifndef BOOST_POOL_VALGRIND
 /*!
   \brief A fast memory allocator that guarantees proper alignment of all allocated chunks.
 
@@ -978,6 +983,140 @@
   return iter;
 }
 
+#else // BOOST_POOL_VALGRIND
+
+template<typename UserAllocator> 
+class pool 
+{
+public:
+  // types
+  typedef UserAllocator                  user_allocator;   // User allocator. 
+  typedef typename UserAllocator::size_type       size_type;        // An unsigned integral type that can represent the size of the largest object to be allocated. 
+  typedef typename UserAllocator::difference_type difference_type;  // A signed integral type that can represent the difference of any two pointers. 
+
+  // construct/copy/destruct
+  explicit pool(const size_type s, const size_type = 32, const size_type m = 0) : chunk_size(s), max_alloc_size(m) {}
+  ~pool()
+  {
+     purge_memory();
+  }
+
+  bool release_memory()
+  {
+     bool ret = free_list.empty() ? false : true;
+     for(std::set<void*>::iterator pos = free_list.begin(); pos != free_list.end(); ++pos)
+     {
+        (user_allocator::free)(static_cast<char*>(*pos));
+     }
+     free_list.clear();
+     return ret;
+  }
+  bool purge_memory()
+  {
+     bool ret = free_list.empty() && used_list.empty() ? false : true;
+     for(std::set<void*>::iterator pos = free_list.begin(); pos != free_list.end(); ++pos)
+     {
+        (user_allocator::free)(static_cast<char*>(*pos));
+     }
+     free_list.clear();
+     for(std::set<void*>::iterator pos = used_list.begin(); pos != used_list.end(); ++pos)
+     {
+        (user_allocator::free)(static_cast<char*>(*pos));
+     }
+     used_list.clear();
+     return ret;
+  }
+  size_type get_next_size() const
+  {
+     return 1;
+  }
+  void set_next_size(const size_type){}
+  size_type get_max_size() const
+  {
+     return max_alloc_size;
+  }
+  void set_max_size(const size_type s)
+  {
+     max_alloc_size = s;
+  }
+  size_type get_requested_size() const
+  {
+     return chunk_size;
+  }
+  size_type get_size() const
+  {
+     return free_list.size() + used_list.size();
+  }
+  void * malloc BOOST_PREVENT_MACRO_SUBSTITUTION()
+  {
+     void* ret;
+     if(free_list.empty())
+     {
+        ret = (user_allocator::malloc)(chunk_size);
+        VALGRIND_MAKE_MEM_UNDEFINED(ret, chunk_size);
+     }
+     else
+     {
+        ret = *free_list.begin();
+        free_list.erase(free_list.begin());
+        VALGRIND_MAKE_MEM_UNDEFINED(ret, chunk_size);
+     }
+     used_list.insert(ret);
+     return ret;
+  }
+  void * ordered_malloc()
+  {
+     return (this->malloc)();
+  }
+  void * ordered_malloc(size_type n)
+  {
+     if(max_alloc_size && (n > max_alloc_size))
+        return 0;
+     void* ret = (user_allocator::malloc)(chunk_size * n);
+     used_list.insert(ret);
+     return ret;
+  }
+  void free BOOST_PREVENT_MACRO_SUBSTITUTION(void *const chunk)
+  {
+     if (!chunk)
+        return;
+	  
+     BOOST_ASSERT(used_list.count(chunk) == 1);
+     BOOST_ASSERT(free_list.count(chunk) == 0);
+     used_list.erase(chunk);
+     free_list.insert(chunk);
+     VALGRIND_MAKE_MEM_NOACCESS(chunk, chunk_size);
+  }
+  void ordered_free(void *const chunk)
+  {
+     return (this->free)(chunk);
+  }
+  void free BOOST_PREVENT_MACRO_SUBSTITUTION(void *const chunk, const size_type)
+  {
+     if (!chunk)
+        return;
+	  
+     BOOST_ASSERT(used_list.count(chunk) == 1);
+     BOOST_ASSERT(free_list.count(chunk) == 0);
+     used_list.erase(chunk);
+     (user_allocator::free)(static_cast<char*>(chunk));
+  }
+  void ordered_free(void *const chunk, const size_type n)
+  {
+     (this->free)(chunk, n);
+  }
+  bool is_from(void *const chunk) const
+  {
+     return used_list.count(chunk) || free_list.count(chunk);
+  }
+
+protected:
+   size_type chunk_size, max_alloc_size;
+   std::set<void*> free_list, used_list;
+};
+
+#endif
+
 } // namespace boost
 
 #ifdef BOOST_MSVC
Modified: sandbox/pool/libs/pool/test/Jamfile.v2
==============================================================================
--- sandbox/pool/libs/pool/test/Jamfile.v2	(original)
+++ sandbox/pool/libs/pool/test/Jamfile.v2	2012-07-12 16:43:49 EDT (Thu, 12 Jul 2012)
@@ -64,6 +64,28 @@
     [ run test_bug_6867.cpp  : : : [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no  ] : test_bug_6867_valgrind ]
     [ run test_threading.cpp  : : : <threading>multi <library>/boost/thread//boost_thread <toolset>gcc:<cxxflags>-Wno-attributes <toolset>gcc:<cxxflags>-Wno-missing-field-initializers [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1" : <build>no  ] : test_threading_valgrind ]
 
+#
+# The following tests test Boost.Pool's code with valgrind if it's available, and in any case with BOOST_POOL_VALGRIND defined
+# which has the effect of disabling any actual memory pooling:
+#
+    [ run test_simple_seg_storage.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_simple_seg_storage_valgrind_2 ]
+    [ run test_pool_alloc.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no  ] : test_pool_alloc_valgrind_2 ]
+    [ run pool_msvc_compiler_bug_test.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : pool_msvc_compiler_bug_test_valgrind_2 ]
+    [ run test_msvc_mem_leak_detect.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_msvc_mem_leak_detect_valgrind_2 ]
+    [ run test_bug_1252.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_1252_valgrind_2 ]
+    [ run test_bug_2696.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_2696_valgrind_2 ]
+    [ run test_bug_3349.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_3349_valgrind_2 ]
+    [ run test_bug_3789.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_3789_valgrind_2 ]
+    [ run test_bug_4960.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_4960_valgrind_2 ]
+    [ run test_bug_5526.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_5526_valgrind_2 ]
+    [ run test_bug_5902.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_5902_valgrind_2 ]
+    [ run test_bug_6561.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_6561_valgrind_2 ]
+    [ run test_bug_6701.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_6701_valgrind_2 ]
+    [ run test_bug_6865.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_6865_valgrind_2 ]
+    [ run test_bug_6867.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_bug_6867_valgrind_2 ]
+    [ run test_threading.cpp  : : : <threading>multi <library>/boost/thread//boost_thread <define>BOOST_POOL_VALGRIND=1 <toolset>gcc:<cxxflags>-Wno-attributes <toolset>gcc:<cxxflags>-Wno-missing-field-initializers [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] : test_threading_valgrind_2 ]
+    [ run-fail test_valgrind_fail_1.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] ]
+    [ run-fail test_valgrind_fail_2.cpp  : : : <define>BOOST_POOL_VALGRIND=1 [ check-target-builds valgrind_config_check : <testing.launcher>"valgrind --error-exitcode=1"  : <build>no ] ]
     ;
 
 
Modified: sandbox/pool/libs/pool/test/test_bug_3789.cpp
==============================================================================
--- sandbox/pool/libs/pool/test/test_bug_3789.cpp	(original)
+++ sandbox/pool/libs/pool/test/test_bug_3789.cpp	2012-07-12 16:43:49 EDT (Thu, 12 Jul 2012)
@@ -29,7 +29,12 @@
 {
   object::instances = 0;
   {
+#ifndef BOOST_POOL_VALGRIND
     static const int size = 1000000;
+#else
+    static const int size = 100000;
+#endif
+
     boost::object_pool<object> pool(1);		
   
     object **objects = new object *[size];
Modified: sandbox/pool/libs/pool/test/test_bug_6701.cpp
==============================================================================
--- sandbox/pool/libs/pool/test/test_bug_6701.cpp	(original)
+++ sandbox/pool/libs/pool/test/test_bug_6701.cpp	2012-07-12 16:43:49 EDT (Thu, 12 Jul 2012)
@@ -12,6 +12,7 @@
 
 int main()
 {
+#ifndef BOOST_POOL_VALGRIND
   boost::pool<> p(1024, std::numeric_limits<size_t>::max() / 768);
 
   void *x = p.malloc();
@@ -19,6 +20,7 @@
   
   void *y = p.ordered_malloc(std::numeric_limits<size_t>::max() / 768);
   BOOST_ASSERT(!y);
+#endif
 
   return 0;
 }
Modified: sandbox/pool/libs/pool/test/test_bug_6865.cpp
==============================================================================
--- sandbox/pool/libs/pool/test/test_bug_6865.cpp	(original)
+++ sandbox/pool/libs/pool/test/test_bug_6865.cpp	2012-07-12 16:43:49 EDT (Thu, 12 Jul 2012)
@@ -17,27 +17,53 @@
   for (int nSize = 1; nSize < 128; nSize = 2 * nSize + 1)
   {
     boost::pool<> p(nSize, 4);
-    p.malloc();
+    void *ptr = p.malloc();
 
+#ifndef BOOST_POOL_VALGRIND
     BOOST_ASSERT(p.get_size() == 4);
+#else
+    BOOST_ASSERT(p.get_size() == 1);
+#endif
 
     for (int k = 0; k < 4; k++)
       p.malloc();
 
+#ifndef BOOST_POOL_VALGRIND
     BOOST_ASSERT(p.get_size() == 4 + 8);
+#else
+    BOOST_ASSERT(p.get_size() == 1 + 4);
+#endif
+
+    p.free(ptr);
+
+#ifndef BOOST_POOL_VALGRIND
+    BOOST_ASSERT(p.get_size() == 4 + 8);
+#else
+    BOOST_ASSERT(p.get_size() == 1 + 4);
+#endif
 
     p.purge_memory();
     BOOST_ASSERT(p.get_size() == 0);
 
     p.malloc();
+    
+#ifndef BOOST_POOL_VALGRIND
     BOOST_ASSERT(p.get_size() == 4);
+#else
+    BOOST_ASSERT(p.get_size() == 1);
+#endif
   }
 
   // Test object_pool
   boost::object_pool<int> op(32);
   
   op.malloc();
+  
+#ifndef BOOST_POOL_VALGRIND
   BOOST_ASSERT(op.get_size() == 32);
+#else
+  BOOST_ASSERT(op.get_size() == 1);
+#endif
 
   return 0;
 }