tnintemann / rpms / boost

Forked from rpms/boost 3 years ago
Clone

Blame SOURCES/boost-1.58.0-pool.patch

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