Fix a bug which was causing the memory area stuff to fail.

I should probably try to be less clever and use memory area's lower
bounds as the key, and do the extra work required to get that working.


[SVN r42587]
This commit is contained in:
Daniel James
2008-01-07 21:05:42 +00:00
parent 86e01c9c4c
commit 7d128006e1

View File

@@ -215,18 +215,7 @@ namespace test
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);
}
};
@@ -239,7 +228,22 @@ namespace test
int tag_;
};
typedef std::map<memory_area, memory_track> allocated_memory_type;
// 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> allocated_memory_type;
allocated_memory_type allocated_memory;
unsigned int count_allocators = 0;
unsigned int count_allocations = 0;
@@ -293,12 +297,12 @@ namespace test
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));
if(pos == allocated_memory.end()) {
BOOST_ERROR("Deallocating unknown pointer.");
} else {
BOOST_TEST(pos->first.start == ptr);
BOOST_TEST(pos->first.end == (char*) ptr + n * size);
BOOST_TEST(pos->first.end == (char*) ptr + n * size - 1);
BOOST_TEST(pos->second.tag_ == tag);
BOOST_TEST(pos->second.constructed_ == 0);
allocated_memory.erase(pos);
@@ -307,10 +311,10 @@ namespace test
if(count_allocations > 0) --count_allocations;
}
void track_construct(void* ptr, std::size_t /*size*/, int tag)
void track_construct(void* ptr, 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 + size));
if(pos == allocated_memory.end()) {
BOOST_ERROR("Constructing unknown pointer.");
}
@@ -321,10 +325,10 @@ namespace test
++count_constructions;
}
void track_destroy(void* ptr, std::size_t /*size*/, int tag)
void track_destroy(void* ptr, 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 + size));
if(pos == allocated_memory.end())
BOOST_ERROR("Destroying unknown pointer.");
else {