Index: doc/html/image_src/generator.c
===================================================================
--- doc/html/image_src/generator.c (revision 10851)
+++ doc/html/image_src/generator.c (working copy)
@@ -49,16 +49,6 @@
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
* pairs can be interpreted by ImageMagick's SVG draw command.
Index: loader/shpcommon.c
===================================================================
--- loader/shpcommon.c (revision 10851)
+++ loader/shpcommon.c (working copy)
@@ -14,16 +14,8 @@
#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();
-}
-
-
/**
* Escape strings that are to be used as part of a PostgreSQL connection string. If no
* characters require escaping, simply return the input pointer. Otherwise return a
Index: liblwgeom/liblwgeom.h.in
===================================================================
--- liblwgeom/liblwgeom.h.in (revision 10851)
+++ liblwgeom/liblwgeom.h.in (working copy)
@@ -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* (*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: liblwgeom/cunit/cu_tester.c
===================================================================
--- liblwgeom/cunit/cu_tester.c (revision 10851)
+++ liblwgeom/cunit/cu_tester.c (working copy)
@@ -93,6 +93,9 @@
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 @@
*
* CAUTION: Not stop execution on lwerror case !!!
*/
-static void
+void
cu_errorreporter(const char *fmt, va_list ap)
{
char *msg;
@@ -232,17 +235,3 @@
{
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: liblwgeom/cunit/cu_tester.h
===================================================================
--- liblwgeom/cunit/cu_tester.h (revision 10851)
+++ liblwgeom/cunit/cu_tester.h (working copy)
@@ -18,3 +18,5 @@
/* Resets cu_error_msg back to blank. */
void cu_error_msg_reset(void);
+void
+cu_errorreporter(const char *fmt, va_list ap);
Index: liblwgeom/lwutil.c
===================================================================
--- liblwgeom/lwutil.c (revision 10851)
+++ liblwgeom/lwutil.c (working copy)
@@ -87,7 +87,7 @@
void *
init_allocator(size_t size)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
return lwalloc_var(size);
}
@@ -95,7 +95,7 @@
void
init_freeor(void *mem)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
lwfree_var(mem);
}
@@ -103,7 +103,7 @@
void *
init_reallocator(void *mem, size_t size)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
return lwrealloc_var(mem, size);
}
@@ -111,7 +111,7 @@
void
init_noticereporter(const char *fmt, va_list ap)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
(*lwnotice_var)(fmt, ap);
}
@@ -119,7 +119,7 @@
void
init_errorreporter(const char *fmt, va_list ap)
{
- lwgeom_init_allocators();
+ lwgeom_install_default_allocators();
(*lwerror_var)(fmt, ap);
}
@@ -192,8 +192,8 @@
/*
- * 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,7 +205,23 @@
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: raster/rt_pg/rt_pg.h
===================================================================
--- raster/rt_pg/rt_pg.h (revision 10851)
+++ raster/rt_pg/rt_pg.h (working copy)
@@ -99,4 +99,8 @@
* 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: raster/rt_pg/rt_module.c
===================================================================
--- raster/rt_pg/rt_module.c (revision 0)
+++ raster/rt_pg/rt_module.c (working copy)
@@ -0,0 +1,35 @@
+/**********************************************************************
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ *
+ * Copyright (C) 2011 OpenGeo.org
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU General Public Licence. See the COPYING file.
+ *
+ **********************************************************************/
+
+#include "postgres.h"
+#include "fmgr.h"
+
+#include "../../postgis_config.h"
+
+#include "rt_pg.h"
+
+/*
+ * This is required for builds against pgsql
+ */
+PG_MODULE_MAGIC;
+
+/*
+ * Module load callback
+ */
+void _PG_init(void);
+void
+_PG_init(void)
+{
+ /* install raster handlers */
+ rt_pg_install_handlers();
+}
+
Index: raster/rt_pg/Makefile.in
===================================================================
--- raster/rt_pg/Makefile.in (revision 10851)
+++ raster/rt_pg/Makefile.in (working copy)
@@ -24,7 +24,9 @@
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: raster/rt_pg/rt_pg.c
===================================================================
--- raster/rt_pg/rt_pg.c (revision 10851)
+++ raster/rt_pg/rt_pg.c (working copy)
@@ -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,7 +17265,15 @@
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: raster/test/core/testapi.c
===================================================================
--- raster/test/core/testapi.c (revision 10851)
+++ raster/test/core/testapi.c (working copy)
@@ -8675,14 +8675,7 @@
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: raster/test/core/testwkb.c
===================================================================
--- raster/test/core/testwkb.c (revision 10851)
+++ raster/test/core/testwkb.c (working copy)
@@ -803,13 +803,6 @@
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: raster/loader/raster2pgsql.c
===================================================================
--- raster/loader/raster2pgsql.c (revision 10851)
+++ raster/loader/raster2pgsql.c (working copy)
@@ -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: ";
Index: postgis/postgis_module.c
===================================================================
--- postgis/postgis_module.c (revision 10851)
+++ postgis/postgis_module.c (working copy)
@@ -92,6 +92,8 @@
);
#endif
+ /* install PostgreSQL handlers */
+ pg_install_handlers();
}
/*
Index: libpgcommon/lwgeom_pg.c
===================================================================
--- libpgcommon/lwgeom_pg.c (revision 10851)
+++ libpgcommon/lwgeom_pg.c (working copy)
@@ -181,14 +181,10 @@
}
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: libpgcommon/lwgeom_pg.h
===================================================================
--- libpgcommon/lwgeom_pg.h (revision 10851)
+++ libpgcommon/lwgeom_pg.h (working copy)
@@ -28,7 +28,10 @@
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