]> granicus.if.org Git - postgis/commitdiff
Move JSON input test where it belons (#2156)
authorSandro Santilli <strk@keybit.net>
Wed, 19 Dec 2012 18:01:19 +0000 (18:01 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 19 Dec 2012 18:01:19 +0000 (18:01 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10859 b70326c6-7e19-0410-871a-916f4a2858ee

19 files changed:
doc/html/image_src/generator.c
liblwgeom/cunit/cu_tester.c
liblwgeom/cunit/cu_tester.h
liblwgeom/liblwgeom.h.in
liblwgeom/lwutil.c
libpgcommon/lwgeom_pg.c
libpgcommon/lwgeom_pg.h
loader/shpcommon.c
postgis/postgis_module.c
raster/loader/raster2pgsql.c
raster/rt_pg/Makefile.in
raster/rt_pg/rt_pg.c
raster/rt_pg/rt_pg.h
raster/test/core/testapi.c
raster/test/core/testwkb.c
regress/in_geojson.sql
regress/in_geojson_expected
regress/tickets.sql
regress/tickets_expected

index 2fd32f3c583e0aee33693d3065572f8475f2166c..14628886221889ea2948a82856a1e3fdc90feaf9 100644 (file)
@@ -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
index 9e2998164652778e988a2896fad0ca4a0aa048e2..84c7e3171ff75bcdbb209e565c3e9bba3a3abf69 100644 (file)
@@ -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;
-}
-
index 2f857fcc8dc68701bb59df2b4ddf9517402c52b3..f5de811a74fd2f1a26c321c65f9e06e46fa1d9d7 100644 (file)
@@ -9,6 +9,8 @@
  *
  **********************************************************************/
 
+#include <stdarg.h> /* 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);
index 6053c0ffe18efeed3bb24b441082f1be9a28991b..d5e1261395de48fc82400f0a7a09cec89c1e5410 100644 (file)
 * 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.
index 549e095dc78924eed0e6b733dd2d8dfc9b396c70..f3d3dd8c5f7db689c3ddf0b725749f22dd4ce0fb 100644 (file)
@@ -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)
index bb59080be12d7759965c019b85e3dfbebdfa476c..09c5a8e954bf63c9a9f4515299e3629baf3381f9 100644 (file)
@@ -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);
 }
 
 /**
index ab3d3ce09f4efac00c6c9983f79256eb76052763..3393c06e114c8a87bacd3b831a7c256fa0031cf0 100644 (file)
@@ -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
index 0c76d37ead26e4d5cd5ac802efde57a8ab7121b6..d2cb0a3f8b618acc03e676933a4b8062ba691c8c 100644 (file)
 
 #include <stdlib.h>
 #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();
-}
 
 
 /**
index 62ca4e33561f4e41d9514e5aa45def59d6994fcc..f219bf828babd9ff204e56262865aedb89bba7e8 100644 (file)
@@ -92,6 +92,8 @@ _PG_init(void)
    );
 #endif
 
+    /* install PostgreSQL handlers */
+    pg_install_handlers();
 }
 
 /*
index e7f14ca48db5269d3c44f5b27a732bf4d4b7a12a..a293fc3bce480acdcef52e68ebb732318956fb52 100644 (file)
 #include "ogr_srs_api.h"
 #include <assert.h>
 
-/* 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: ";
index ff4e47722b806960ebce6c27711f104ffc0836e2..fe98a1f5bb43964f8a4db612f46f2e74d578cf95 100644 (file)
@@ -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)
 #
index 59dbc50013910a4f3e5053a1c724ba319b6178f2..6e01652604dfe70958d2b735352657c2641c3a32 100644 (file)
 #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)
index 3137513b65d582baed712ae7efa89e2441e65270..f61b798070c70a330646a47ff1b9c2a50ec0da9a 100644 (file)
@@ -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 */
index fab6447f9a27e2167cf34d5163297850e9a00f81..5a8314e1d6fbdcfebf5f6a25fd7692328cad66e4 100644 (file)
@@ -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)
 {
index 1a7865e52a5c0748c8fa629ae6802f4ae1de4bf4..409e7780e7adcc34dddd1e989389353a06fa7e9f 100644 (file)
@@ -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();
index e77ad32af4b4dd31764703fda7111cfc8d0bb6e4..68f57b5a989dae33d0c28c268e5e3098d5deb53b 100644 (file)
@@ -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]]]]}'));
index 8e218c78a009617bd1bd30d1dd35a69b7b6903c0..a3f59d4b76db4504fbaefce29a421b0d1784100d 100644 (file)
@@ -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
index 6afba5fb9b0d58ee419635a42b31f3236ebd53a5..6bb9ba979fd74a96c528004645324dbf5f768e3c 100644 (file)
@@ -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);
index 670ed1fe2bd672078882c53dd2020e8bd70bbd85..7bcf711c908df68910bec3e74ee2d82ef8c1894e 100644 (file)
@@ -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