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
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())
{
*
* CAUTION: Not stop execution on lwerror case !!!
*/
-static void
+void
cu_errorreporter(const char *fmt, va_list ap)
{
char *msg;
{
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;
-}
-
*
**********************************************************************/
+#include <stdarg.h> /* for va_list */
+
#define PG_TEST(test_func) { #test_func, test_func }
#define MAX_CUNIT_ERROR_LENGTH 512
/* Resets cu_error_msg back to blank. */
void cu_error_msg_reset(void);
+void
+cu_errorreporter(const char *fmt, va_list ap);
* 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.
*/
/**
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.
void *
init_allocator(size_t size)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
return lwalloc_var(size);
}
void
init_freeor(void *mem)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
lwfree_var(mem);
}
void *
init_reallocator(void *mem, size_t size)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
return lwrealloc_var(mem, size);
}
void
init_noticereporter(const char *fmt, va_list ap)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
(*lwnotice_var)(fmt, ap);
}
void
init_errorreporter(const char *fmt, va_list ap)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
(*lwerror_var)(fmt, 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)
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)
}
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);
}
/**
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
#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();
-}
/**
);
#endif
+ /* install PostgreSQL handlers */
+ pg_install_handlers();
}
/*
#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: ";
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)
#
#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
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)
* 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 */
return EXIT_SUCCESS;
}
-/* This is needed by liblwgeom */
-void
-lwgeom_init_allocators(void)
-{
- lwgeom_install_default_allocators();
-}
-
void rt_init_allocators(void)
{
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();
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]]]]}'));
#1434: Next two errors
ERROR: Unable to find 'coordinates' in GeoJSON string
ERROR: unexpected character (at offset 0)
+#2130|8
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);
#2112b|1|LINESTRING(1 1 1,1 0 1)
#2108|SRID=3395;POINTM EMPTY
#2117|SRID=3395;POINTM EMPTY
-#2130|8
#2145|6792004