[geos-commits] r3633 - in trunk: src/util tests/unit/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed May 16 12:47:18 EDT 2012
Author: strk
Date: 2012-05-16 09:47:18 -0700 (Wed, 16 May 2012)
New Revision: 3633
Modified:
trunk/src/util/CustomAllocators.cpp
trunk/tests/unit/capi/GEOSCustomAllocatorTest.cpp
Log:
Fix CustomAllocators to really use the custom allocators
Improve the unit test for it
Modified: trunk/src/util/CustomAllocators.cpp
===================================================================
--- trunk/src/util/CustomAllocators.cpp 2012-05-16 12:20:53 UTC (rev 3632)
+++ trunk/src/util/CustomAllocators.cpp 2012-05-16 16:47:18 UTC (rev 3633)
@@ -45,15 +45,14 @@
}
}
-
void*
operator new (std::size_t size, const std::nothrow_t&) throw () {
//std::cout << "...new(" << size << ") called" << std::endl;
- return std::malloc(size);
+ return geos::util::CustomAllocators::geos_alloc(size);
}
void operator delete (void *ptr) throw () {
//std::cout << "...delete(" << ptr << ") called" << std::endl;
- if ( ptr ) std::free(ptr);
+ if ( ptr ) geos::util::CustomAllocators::geos_free(ptr);
}
Modified: trunk/tests/unit/capi/GEOSCustomAllocatorTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSCustomAllocatorTest.cpp 2012-05-16 12:20:53 UTC (rev 3632)
+++ trunk/tests/unit/capi/GEOSCustomAllocatorTest.cpp 2012-05-16 16:47:18 UTC (rev 3633)
@@ -20,6 +20,7 @@
struct test_capicustomallocators_data
{
static int alloc_count;
+ static int dealloc_count;
static void notice(const char *fmt, ...)
{
@@ -44,7 +45,7 @@
static void t_free(void *ptr)
{
//notice("t_free(%p)", ptr);
- --alloc_count;
+ ++dealloc_count;
std::free(ptr);
}
@@ -52,8 +53,6 @@
{
GEOS_setAllocator(t_alloc);
GEOS_setFreer(t_free);
-
- alloc_count = 0;
}
~test_capicustomallocators_data()
@@ -63,6 +62,7 @@
};
int test_capicustomallocators_data::alloc_count = 0;
+ int test_capicustomallocators_data::dealloc_count = 0;
typedef test_group<test_capicustomallocators_data> group;
typedef group::object object;
@@ -78,12 +78,15 @@
template<>
void object::test<1>()
{
- alloc_count = 0;
+ alloc_count = dealloc_count = 0;
initGEOS(notice, notice);
+ notice("%d allocs, %d deallocs after initGEOS", alloc_count, dealloc_count);
finishGEOS();
+ notice("%d allocs, %d deallocs after finishGEOS", alloc_count, dealloc_count);
- ensure_equals(alloc_count, 0);
+ ensure(alloc_count > 0);
+ ensure_equals(alloc_count, dealloc_count);
}
/// WKTReader
@@ -91,18 +94,45 @@
template<>
void object::test<2>()
{
- alloc_count = 0;
+ alloc_count = dealloc_count = 0;
+ int tmpcount = 0;
initGEOS(notice, notice);
+ ensure("initGEOS didn't alloc", alloc_count > tmpcount);
+ notice("%d allocs, %d deallocs after initGEOS", alloc_count, dealloc_count);
+
+ tmpcount = alloc_count;
GEOSWKTReader* reader = GEOSWKTReader_create();
+ ensure("GEOSWKTReader_create didn't alloc", alloc_count > tmpcount);
+
+ notice("%d allocs, %d deallocs after GEOSWKTReader_create", alloc_count, dealloc_count);
+
+ tmpcount = alloc_count;
GEOSGeometry* g = GEOSWKTReader_read(reader, "POINT(0 0)");
+ ensure("GEOSWKTReader_read didn't alloc", alloc_count > tmpcount);
+
+ notice("%d allocs, %d deallocs after GEOSWKTReader_read", alloc_count, dealloc_count);
+
+ tmpcount = dealloc_count;
GEOSGeom_destroy(g);
+ ensure("GEOSGeom_destroy didn't dealloc", dealloc_count > tmpcount);
+
+ notice("%d allocs, %d deallocs after GEOSGeom_destroy", alloc_count, dealloc_count);
+
+ tmpcount = dealloc_count;
GEOSWKTReader_destroy(reader);
+ ensure("GEOSWKTReader_destroy didn't dealloc", dealloc_count > tmpcount);
+ notice("%d allocs, %d deallocs after GEOSWKTReader_destroy", alloc_count, dealloc_count);
+
+ tmpcount = dealloc_count;
finishGEOS();
+ ensure("finishGEOS didn't dealloc", dealloc_count > tmpcount);
- ensure_equals(alloc_count, 0);
+ notice("%d allocs, %d deallocs after finishGEOS", alloc_count, dealloc_count);
+
+ ensure_equals(alloc_count, dealloc_count);
}
More information about the geos-commits
mailing list