Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-01-08 07:05:59


Author: danieljames
Date: 2008-01-08 07:05:59 EST (Tue, 08 Jan 2008)
New Revision: 42611
URL: http://svn.boost.org/trac/boost/changeset/42611

Log:
More memory_area fixes - there's some shameful code duplication that I'll have to factor out.

Text files modified:
   branches/unordered/trunk/libs/unordered/test/objects/exception.hpp | 32 ++++++++++++++++++--------------
   branches/unordered/trunk/libs/unordered/test/objects/test.hpp | 2 +-
   2 files changed, 19 insertions(+), 15 deletions(-)

Modified: branches/unordered/trunk/libs/unordered/test/objects/exception.hpp
==============================================================================
--- branches/unordered/trunk/libs/unordered/test/objects/exception.hpp (original)
+++ branches/unordered/trunk/libs/unordered/test/objects/exception.hpp 2008-01-08 07:05:59 EST (Tue, 08 Jan 2008)
@@ -192,18 +192,7 @@
                 memory_area(void const* s, void const* e)
                     : start(s), end(e)
                 {
- }
-
- // This is a bit dodgy as it defines overlapping
- // areas as 'equal', so this isn't a total ordering.
- // But it is for non-overlapping memory regions - which
- // is what'll be stored.
- //
- // All searches will be for areas entirely contained by
- // a member of the set - so it should find the area that contains
- // the region that is searched for.
- bool operator<(memory_area const& other) const {
- return end < other.start;
+ BOOST_ASSERT(start != end);
                 }
             };
 
@@ -214,7 +203,22 @@
                 int tag_;
             };
 
- typedef std::map<memory_area, memory_track, std::less<memory_area>,
+ // This is a bit dodgy as it defines overlapping
+ // areas as 'equal', so this isn't a total ordering.
+ // But it is for non-overlapping memory regions - which
+ // is what'll be stored.
+ //
+ // All searches will be for areas entirely contained by
+ // a member of the set - so it should find the area that contains
+ // the region that is searched for.
+
+ struct memory_area_compare {
+ bool operator()(memory_area const& x, memory_area const& y) const {
+ return x.end <= y.start;
+ }
+ };
+
+ typedef std::map<memory_area, memory_track, memory_area_compare,
                 test::malloc_allocator<std::pair<memory_area const, memory_track> > >
                 allocated_memory_type;
             allocated_memory_type allocated_memory;
@@ -270,7 +274,7 @@
         void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag)
         {
             allocated_memory_type::iterator pos
- = allocated_memory.find(memory_area(ptr, ptr));
+ = allocated_memory.find(memory_area(ptr, (char*) ptr + n * size));
             if(pos == allocated_memory.end()) {
                 BOOST_ERROR("Deallocating unknown pointer.");
             } else {

Modified: branches/unordered/trunk/libs/unordered/test/objects/test.hpp
==============================================================================
--- branches/unordered/trunk/libs/unordered/test/objects/test.hpp (original)
+++ branches/unordered/trunk/libs/unordered/test/objects/test.hpp 2008-01-08 07:05:59 EST (Tue, 08 Jan 2008)
@@ -297,7 +297,7 @@
         void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag)
         {
             allocated_memory_type::iterator pos
- = allocated_memory.find(memory_area(ptr, (char*) ptr + n));
+ = allocated_memory.find(memory_area(ptr, (char*) ptr + n * size));
             if(pos == allocated_memory.end()) {
                 BOOST_ERROR("Deallocating unknown pointer.");
             } else {


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