Ticket #6701: boost-1.58.0-pool.patch

File boost-1.58.0-pool.patch, 4.6 KB (added by jwakely <jwakely.boost@…>, 7 years ago)

Updated patch against 1.58.0, fixing shadowing warning.

  • boost/pool/pool.hpp

     
    2727#include <boost/pool/poolfwd.hpp>
    2828
     29// std::numeric_limits
     30#include <boost/limits.hpp>
    2931// boost::integer::static_lcm
    3032#include <boost/integer/common_factor_ct.hpp>
     
    358360    }
    359361
     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 = math::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
    360369    static void * & nextof(void * const ptr)
    361370    { //! \returns Pointer dereferenced.
     
    377388      //!   the first time that object needs to allocate system memory.
    378389      //!   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);
    380393    }
    381394
     
    400413    }
    401414    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());
    405418    }
    406419    size_type get_max_size() const
     
    410423    void set_max_size(const size_type nmax_size)
    411424    { //! 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());
    413427    }
    414428    size_type get_requested_size() const
     
    713727  BOOST_USING_STD_MIN();
    714728  if(!max_size)
    715     next_size <<= 1;
     729    set_next_size(next_size << 1);
    716730  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));
    718732
    719733  //  initialize it,
     
    753767  BOOST_USING_STD_MIN();
    754768  if(!max_size)
    755     next_size <<= 1;
     769    set_next_size(next_size << 1);
    756770  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));
    758772
    759773  //  initialize it,
     
    797811  //! \returns Address of chunk n if allocated ok.
    798812  //! \returns 0 if not enough memory for n chunks.
     813  if (n > max_chunks())
     814    return 0;
    799815
    800816  const size_type partition_size = alloc_size();
     
    845861  BOOST_USING_STD_MIN();
    846862  if(!max_size)
    847     next_size <<= 1;
     863    set_next_size(next_size << 1);
    848864  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));
    850866
    851867  //  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
     13int 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}