Blame SOURCES/boost-1.58.0-pool.patch

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