tnintemann / rpms / boost

Forked from rpms/boost 3 years ago
Clone

Blame SOURCES/boost-1.50.0-pool.patch

6e52e0
Index: boost/pool/pool.hpp
6e52e0
===================================================================
6e52e0
--- boost/pool/pool.hpp	(revision 78317)
6e52e0
+++ boost/pool/pool.hpp	(revision 78326)
6e52e0
@@ -27,4 +27,6 @@
6e52e0
 #include <boost/pool/poolfwd.hpp>
6e52e0
 
6e52e0
+// std::numeric_limits
6e52e0
+#include <boost/limits.hpp>
6e52e0
 // boost::math::static_lcm
6e52e0
 #include <boost/math/common_factor_ct.hpp>
6e52e0
@@ -358,4 +360,13 @@
6e52e0
     }
6e52e0
 
6e52e0
+    size_type max_chunks() const
6e52e0
+    { //! Calculated maximum number of memory chunks that can be allocated in a single call by this Pool.
6e52e0
+      size_type partition_size = alloc_size();
6e52e0
+      size_type POD_size = math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
6e52e0
+      size_type max_chunks = (std::numeric_limits<size_type>::max() - POD_size) / alloc_size();
6e52e0
+    
6e52e0
+      return max_chunks;
6e52e0
+    }
6e52e0
+
6e52e0
     static void * & nextof(void * const ptr)
6e52e0
     { //! \returns Pointer dereferenced.
6e52e0
@@ -377,5 +388,7 @@
6e52e0
       //!   the first time that object needs to allocate system memory.
6e52e0
       //!   The default is 32. This parameter may not be 0.
6e52e0
-      //! \param nmax_size is the maximum number of chunks to allocate in one block.
6e52e0
+      //! \param nmax_size is the maximum number of chunks to allocate in one block.			
6e52e0
+      set_next_size(nnext_size);
6e52e0
+      set_max_size(nmax_size);
6e52e0
     }
6e52e0
 
6e52e0
@@ -400,7 +413,7 @@
6e52e0
     }
6e52e0
     void set_next_size(const size_type nnext_size)
6e52e0
-    { //! Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should never be set to 0.
6e52e0
-      //! \returns nnext_size.
6e52e0
-      next_size = start_size = nnext_size;
6e52e0
+    { //! Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should never be set to 0.     
6e52e0
+      BOOST_USING_STD_MIN();
6e52e0
+      next_size = start_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nnext_size, max_chunks());
6e52e0
     }
6e52e0
     size_type get_max_size() const
6e52e0
@@ -410,5 +423,6 @@
6e52e0
     void set_max_size(const size_type nmax_size)
6e52e0
     { //! Set max_size.
6e52e0
-      max_size = nmax_size;
6e52e0
+      BOOST_USING_STD_MIN();
6e52e0
+      max_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nmax_size, max_chunks());
6e52e0
     }
6e52e0
     size_type get_requested_size() const
6e52e0
@@ -713,7 +727,7 @@
6e52e0
   BOOST_USING_STD_MIN();
6e52e0
   if(!max_size)
6e52e0
-    next_size <<= 1;
6e52e0
+    set_next_size(next_size << 1);
6e52e0
   else if( next_size*partition_size/requested_size < max_size)
6e52e0
-    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
6e52e0
+    set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
6e52e0
 
6e52e0
   //  initialize it,
6e52e0
@@ -753,7 +767,7 @@
6e52e0
   BOOST_USING_STD_MIN();
6e52e0
   if(!max_size)
6e52e0
-    next_size <<= 1;
6e52e0
+    set_next_size(next_size << 1);
6e52e0
   else if( next_size*partition_size/requested_size < max_size)
6e52e0
-    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
6e52e0
+    set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
6e52e0
 
6e52e0
   //  initialize it,
6e52e0
@@ -797,4 +811,6 @@
6e52e0
   //! \returns Address of chunk n if allocated ok.
6e52e0
   //! \returns 0 if not enough memory for n chunks.
6e52e0
+  if (n > max_chunks())
6e52e0
+    return 0;
6e52e0
 
6e52e0
   const size_type partition_size = alloc_size();
6e52e0
@@ -845,7 +861,7 @@
6e52e0
   BOOST_USING_STD_MIN();
6e52e0
   if(!max_size)
6e52e0
-    next_size <<= 1;
6e52e0
+    set_next_size(next_size << 1);
6e52e0
   else if( next_size*partition_size/requested_size < max_size)
6e52e0
-    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
6e52e0
+    set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
6e52e0
 
6e52e0
   //  insert it into the list,
6e52e0
Index: libs/pool/test/test_bug_6701.cpp
6e52e0
===================================================================
6e52e0
--- libs/pool/test/test_bug_6701.cpp	(revision 78326)
6e52e0
+++ libs/pool/test/test_bug_6701.cpp	(revision 78326)
6e52e0
@@ -0,0 +1,27 @@
6e52e0
+/* Copyright (C) 2012 Étienne Dupuis
6e52e0
+* 
6e52e0
+* Use, modification and distribution is subject to the 
6e52e0
+* Boost Software License, Version 1.0. (See accompanying
6e52e0
+* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6e52e0
+*/
6e52e0
+
6e52e0
+// Test of bug #6701 (https://svn.boost.org/trac/boost/ticket/6701)
6e52e0
+
6e52e0
+#include <boost/pool/object_pool.hpp>
6e52e0
+#include <boost/limits.hpp>
6e52e0
+
6e52e0
+int main()
6e52e0
+{
6e52e0
+  boost::pool<> p(1024, std::numeric_limits<size_t>::max() / 768);
6e52e0
+
6e52e0
+  void *x = p.malloc();
6e52e0
+  BOOST_ASSERT(!x);
6e52e0
+  
6e52e0
+  BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_next_size());
6e52e0
+  BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_max_size());
6e52e0
+
6e52e0
+  void *y = p.ordered_malloc(std::numeric_limits<size_t>::max() / 768);
6e52e0
+  BOOST_ASSERT(!y);
6e52e0
+
6e52e0
+  return 0;
6e52e0
+}