[geos-commits] r3647 - in trunk: . capi include/geos/util src/util tests/unit tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Fri May 25 08:50:53 PDT 2012


Author: strk
Date: 2012-05-25 08:50:38 -0700 (Fri, 25 May 2012)
New Revision: 3647

Removed:
   trunk/include/geos/util/CustomAllocators.h
   trunk/src/util/CustomAllocators.cpp
   trunk/tests/unit/capi/GEOSCustomAllocatorTest.cpp
Modified:
   trunk/NEWS
   trunk/capi/geos_ts_c.cpp
   trunk/include/geos/util/Makefile.am
   trunk/src/util/Makefile.am
   trunk/tests/unit/Makefile.am
Log:
Revert the whole custom memory allocation work (#540)

It wasn't well done. Pity.

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2012-05-25 15:26:58 UTC (rev 3646)
+++ trunk/NEWS	2012-05-25 15:50:38 UTC (rev 3647)
@@ -4,7 +4,6 @@
 - New things:
   - CAPI: GEOSNode (#496) - PHP: Geometry->node
   - GeometryPrecisionReducer class
-  - Allow passing custom memory managment functions (#540)
 - C++ API changes:
   - New noding::GeometryNoder class
   - Added BufferOp::setSingleSided 

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2012-05-25 15:26:58 UTC (rev 3646)
+++ trunk/capi/geos_ts_c.cpp	2012-05-25 15:50:38 UTC (rev 3647)
@@ -58,7 +58,6 @@
 #include <geos/operation/relate/RelateOp.h>
 #include <geos/operation/sharedpaths/SharedPathsOp.h>
 #include <geos/linearref/LengthIndexedLine.h>
-#include <geos/util/CustomAllocators.h>
 #include <geos/util/IllegalArgumentException.h>
 #include <geos/util/UniqueCoordinateArrayFilter.h>
 #include <geos/util/Machine.h>
@@ -157,56 +156,12 @@
 extern "C" const char GEOS_DLL *GEOSjtsport();
 extern "C" char GEOS_DLL *GEOSasText(Geometry *g1);
 
-// --- Custom memory allocators -------------------------------- {
-using geos::util::CustomAllocators::GEOSAllocator;
-using geos::util::CustomAllocators::GEOSDeallocator;
 
-GEOSAllocator geos_alloc = std::malloc;
-GEOSDeallocator geos_free = std::free; 
-
-GEOSAllocator
-GEOS_setAllocator(GEOSAllocator nf)
-{
-  GEOSAllocator of = geos_alloc;
-  geos_alloc = nf;
-  geos::util::CustomAllocators::setAllocator(geos_alloc);
-  return of;
-}
-
-GEOSDeallocator
-GEOS_setDeallocator(GEOSDeallocator nf)
-{
-  GEOSDeallocator of = geos_free;
-  geos_free = nf;
-  geos::util::CustomAllocators::setDeallocator(geos_free);
-  return of;
-}
-
-void*
-operator new (std::size_t size, const std::nothrow_t&) throw () {
-        //cout << "new(" << size << ") called" << endl;
-        return geos_alloc(size);
-}
-
-void operator delete (void *ptr) throw () {
-        //cout << "delete(" << ptr << ") called" << endl;
-        if ( ptr ) geos_free(ptr);
-}
-
-void* operator new (std::size_t size) throw (std::bad_alloc) {
-  if ( void* ret = operator new (size, std::nothrow) ) return ret;
-  throw std::bad_alloc();
-}
-
-// ---------------------------------------------------------------- }
-
-
-
 namespace { // anonymous
 
 char* gstrdup_s(const char* str, const std::size_t size)
 {
-    char* out = static_cast<char*>(geos_alloc(size + 1));
+    char* out = static_cast<char*>(malloc(size + 1));
     if (0 != out)
     {
         // as no strlen call necessary, memcpy may be faster than strcpy
@@ -239,7 +194,7 @@
     GEOSContextHandleInternal_t *handle = 0;
     void *extHandle = 0;
 
-    extHandle = geos_alloc(sizeof(GEOSContextHandleInternal_t));
+    extHandle = malloc(sizeof(GEOSContextHandleInternal_t));
     if (0 != extHandle)
     {
         handle = static_cast<GEOSContextHandleInternal_t*>(extHandle);
@@ -292,7 +247,7 @@
 finishGEOS_r(GEOSContextHandle_t extHandle)
 {
     // Fix up freeing handle w.r.t. malloc above
-    geos_free(extHandle);
+    free(extHandle);
     extHandle = NULL;
 }
 
@@ -301,7 +256,7 @@
 { 
     assert(0 != extHandle);
 
-    geos_free(buffer); 
+    free(buffer); 
 } 
 
 //-----------------------------------------------------------
@@ -1286,7 +1241,7 @@
         const std::size_t len = wkbstring.length();
 
         unsigned char* result = 0;
-        result = static_cast<unsigned char*>(geos_alloc(len));
+        result = static_cast<unsigned char*>(malloc(len));
         if (0 != result)
         {
             std::memcpy(result, wkbstring.c_str(), len);
@@ -4778,7 +4733,7 @@
         const std::size_t len = wkbstring.length();
 
         unsigned char *result = NULL;
-        result = (unsigned char*) geos_alloc(len);
+        result = (unsigned char*) malloc(len);
         std::memcpy(result, wkbstring.c_str(), len);
         *size = len;
         return result;
@@ -4822,7 +4777,7 @@
         const std::size_t len = wkbstring.length();
 
         unsigned char *result = NULL;
-        result = (unsigned char*) geos_alloc(len);
+        result = (unsigned char*) malloc(len);
         std::memcpy(result, wkbstring.c_str(), len);
         *size = len;
         return result;

Deleted: trunk/include/geos/util/CustomAllocators.h
===================================================================
--- trunk/include/geos/util/CustomAllocators.h	2012-05-25 15:26:58 UTC (rev 3646)
+++ trunk/include/geos/util/CustomAllocators.h	2012-05-25 15:50:38 UTC (rev 3647)
@@ -1,35 +0,0 @@
-/**********************************************************************
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.osgeo.org
- *
- * Copyright (C) 2012 Sandro Santilli <strk at keybit.net>
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation. 
- * See the COPYING file for more information.
- *
- **********************************************************************/
-
-#ifndef GEOS_UTIL_CUSTOMALLOCATORS_H
-#define GEOS_UTIL_CUSTOMALLOCATORS_H
-
-#include <geos/export.h>
-#include <cstdlib> // size_t
-
-namespace geos {
-namespace util {
-namespace CustomAllocators {
-
-  typedef void* (*GEOSAllocator) (std::size_t size);
-  GEOSAllocator GEOS_DLL setAllocator(GEOSAllocator nf);
-
-  typedef void  (*GEOSDeallocator)(void *ptr);
-  GEOSDeallocator GEOS_DLL setDeallocator(GEOSDeallocator nf);
-
-}
-}
-}
-
-#endif // GEOS_UTIL_CUSTOMALLOCATORS_H

Modified: trunk/include/geos/util/Makefile.am
===================================================================
--- trunk/include/geos/util/Makefile.am	2012-05-25 15:26:58 UTC (rev 3646)
+++ trunk/include/geos/util/Makefile.am	2012-05-25 15:50:38 UTC (rev 3647)
@@ -10,7 +10,6 @@
 geos_HEADERS = \
     Assert.h \
     AssertionFailedException.h \
-    CustomAllocators.h \
     CoordinateArrayFilter.h \
     GeometricShapeFactory.h \
     GEOSException.h \

Deleted: trunk/src/util/CustomAllocators.cpp
===================================================================
--- trunk/src/util/CustomAllocators.cpp	2012-05-25 15:26:58 UTC (rev 3646)
+++ trunk/src/util/CustomAllocators.cpp	2012-05-25 15:50:38 UTC (rev 3647)
@@ -1,58 +0,0 @@
-/**********************************************************************
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.osgeo.org
- *
- * Copyright (C) 2012 Sandro Santilli <strk at keybit.net>
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation. 
- * See the COPYING file for more information.
- *
- **********************************************************************/
-
-#include <geos/util/CustomAllocators.h>
-
-#include <new>
-#include <iostream>
-#include <cstdlib>
-
-namespace geos {
-namespace util {
-namespace CustomAllocators {
-
-GEOSAllocator geos_alloc = std::malloc;
-GEOSDeallocator geos_free = std::free;
-
-GEOSAllocator
-setAllocator(GEOSAllocator nf)
-{
-  GEOSAllocator of = geos_alloc;
-  geos_alloc = nf;
-  return of;
-}
-
-GEOSDeallocator
-setDeallocator(GEOSDeallocator nf)
-{
-  GEOSDeallocator of = geos_free;
-  geos_free = nf;
-  return of;
-}
-
-}
-}
-}
-
-void*
-operator new (std::size_t size, const std::nothrow_t&) throw () {
-        //std::cout << "...new(" << size << ") called" << std::endl;
-        return geos::util::CustomAllocators::geos_alloc(size);
-}
-
-void operator delete (void *ptr) throw () {
-        //std::cout << "...delete(" << ptr << ") called" << std::endl;
-        if ( ptr ) geos::util::CustomAllocators::geos_free(ptr);
-}
-

Modified: trunk/src/util/Makefile.am
===================================================================
--- trunk/src/util/Makefile.am	2012-05-25 15:26:58 UTC (rev 3646)
+++ trunk/src/util/Makefile.am	2012-05-25 15:50:38 UTC (rev 3647)
@@ -9,7 +9,6 @@
 
 libutil_la_SOURCES = \
 	Assert.cpp \
-	CustomAllocators.cpp \
 	GeometricShapeFactory.cpp \
 	Interrupt.cpp \
 	math.cpp \

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2012-05-25 15:26:58 UTC (rev 3646)
+++ trunk/tests/unit/Makefile.am	2012-05-25 15:50:38 UTC (rev 3647)
@@ -102,7 +102,6 @@
 	simplify/TopologyPreservingSimplifierTest.cpp \
 	util/UniqueCoordinateArrayFilterTest.cpp \
 	capi/GEOSCoordSeqTest.cpp \
-	capi/GEOSCustomAllocatorTest.cpp \
 	capi/GEOSGeomFromWKBTest.cpp \
 	capi/GEOSGeomToWKTTest.cpp \
 	capi/GEOSContainsTest.cpp \

Deleted: trunk/tests/unit/capi/GEOSCustomAllocatorTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSCustomAllocatorTest.cpp	2012-05-25 15:26:58 UTC (rev 3646)
+++ trunk/tests/unit/capi/GEOSCustomAllocatorTest.cpp	2012-05-25 15:50:38 UTC (rev 3647)
@@ -1,140 +0,0 @@
-// 
-// Test Suite for C-API custom allocators
-
-#include <tut.hpp>
-// geos
-#include <geos_c.h>
-// std
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
-#include <memory>
-
-namespace tut
-{
-    //
-    // Test Group
-    //
-
-    // Common data used in test cases.
-    struct test_capicustomallocators_data
-    {
-        static int alloc_count;
-        static int dealloc_count;
-
-        static void notice(const char *fmt, ...)
-        {
-            std::fprintf( stdout, "NOTICE: ");
-
-            va_list ap;
-            va_start(ap, fmt);
-            std::vfprintf(stdout, fmt, ap);
-            va_end(ap);
-        
-            std::fprintf(stdout, "\n");
-        }
-
-        static void *t_alloc(size_t sz)
-        {
-            ++alloc_count;
-            void *ret = std::malloc(sz);
-            //notice("t_alloc(%d) returning %p", sz, ret);
-            return ret;
-        }
-
-        static void t_free(void *ptr)
-        {
-            //notice("t_free(%p)", ptr);
-            ++dealloc_count;
-            std::free(ptr);
-        }
-
-        test_capicustomallocators_data()
-        {
-            GEOS_setAllocator(t_alloc);
-            GEOS_setDeallocator(t_free);
-        }       
-
-        ~test_capicustomallocators_data()
-        {
-        }
-
-    };
-
-    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;
-
-    group test_capicustomallocators_group("capi::GEOSCustomAllocators");
-
-    //
-    // Test Cases
-    //
-
-    /// init and finish
-    template<>
-    template<>
-    void object::test<1>()
-    {
-        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(alloc_count > 0);
-        ensure_equals(alloc_count, dealloc_count);
-    }
-
-    /// WKTReader 
-    template<>
-    template<>
-    void object::test<2>()
-    {
-        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);
-
-        notice("%d allocs, %d deallocs after finishGEOS", alloc_count, dealloc_count);
-
-        ensure_equals(alloc_count, dealloc_count);
-    }
-
-
-} // namespace tut
-



More information about the geos-commits mailing list