From ec4425d17216956dcf8071ccca91f387dad8ab73 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 19 Dec 2012 18:06:17 +0000 Subject: [PATCH] Revert "Move JSON input test where it belons (#2156)" Accidentally committed an unrelated patch.. git-svn-id: http://svn.osgeo.org/postgis/trunk@10860 b70326c6-7e19-0410-871a-916f4a2858ee --- doc/html/image_src/generator.c | 10 ++++++++++ liblwgeom/cunit/cu_tester.c | 19 +++++++++++++++---- liblwgeom/cunit/cu_tester.h | 4 ---- liblwgeom/liblwgeom.h.in | 21 +++++++++++++-------- liblwgeom/lwutil.c | 30 +++++++----------------------- libpgcommon/lwgeom_pg.c | 10 +++++++--- libpgcommon/lwgeom_pg.h | 3 --- loader/shpcommon.c | 8 ++++++++ postgis/postgis_module.c | 2 -- raster/loader/raster2pgsql.c | 5 +++++ raster/rt_pg/Makefile.in | 4 +--- raster/rt_pg/rt_pg.c | 13 +++++-------- raster/rt_pg/rt_pg.h | 4 ---- raster/test/core/testapi.c | 7 +++++++ raster/test/core/testwkb.c | 7 +++++++ regress/in_geojson.sql | 3 --- regress/in_geojson_expected | 1 - regress/tickets.sql | 1 + regress/tickets_expected | 1 + 19 files changed, 87 insertions(+), 66 deletions(-) diff --git a/doc/html/image_src/generator.c b/doc/html/image_src/generator.c index 146288862..2fd32f3c5 100644 --- a/doc/html/image_src/generator.c +++ b/doc/html/image_src/generator.c @@ -48,6 +48,16 @@ char *imageSize = "200x200"; int getStyleName(char **styleName, char* line); +/** + * Set up liblwgeom to run in stand-alone mode using the + * usual system memory handling functions. + */ +void lwgeom_init_allocators(void) +{ + /* liblwgeom callback - install default handlers */ + lwgeom_install_default_allocators(); +} + /** * Writes the coordinates of a POINTARRAY to a char* where ordinates are * separated by a comma and coordinates by a space so that the coordinate diff --git a/liblwgeom/cunit/cu_tester.c b/liblwgeom/cunit/cu_tester.c index 84c7e3171..9e2998164 100644 --- a/liblwgeom/cunit/cu_tester.c +++ b/liblwgeom/cunit/cu_tester.c @@ -93,9 +93,6 @@ int main(int argc, char *argv[]) int num_run; int num_failed; - /* install the custom error handler */ - lwgeom_set_handlers(0, 0, 0, cu_errorreporter, 0); - /* initialize the CUnit test registry */ if (CUE_SUCCESS != CU_initialize_registry()) { @@ -212,7 +209,7 @@ int main(int argc, char *argv[]) * * CAUTION: Not stop execution on lwerror case !!! */ -void +static void cu_errorreporter(const char *fmt, va_list ap) { char *msg; @@ -235,3 +232,17 @@ cu_error_msg_reset() { memset(cu_error_msg, '\0', MAX_CUNIT_ERROR_LENGTH); } + +/* +** Set up liblwgeom to run in stand-alone mode using the +** usual system memory handling functions. +*/ +void lwgeom_init_allocators(void) +{ + lwalloc_var = default_allocator; + lwrealloc_var = default_reallocator; + lwfree_var = default_freeor; + lwnotice_var = default_noticereporter; + lwerror_var = cu_errorreporter; +} + diff --git a/liblwgeom/cunit/cu_tester.h b/liblwgeom/cunit/cu_tester.h index f5de811a7..2f857fcc8 100644 --- a/liblwgeom/cunit/cu_tester.h +++ b/liblwgeom/cunit/cu_tester.h @@ -9,8 +9,6 @@ * **********************************************************************/ -#include /* for va_list */ - #define PG_TEST(test_func) { #test_func, test_func } #define MAX_CUNIT_ERROR_LENGTH 512 @@ -20,5 +18,3 @@ char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]; /* Resets cu_error_msg back to blank. */ void cu_error_msg_reset(void); -void -cu_errorreporter(const char *fmt, va_list ap); diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index d5e126139..6053c0ffe 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -32,9 +32,10 @@ * units tests at cunit/cu_tester.c and the loader/dumper programs at * ../loader/shp2pgsql.c are examples of non-PostGIS applications using liblwgeom. * -* Programs using this library can install their custom memory managers and error -* handlers by calling the lwgeom_set_handlers() function, otherwise the default -* ones will be used. +* Programs using this library should set up the default memory managers and error +* handlers by implementing an lwgeom_init_allocators() function, which can be as +* a wrapper around the lwgeom_install_default_allocators() function if you want +* no special handling for memory management and error reporting. */ /** @@ -176,21 +177,25 @@ typedef void* (*lwallocator)(size_t size); typedef void* (*lwreallocator)(void *mem, size_t size); typedef void (*lwfreeor)(void* mem); typedef void (*lwreporter)(const char* fmt, va_list ap); +extern lwreallocator lwrealloc_var; +extern lwallocator lwalloc_var; +extern lwfreeor lwfree_var; +extern lwreporter lwerror_var; +extern lwreporter lwnotice_var; /** -* Install custom memory management and error handling functions you want your +* Supply the memory management and error handling functions you want your * application to use. * @ingroup system */ -extern void lwgeom_set_handlers(lwallocator allocator, - lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter, - lwreporter noticereporter); +extern void lwgeom_init_allocators(void); /** * Apply the default memory management (malloc() and free()) and error handlers. +* Called inside lwgeom_init_allocators() generally. * @ingroup system */ -void lwgeom_install_default_allocators(void); +extern void lwgeom_install_default_allocators(void); /** * Write a notice out to the notice handler. diff --git a/liblwgeom/lwutil.c b/liblwgeom/lwutil.c index f3d3dd8c5..549e095dc 100644 --- a/liblwgeom/lwutil.c +++ b/liblwgeom/lwutil.c @@ -87,7 +87,7 @@ lwerror(const char *fmt, ...) void * init_allocator(size_t size) { - lwgeom_install_default_allocators(); + lwgeom_init_allocators(); return lwalloc_var(size); } @@ -95,7 +95,7 @@ init_allocator(size_t size) void init_freeor(void *mem) { - lwgeom_install_default_allocators(); + lwgeom_init_allocators(); lwfree_var(mem); } @@ -103,7 +103,7 @@ init_freeor(void *mem) void * init_reallocator(void *mem, size_t size) { - lwgeom_install_default_allocators(); + lwgeom_init_allocators(); return lwrealloc_var(mem, size); } @@ -111,7 +111,7 @@ init_reallocator(void *mem, size_t size) void init_noticereporter(const char *fmt, va_list ap) { - lwgeom_install_default_allocators(); + lwgeom_init_allocators(); (*lwnotice_var)(fmt, ap); } @@ -119,7 +119,7 @@ init_noticereporter(const char *fmt, va_list ap) void init_errorreporter(const char *fmt, va_list ap) { - lwgeom_install_default_allocators(); + lwgeom_init_allocators(); (*lwerror_var)(fmt, ap); } @@ -192,8 +192,8 @@ default_errorreporter(const char *fmt, va_list ap) /* - * This function set up default which wish to use the default memory managers - * and error handlers + * This function should be called from lwgeom_init_allocators() by programs + * which wish to use the default allocators above */ void lwgeom_install_default_allocators(void) @@ -205,22 +205,6 @@ void lwgeom_install_default_allocators(void) lwnotice_var = default_noticereporter; } -/** - * This function is called by programs which want to set up custom handling - * for memory management and error reporting - */ -void -lwgeom_set_handlers(lwallocator allocator, lwreallocator reallocator, - lwfreeor freeor, lwreporter errorreporter, - lwreporter noticereporter) { - - lwalloc_var = allocator ? allocator : default_allocator; - lwrealloc_var = reallocator ? reallocator : default_reallocator; - lwfree_var = freeor ? freeor : default_freeor; - - lwerror_var = errorreporter ? errorreporter : default_errorreporter; - lwnotice_var = noticereporter ? noticereporter : default_noticereporter; -} const char* lwtype_name(uint8_t type) diff --git a/libpgcommon/lwgeom_pg.c b/libpgcommon/lwgeom_pg.c index 09c5a8e95..bb59080be 100644 --- a/libpgcommon/lwgeom_pg.c +++ b/libpgcommon/lwgeom_pg.c @@ -181,10 +181,14 @@ pg_notice(const char *fmt, va_list ap) } void -pg_install_handlers(void) +lwgeom_init_allocators(void) { - /* install PostgreSQL handlers */ - lwgeom_set_handlers(pg_alloc, pg_realloc, pg_free, pg_error, pg_notice); + /* liblwgeom callback - install PostgreSQL handlers */ + lwalloc_var = pg_alloc; + lwrealloc_var = pg_realloc; + lwfree_var = pg_free; + lwerror_var = pg_error; + lwnotice_var = pg_notice; } /** diff --git a/libpgcommon/lwgeom_pg.h b/libpgcommon/lwgeom_pg.h index 3393c06e1..ab3d3ce09 100644 --- a/libpgcommon/lwgeom_pg.h +++ b/libpgcommon/lwgeom_pg.h @@ -28,9 +28,6 @@ void pg_free(void *ptr); void pg_error(const char *msg, va_list vp); void pg_notice(const char *msg, va_list vp); -/* Install PostgreSQL memory management and error handling functions */ -void pg_install_handlers(void); - /* Debugging macros */ #if POSTGIS_DEBUG_LEVEL > 0 diff --git a/loader/shpcommon.c b/loader/shpcommon.c index d2cb0a3f8..0c76d37ea 100644 --- a/loader/shpcommon.c +++ b/loader/shpcommon.c @@ -14,6 +14,14 @@ #include #include "shpcommon.h" +#include "../liblwgeom/liblwgeom.h" /* for lwgeom_install_default_allocators */ + + +/* liblwgeom allocator callback - install the defaults (malloc/free/stdout/stderr) */ +void lwgeom_init_allocators() +{ + lwgeom_install_default_allocators(); +} /** diff --git a/postgis/postgis_module.c b/postgis/postgis_module.c index f219bf828..62ca4e335 100644 --- a/postgis/postgis_module.c +++ b/postgis/postgis_module.c @@ -92,8 +92,6 @@ _PG_init(void) ); #endif - /* install PostgreSQL handlers */ - pg_install_handlers(); } /* diff --git a/raster/loader/raster2pgsql.c b/raster/loader/raster2pgsql.c index a293fc3bc..e7f14ca48 100644 --- a/raster/loader/raster2pgsql.c +++ b/raster/loader/raster2pgsql.c @@ -31,6 +31,11 @@ #include "ogr_srs_api.h" #include +/* This is needed by liblwgeom */ +void lwgeom_init_allocators(void) { + lwgeom_install_default_allocators(); +} + static void loader_rt_error_handler(const char *fmt, va_list ap) { static const char *label = "ERROR: "; diff --git a/raster/rt_pg/Makefile.in b/raster/rt_pg/Makefile.in index fe98a1f5b..ff4e47722 100644 --- a/raster/rt_pg/Makefile.in +++ b/raster/rt_pg/Makefile.in @@ -24,9 +24,7 @@ SQLPP = @SQLPP@ SQL_OBJS=rtpostgis.sql.in rtpostgis_drop.sql.in rtpostgis_upgrade_cleanup.sql.in rtpostgis_legacy.sql.in # Objects to build using PGXS -OBJS= \ - rt_module.o \ - rt_pg.o +OBJS=rt_pg.o # Libraries to link into the module (proj, geos) # diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 6e0165260..59dbc5001 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -60,6 +60,11 @@ #define MAX_DBL_CHARLEN (3 + DBL_MANT_DIG - DBL_MIN_EXP) #define MAX_INT_CHARLEN 32 +/* + * This is required for builds against pgsql + */ +PG_MODULE_MAGIC; + /*************************************************************** * Internal functions must be prefixed with rtpg_. This is * keeping inline with the use of pgis_ for ./postgis C utility @@ -17265,14 +17270,6 @@ rt_pg_notice(const char *fmt, va_list ap) free(msg); } -void -rt_pg_install_handlers(void) -{ - /* install raster handlers */ - lwgeom_set_handlers(rt_pg_alloc, rt_pg_realloc, rt_pg_free, rt_pg_error, - rt_pg_notice); -} - void rt_init_allocators(void) diff --git a/raster/rt_pg/rt_pg.h b/raster/rt_pg/rt_pg.h index f61b79807..3137513b6 100644 --- a/raster/rt_pg/rt_pg.h +++ b/raster/rt_pg/rt_pg.h @@ -99,8 +99,4 @@ typedef struct rt_pgband_t { * and binary representation of it */ typedef struct rt_raster_serialized_t rt_pgraster; - -/* Install raster memory management and error handling functions */ -void rt_pg_install_handlers(void); - #endif /* RT_PG_H_INCLUDED */ diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index 5a8314e1d..fab6447f9 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -8675,6 +8675,13 @@ main() return EXIT_SUCCESS; } +/* This is needed by liblwgeom */ +void +lwgeom_init_allocators(void) +{ + lwgeom_install_default_allocators(); +} + void rt_init_allocators(void) { diff --git a/raster/test/core/testwkb.c b/raster/test/core/testwkb.c index 409e7780e..1a7865e52 100644 --- a/raster/test/core/testwkb.c +++ b/raster/test/core/testwkb.c @@ -803,6 +803,13 @@ main() return EXIT_SUCCESS; } +/* This is needed by liblwgeom */ +void +lwgeom_init_allocators(void) +{ + lwgeom_install_default_allocators(); +} + void rt_init_allocators(void) { rt_install_default_allocators(); diff --git a/regress/in_geojson.sql b/regress/in_geojson.sql index 68f57b5a9..e77ad32af 100644 --- a/regress/in_geojson.sql +++ b/regress/in_geojson.sql @@ -10,6 +10,3 @@ select 'geomfromgeojson_06',st_astext(st_geomfromgeojson(st_asgeojson('MULTIPOLY select '#1434: Next two errors'; select '#1434.1',ST_GeomFromGeoJSON('{ "type": "Point", "crashme": [100.0, 0.0] }'); select '#1434.2',ST_GeomFromGeoJSON('crashme');; - --- #2130 -SELECT '#2130', ST_NPoints(ST_GeomFromGeoJSON('{"type":"MultiPolygon","coordinates":[[[[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,32],[-117,32],[-117,32],[-117,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-117,32],[-117,32],[-117,32],[-117,32]],[[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,32],[-117,33]]]]}')); diff --git a/regress/in_geojson_expected b/regress/in_geojson_expected index a3f59d4b7..8e218c78a 100644 --- a/regress/in_geojson_expected +++ b/regress/in_geojson_expected @@ -7,4 +7,3 @@ geomfromgeojson_06|MULTIPOLYGON(((0 0,1 1,1 0,0 0))) #1434: Next two errors ERROR: Unable to find 'coordinates' in GeoJSON string ERROR: unexpected character (at offset 0) -#2130|8 diff --git a/regress/tickets.sql b/regress/tickets.sql index 6bb9ba979..6afba5fb9 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -802,6 +802,7 @@ FROM (SELECT 'POLYGON((1 1 1, 5 1 1,5 5 1, 1 5 1,1 1 1))'::geometry as a, 'LINES SELECT '#2108', ST_AsEWKT(ST_Line_Interpolate_Point('SRID=3395;LINESTRING M EMPTY'::geometry, 0.5)); SELECT '#2117', ST_AsEWKT(ST_PointOnSurface('SRID=3395;MULTIPOLYGON M EMPTY'::geometry)); +SELECT '#2130', ST_NPoints(ST_GeomFromGeoJSON('{"type":"MultiPolygon","coordinates":[[[[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,32],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,32],[-117,32],[-117,32],[-117,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-116,32],[-117,32],[-117,32],[-117,32],[-117,32]],[[-117,33],[-117,33],[-117,33],[-117,33],[-117,33],[-117,32],[-117,33]]]]}')); SELECT '#2145', round(ST_Length(St_Segmentize(ST_GeographyFromText('LINESTRING(-89.3000030518 28.2000007629,-89.1999969482 89.1999969482,-89.1999969482 89.1999969482)'), 10000))::numeric,0); diff --git a/regress/tickets_expected b/regress/tickets_expected index 7bcf711c9..670ed1fe2 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -235,4 +235,5 @@ ERROR: invalid GML representation #2112b|1|LINESTRING(1 1 1,1 0 1) #2108|SRID=3395;POINTM EMPTY #2117|SRID=3395;POINTM EMPTY +#2130|8 #2145|6792004 -- 2.40.0