Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56998 - in trunk: boost/pool libs/pool/test
From: steven_at_[hidden]
Date: 2009-10-19 12:26:53


Author: steven_watanabe
Date: 2009-10-19 12:26:52 EDT (Mon, 19 Oct 2009)
New Revision: 56998
URL: http://svn.boost.org/trac/boost/changeset/56998

Log:
Allow zero-sized blocks to be allocated by malloc_n. Fixes #386
Text files modified:
   trunk/boost/pool/simple_segregated_storage.hpp | 8 ++++++--
   trunk/libs/pool/test/test_pool_alloc.cpp | 7 +++++++
   2 files changed, 13 insertions(+), 2 deletions(-)

Modified: trunk/boost/pool/simple_segregated_storage.hpp
==============================================================================
--- trunk/boost/pool/simple_segregated_storage.hpp (original)
+++ trunk/boost/pool/simple_segregated_storage.hpp 2009-10-19 12:26:52 EDT (Mon, 19 Oct 2009)
@@ -147,7 +147,8 @@
     void free_n(void * const chunks, const size_type n,
         const size_type partition_size)
     {
- add_block(chunks, n * partition_size, partition_size);
+ if(n != 0)
+ add_block(chunks, n * partition_size, partition_size);
     }
 
     // pre: chunks was previously allocated from *this with the same
@@ -156,7 +157,8 @@
     void ordered_free_n(void * const chunks, const size_type n,
         const size_type partition_size)
     {
- add_ordered_block(chunks, n * partition_size, partition_size);
+ if(n != 0)
+ add_ordered_block(chunks, n * partition_size, partition_size);
     }
 };
 
@@ -247,6 +249,8 @@
 void * simple_segregated_storage<SizeType>::malloc_n(const size_type n,
     const size_type partition_size)
 {
+ if(n == 0)
+ return 0;
   void * start = &first;
   void * iter;
   do

Modified: trunk/libs/pool/test/test_pool_alloc.cpp
==============================================================================
--- trunk/libs/pool/test/test_pool_alloc.cpp (original)
+++ trunk/libs/pool/test/test_pool_alloc.cpp 2009-10-19 12:26:52 EDT (Mon, 19 Oct 2009)
@@ -215,6 +215,13 @@
   // clean up memory leak
   tmp->~tester();
   boost::pool_allocator<tester>::deallocate(tmp, 1);
+
+ // test allocating zero elements
+ {
+ boost::pool_allocator<tester> alloc;
+ tester* ip = alloc.allocate(0);
+ alloc.deallocate(ip, 0);
+ }
 }
 
 // This is a wrapper around a UserAllocator. It just registers alloc/dealloc


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk