tnintemann / rpms / boost

Forked from rpms/boost 3 years ago
Clone

Blame SOURCES/boost-1.50.0-pool.patch

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