Ticket #6701: boost-1.58.0-pool.2.patch
File boost-1.58.0-pool.2.patch, 4.6 KB (added by , 7 years ago) |
---|
-
boost/pool/pool.hpp
27 27 #include <boost/pool/poolfwd.hpp> 28 28 29 // std::numeric_limits 30 #include <boost/limits.hpp> 29 31 // boost::integer::static_lcm 30 32 #include <boost/integer/common_factor_ct.hpp> … … 358 360 } 359 361 362 size_type max_chunks() const 363 { //! Calculated maximum number of memory chunks that can be allocated in a single call by this Pool. 364 size_type partition_size = alloc_size(); 365 size_type POD_size = integer::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type); 366 return (std::numeric_limits<size_type>::max() - POD_size) / alloc_size(); 367 } 368 360 369 static void * & nextof(void * const ptr) 361 370 { //! \returns Pointer dereferenced. … … 377 388 //! the first time that object needs to allocate system memory. 378 389 //! The default is 32. This parameter may not be 0. 379 //! \param nmax_size is the maximum number of chunks to allocate in one block. 390 //! \param nmax_size is the maximum number of chunks to allocate in one block. 391 set_next_size(nnext_size); 392 set_max_size(nmax_size); 380 393 } 381 394 … … 400 413 } 401 414 void set_next_size(const size_type nnext_size) 402 { //! 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. 403 //! \returns nnext_size.404 next_size = start_size = nnext_size;415 { //! 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. 416 BOOST_USING_STD_MIN(); 417 next_size = start_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nnext_size, max_chunks()); 405 418 } 406 419 size_type get_max_size() const … … 410 423 void set_max_size(const size_type nmax_size) 411 424 { //! Set max_size. 412 max_size = nmax_size; 425 BOOST_USING_STD_MIN(); 426 max_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nmax_size, max_chunks()); 413 427 } 414 428 size_type get_requested_size() const … … 713 727 BOOST_USING_STD_MIN(); 714 728 if(!max_size) 715 next_size <<= 1;729 set_next_size(next_size << 1); 716 730 else if( next_size*partition_size/requested_size < max_size) 717 next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);731 set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size)); 718 732 719 733 // initialize it, … … 753 767 BOOST_USING_STD_MIN(); 754 768 if(!max_size) 755 next_size <<= 1;769 set_next_size(next_size << 1); 756 770 else if( next_size*partition_size/requested_size < max_size) 757 next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);771 set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size)); 758 772 759 773 // initialize it, … … 797 811 //! \returns Address of chunk n if allocated ok. 798 812 //! \returns 0 if not enough memory for n chunks. 813 if (n > max_chunks()) 814 return 0; 799 815 800 816 const size_type partition_size = alloc_size(); … … 845 861 BOOST_USING_STD_MIN(); 846 862 if(!max_size) 847 next_size <<= 1;863 set_next_size(next_size << 1); 848 864 else if( next_size*partition_size/requested_size < max_size) 849 next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);865 set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size)); 850 866 851 867 // insert it into the list, -
libs/pool/test/test_bug_6701.cpp
1 /* Copyright (C) 2012 Étienne Dupuis 2 * 3 * Use, modification and distribution is subject to the 4 * Boost Software License, Version 1.0. (See accompanying 5 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 8 // Test of bug #6701 (https://svn.boost.org/trac/boost/ticket/6701) 9 10 #include <boost/pool/object_pool.hpp> 11 #include <boost/limits.hpp> 12 13 int main() 14 { 15 boost::pool<> p(1024, std::numeric_limits<size_t>::max() / 768); 16 17 void *x = p.malloc(); 18 BOOST_ASSERT(!x); 19 20 BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_next_size()); 21 BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_max_size()); 22 23 void *y = p.ordered_malloc(std::numeric_limits<size_t>::max() / 768); 24 BOOST_ASSERT(!y); 25 26 return 0; 27 }