From: Sandro Santilli Date: Wed, 19 Dec 2012 18:01:19 +0000 (+0000) Subject: Move JSON input test where it belons (#2156) X-Git-Tag: 2.1.0beta2~281 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=701c3bc5eb96b48c60c112344f940da271fd9b66;p=postgis Move JSON input test where it belons (#2156) git-svn-id: http://svn.osgeo.org/postgis/trunk@10859 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/html/image_src/generator.c b/doc/html/image_src/generator.c index 2fd32f3c5..146288862 100644 --- a/doc/html/image_src/generator.c +++ b/doc/html/image_src/generator.c @@ -48,16 +48,6 @@ 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 9e2998164..84c7e3171 100644 --- a/liblwgeom/cunit/cu_tester.c +++ b/liblwgeom/cunit/cu_tester.c @@ -93,6 +93,9 @@ 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()) { @@ -209,7 +212,7 @@ int main(int argc, char *argv[]) * * CAUTION: Not stop execution on lwerror case !!! */ -static void +void cu_errorreporter(const char *fmt, va_list ap) { char *msg; @@ -232,17 +235,3 @@ 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 2f857fcc8..f5de811a7 100644 --- a/liblwgeom/cunit/cu_tester.h +++ b/liblwgeom/cunit/cu_tester.h @@ -9,6 +9,8 @@ * **********************************************************************/ +#include /* for va_list */ + #define PG_TEST(test_func) { #test_func, test_func } #define MAX_CUNIT_ERROR_LENGTH 512 @@ -18,3 +20,5 @@ 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 6053c0ffe..d5e126139 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -32,10 +32,9 @@ * 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 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. +* 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. */ /** @@ -177,25 +176,21 @@ 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; /** -* Supply the memory management and error handling functions you want your +* Install custom memory management and error handling functions you want your * application to use. * @ingroup system */ -extern void lwgeom_init_allocators(void); +extern void lwgeom_set_handlers(lwallocator allocator, + lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter, + lwreporter noticereporter); /** * Apply the default memory management (malloc() and free()) and error handlers. -* Called inside lwgeom_init_allocators() generally. * @ingroup system */ -extern void lwgeom_install_default_allocators(void); +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 549e095dc..f3d3dd8c5 100644 --- a/liblwgeom/lwutil.c +++ b/liblwgeom/lwutil.c @@ -87,7 +87,7 @@ lwerror(const char *fmt, ...) void * init_allocator(size_t size) { - lwgeom_init_allocators(); + lwgeom_install_default_allocators(); return lwalloc_var(size); } @@ -95,7 +95,7 @@ init_allocator(size_t size) void init_freeor(void *mem) { - lwgeom_init_allocators(); + lwgeom_install_default_allocators(); lwfree_var(mem); } @@ -103,7 +103,7 @@ init_freeor(void *mem) void * init_reallocator(void *mem, size_t size) { - lwgeom_init_allocators(); + lwgeom_install_default_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_init_allocators(); + lwgeom_install_default_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_init_allocators(); + lwgeom_install_default_allocators(); (*lwerror_var)(fmt, ap); } @@ -192,8 +192,8 @@ default_errorreporter(const char *fmt, va_list ap) /* - * This function should be called from lwgeom_init_allocators() by programs - * which wish to use the default allocators above + * This function set up default which wish to use the default memory managers + * and error handlers */ void lwgeom_install_default_allocators(void) @@ -205,6 +205,22 @@ 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 bb59080be..09c5a8e95 100644 --- a/libpgcommon/lwgeom_pg.c +++ b/libpgcommon/lwgeom_pg.c @@ -181,14 +181,10 @@ pg_notice(const char *fmt, va_list ap) } void -lwgeom_init_allocators(void) +pg_install_handlers(void) { - /* 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; + /* install PostgreSQL handlers */ + lwgeom_set_handlers(pg_alloc, pg_realloc, pg_free, pg_error, pg_notice); } /** diff --git a/libpgcommon/lwgeom_pg.h b/libpgcommon/lwgeom_pg.h index ab3d3ce09..3393c06e1 100644 --- a/libpgcommon/lwgeom_pg.h +++ b/libpgcommon/lwgeom_pg.h @@ -28,6 +28,9 @@ 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 0c76d37ea..d2cb0a3f8 100644 --- a/loader/shpcommon.c +++ b/loader/shpcommon.c @@ -14,14 +14,6 @@ #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 62ca4e335..f219bf828 100644 --- a/postgis/postgis_module.c +++ b/postgis/postgis_module.c @@ -92,6 +92,8 @@ _PG_init(void) ); #endif + /* install PostgreSQL handlers */ + pg_install_handlers(); } /* diff --git a/raster/loader/raster2pgsql.c b/raster/loader/raster2pgsql.c index e7f14ca48..a293fc3bc 100644 --- a/raster/loader/raster2pgsql.c +++ b/raster/loader/raster2pgsql.c @@ -31,11 +31,6 @@ #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 ff4e47722..fe98a1f5b 100644 --- a/raster/rt_pg/Makefile.in +++ b/raster/rt_pg/Makefile.in @@ -24,7 +24,9 @@ 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_pg.o +OBJS= \ + rt_module.o \ + 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 59dbc5001..6e0165260 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -60,11 +60,6 @@ #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 @@ -17270,6 +17265,14 @@ 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 3137513b6..f61b79807 100644 --- a/raster/rt_pg/rt_pg.h +++ b/raster/rt_pg/rt_pg.h @@ -99,4 +99,8 @@ 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 fab6447f9..5a8314e1d 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -8675,13 +8675,6 @@ 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 1a7865e52..409e7780e 100644 --- a/raster/test/core/testwkb.c +++ b/raster/test/core/testwkb.c @@ -803,13 +803,6 @@ 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 e77ad32af..68f57b5a9 100644 --- a/regress/in_geojson.sql +++ b/regress/in_geojson.sql @@ -10,3 +10,6 @@ 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 8e218c78a..a3f59d4b7 100644 --- a/regress/in_geojson_expected +++ b/regress/in_geojson_expected @@ -7,3 +7,4 @@ 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 6afba5fb9..6bb9ba979 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -802,7 +802,6 @@ 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 670ed1fe2..7bcf711c9 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -235,5 +235,4 @@ 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