|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69235 - in sandbox/guild/pool: boost/pool libs/pool/doc libs/pool/test
From: john_at_[hidden]
Date: 2011-02-24 05:25:42
Author: johnmaddock
Date: 2011-02-24 05:25:39 EST (Thu, 24 Feb 2011)
New Revision: 69235
URL: http://svn.boost.org/trac/boost/changeset/69235
Log:
Fixes issue #1252.
Add test case for #1252.
Update docs accordingly.
Refs #1252.
Correct return value from test_pool_alloc.cpp.
Text files modified:
sandbox/guild/pool/boost/pool/pool.hpp | 19 ++++++++-
sandbox/guild/pool/libs/pool/doc/jamfile.v2 | 22 ++++------
sandbox/guild/pool/libs/pool/doc/pool.qbk | 10 ++++-
sandbox/guild/pool/libs/pool/test/test_bug_1252.cpp | 76 +++++++++++++++++++++++++++------------
sandbox/guild/pool/libs/pool/test/test_pool_alloc.cpp | 2
5 files changed, 87 insertions(+), 42 deletions(-)
Modified: sandbox/guild/pool/boost/pool/pool.hpp
==============================================================================
--- sandbox/guild/pool/boost/pool/pool.hpp (original)
+++ sandbox/guild/pool/boost/pool/pool.hpp 2011-02-24 05:25:39 EST (Thu, 24 Feb 2011)
@@ -32,6 +32,10 @@
#include <boost/pool/detail/gcd_lcm.hpp>
// boost::simple_segregated_storage
#include <boost/pool/simple_segregated_storage.hpp>
+// boost::alignment_of
+#include <boost/type_traits/alignment_of.hpp>
+// BOOST_ASSERT
+#include <boost/assert.hpp>
#ifdef BOOST_POOL_INSTRUMENT
#include <iostream>
@@ -252,6 +256,8 @@
private:
BOOST_STATIC_CONSTANT(unsigned, min_alloc_size =
(::boost::details::pool::ct_lcm<sizeof(void *), sizeof(size_type)>::value) );
+ BOOST_STATIC_CONSTANT(unsigned, min_align =
+ (::boost::details::pool::ct_lcm< ::boost::alignment_of<void *>::value, ::boost::alignment_of<size_type>::value>::value) );
//! \returns 0 if out-of-memory.
//! Called if malloc/ordered_malloc needs to resize the free list.
@@ -304,10 +310,17 @@
size_type alloc_size() const
{ //! Calculated size of the memory chunks that will be allocated by this Pool.
- //! For alignment reasons, this is defined to be lcm(requested_size, sizeof(void *), sizeof(size_type)).
//! \returns allocated size.
- const unsigned min_size = min_alloc_size;
- return details::pool::lcm<size_type>(requested_size, min_size);
+ // For alignment reasons, this used to be defined to be lcm(requested_size, sizeof(void *), sizeof(size_type)),
+ // but is now more parsimonious: just rounding up to the minimum required alignment of our housekeeping data
+ // when required. This works provided all alignments are powers of two.
+ unsigned s = (std::max)(requested_size, static_cast<unsigned>(min_alloc_size));
+ unsigned rem = s % min_align;
+ if(rem)
+ s += min_align - rem;
+ BOOST_ASSERT(s >= min_alloc_size);
+ BOOST_ASSERT(s % min_align == 0);
+ return s;
}
static void * & nextof(void * const ptr)
Modified: sandbox/guild/pool/libs/pool/doc/jamfile.v2
==============================================================================
--- sandbox/guild/pool/libs/pool/doc/jamfile.v2 (original)
+++ sandbox/guild/pool/libs/pool/doc/jamfile.v2 2011-02-24 05:25:39 EST (Thu, 24 Feb 2011)
@@ -8,7 +8,6 @@
# See http://www.boost.org for updates, documentation, and revision history.
path-constant nav_images : html/images/ ; # png and svg images for home, next, note, tip...
-#path-constant images_location : html/images/ ; # location of SVG and PNG images referenced by Quickbook.
path-constant images_location : html ; # location of SVG and PNG images referenced by Quickbook.
echo "images_location" $(images_location) ; # \guild\pool\libs\pool\doc\html
@@ -51,7 +50,6 @@
using doxygen ; # Required if you want to use Doxygen.
using quickbook ;
-# using auto-index ; # Required if you want to use autoindexing (see above).
doxygen autodoc
:
@@ -71,7 +69,7 @@
# Much better to send message to a logfile than the default stderr.
# and make sure that there are no Doxygen errors or significant warnings in the log file.
<doxygen:param>RECURSIVE=NO # Search recursively down subdirectories.
- <doxygen:param>EXTRACT_ALL=NO
+ <doxygen:param>EXTRACT_ALL=NO
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
<doxygen:param>EXTRACT_PRIVATE=NO
<doxygen:param>EXPAND_ONLY_PREDEF=YES
@@ -104,7 +102,7 @@
<xsl:param>boost.image=Boost # options are: none (no logo), Boost (for boost.png), or your own logo, for example, inspired_by_boost.png
<xsl:param>boost.image.src=./images/boost.png #
<xsl:param>boost.image.w=180 # Width of logo in pixels. (JM has W = 162, h = 46)
- <xsl:param>boost.image.h=90 # Height of logo in pixels.
+ <xsl:param>boost.image.h=90 # Height of logo in pixels.
# Options for html and pdf
# ========================
@@ -168,16 +166,14 @@
<format>pdf:<xsl:param>boost.url.prefix=I:/boost-sandbox/guild/pool/libs/pool/doc/html
<dependency>autodoc #
-
+ <dependency>css-install
+ <dependency>png-install
+ <dependency>svg-install
;
-#install pdf-install : standalone : <location>. <install-type>PDF ; # copy pdf to libs/pool/doc, . means same location as .qbk = /doc .
-# for pdf moves pool.modified.pdf instead.
-
-# install pdf-install : standalone : <install-type>PDF <location>.<name>math.pdf ;
-
-#install pdf-install : standalone : <location>.<name>math.pdf <install-type>PDF ;
-#install pdf-install : standalone : <install-type>PDF <location>. <name>type_traits.pdf ;
install pdf-install : standalone : <install-type>PDF <location>. <name>pool.pdf ;
-# copy pdf to libs/pool/doc, same location as .qbk .
+path-constant boost-root : [ modules.peek : BOOST ] ;
+install css-install : $(boost-root)/doc/src/boostbook.css : <location>html ;
+install png-install : [ glob $(boost-root)/doc/src/images/*.png $(boost-root)/boost.png ] : <location>html/images ;
+install svg-install : [ glob $(boost-root)/doc/src/images/*.svg ] : <location>html/images ;
Modified: sandbox/guild/pool/libs/pool/doc/pool.qbk
==============================================================================
--- sandbox/guild/pool/libs/pool/doc/pool.qbk (original)
+++ sandbox/guild/pool/libs/pool/doc/pool.qbk 2011-02-24 05:25:39 EST (Thu, 24 Feb 2011)
@@ -809,8 +809,9 @@
but that is stored as a pointer to void and cast when necessary,
to simplify alignment requirements to the three types above.
-Therefore, `alloc_size` is defined to be the LCM (least common multiple)
-of the sizes of the three types above.
+Therefore, `alloc_size` is defined to be the largest of the sizes above, rounded up to be a multiple
+of all three sizes. This guarantees alignment provided all alignments are powers of two: something that
+appears to be true on all known platforms.
[h4 A Look at the Memory Block]
@@ -1028,6 +1029,11 @@
[section [*Version 2.0.0, January 11, 2011] ['Documentation and testing revision]]
[*Features:]
+* Fix issues
+[@https://svn.boost.org/trac/boost/ticket/1252 1252],
+[@https://svn.boost.org/trac/boost/ticket/4960 4960],
+[@https://svn.boost.org/trac/boost/ticket/2696 2696].
+
* Documentation converted and rewritten and revised
by Paul A. Bristow using Quickbook, Doxygen, for html and pdf,
based on Stephen Cleary's html version, Revised 05 December, 2006.
Modified: sandbox/guild/pool/libs/pool/test/test_bug_1252.cpp
==============================================================================
--- sandbox/guild/pool/libs/pool/test/test_bug_1252.cpp (original)
+++ sandbox/guild/pool/libs/pool/test/test_bug_1252.cpp 2011-02-24 05:25:39 EST (Thu, 24 Feb 2011)
@@ -1,36 +1,66 @@
-/* Copyright (C) 2011 Kwan Ting Chan
- * Based from bug report submitted by Xiaohan Wang
- *
- * Use, modification and distribution is subject to the
- * Boost Software License, Version 1.0. (See accompanying
- * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
- */
+/* Copyright (C) 2011 John Maddock
+*
+* Use, modification and distribution is subject to the
+* Boost Software License, Version 1.0. (See accompanying
+* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+*/
-// Test of bug #3349 (https://svn.boost.org/trac/boost/ticket/3349)
+// Test of bug #1252 (https://svn.boost.org/trac/boost/ticket/1252)
#include <boost/pool/pool.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/type_traits/alignment_of.hpp>
+#include <cstring>
struct limited_allocator_new_delete
{
- typedef std::size_t size_type;
- typedef std::ptrdiff_t difference_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
- static char * malloc BOOST_PREVENT_MACRO_SUBSTITUTION(const size_type bytes)
- {
- if(bytes > 2000)
- return 0;
- return new (std::nothrow) char[bytes];
- }
- static void free BOOST_PREVENT_MACRO_SUBSTITUTION(char * const block)
- {
- delete [] block;
- }
+ static char * malloc BOOST_PREVENT_MACRO_SUBSTITUTION(const size_type bytes)
+ {
+ if(bytes > 1510 * 32)
+ return 0;
+ return new (std::nothrow) char[bytes];
+ }
+ static void free BOOST_PREVENT_MACRO_SUBSTITUTION(char * const block)
+ {
+ delete [] block;
+ }
};
+template <class T>
+void test_alignment(T)
+{
+ unsigned align = boost::alignment_of<T>::value;
+ boost::pool<> p(sizeof(T));
+ unsigned limit = 100000;
+ for(unsigned i = 0; i < limit; ++i)
+ {
+ void* ptr = p.malloc();
+ BOOST_TEST(reinterpret_cast<std::size_t>(ptr) % align == 0);
+ // Trample over the memory just to be sure the allocated block is big enough,
+ // if it's not, we'll trample over the next block as well (and our internal housekeeping).
+ std::memset(ptr, 0xff, sizeof(T));
+ }
+}
+
int main()
{
- boost::pool<limited_allocator_new_delete> po(1501);
- void* p = po.malloc();
- return p == 0 ? 1 : 0;
+ boost::pool<limited_allocator_new_delete> po(1501);
+ void* p = po.malloc();
+ BOOST_TEST(p != 0);
+
+ test_alignment(char(0));
+ test_alignment(short(0));
+ test_alignment(int(0));
+ test_alignment(long(0));
+ test_alignment(double(0));
+ test_alignment(float(0));
+ test_alignment((long double)(0));
+#ifndef BOOST_NO_LONG_LONG
+ test_alignment((long long)(0));
+#endif
+ return boost::report_errors();
}
Modified: sandbox/guild/pool/libs/pool/test/test_pool_alloc.cpp
==============================================================================
--- sandbox/guild/pool/libs/pool/test/test_pool_alloc.cpp (original)
+++ sandbox/guild/pool/libs/pool/test/test_pool_alloc.cpp 2011-02-24 05:25:39 EST (Thu, 24 Feb 2011)
@@ -286,5 +286,5 @@
test_mem_usage();
test_void();
- return 0;
+ return boost::report_errors();
}
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