[postgis-tickets] r14705 - Expunge rt_init_allocators (#3429)
Paul Ramsey
pramsey at cleverelephant.ca
Fri Feb 26 03:37:39 PST 2016
Author: pramsey
Date: 2016-02-26 03:37:39 -0800 (Fri, 26 Feb 2016)
New Revision: 14705
Modified:
branches/2.1/raster/loader/raster2pgsql.c
branches/2.1/raster/rt_core/rt_api.c
branches/2.1/raster/rt_core/rt_api.h
branches/2.1/raster/rt_pg/rt_pg.c
branches/2.1/raster/test/cunit/cu_tester.c
Log:
Expunge rt_init_allocators (#3429)
Modified: branches/2.1/raster/loader/raster2pgsql.c
===================================================================
--- branches/2.1/raster/loader/raster2pgsql.c 2016-02-26 11:19:07 UTC (rev 14704)
+++ branches/2.1/raster/loader/raster2pgsql.c 2016-02-26 11:37:39 UTC (rev 14705)
@@ -61,7 +61,8 @@
va_end(ap);
}
-void rt_init_allocators(void) {
+static void
+rt_init_allocators(void) {
rt_set_handlers(
default_rt_allocator,
default_rt_reallocator,
@@ -2300,6 +2301,9 @@
textdomain (PACKAGE);
#endif
+ /* Set up memory allocators */
+ rt_init_allocators();
+
/* no args, show usage */
if (argc == 1) {
usage();
Modified: branches/2.1/raster/rt_core/rt_api.c
===================================================================
--- branches/2.1/raster/rt_core/rt_api.c 2016-02-26 11:19:07 UTC (rev 14704)
+++ branches/2.1/raster/rt_core/rt_api.c 2016-02-26 11:37:39 UTC (rev 14705)
@@ -731,14 +731,6 @@
/*- rt_context -------------------------------------------------------*/
-/* Functions definitions */
-void * init_rt_allocator(size_t size);
-void * init_rt_reallocator(void * mem, size_t size);
-void init_rt_deallocator(void * mem);
-void init_rt_errorreporter(const char * fmt, va_list ap);
-void init_rt_warnreporter(const char * fmt, va_list ap);
-void init_rt_inforeporter(const char * fmt, va_list ap);
-
/*
* Default allocators
*
@@ -819,18 +811,17 @@
/* Static variable, to be used for all rt_core functions */
static struct rt_context_t ctx_t = {
- .alloc = init_rt_allocator,
- .realloc = init_rt_reallocator,
- .dealloc = init_rt_deallocator,
- .err = init_rt_errorreporter,
- .warn = init_rt_warnreporter,
- .info = init_rt_inforeporter
+ .alloc = default_rt_allocator,
+ .realloc = default_rt_reallocator,
+ .dealloc = default_rt_deallocator,
+ .err = default_rt_error_handler,
+ .warn = default_rt_warning_handler,
+ .info = default_rt_info_handler
};
/**
- * This function is normally called by rt_init_allocators when no special memory
- * management is needed. Useful in raster core testing and in the (future)
+ * Useful in raster core testing and in the (future)
* loader, when we need to use raster core functions but we don't have
* PostgreSQL backend behind. We must take care of memory by ourselves in those
* situations
@@ -848,7 +839,7 @@
/**
- * This function is called by rt_init_allocators when the PostgreSQL backend is
+ * This function is called when the PostgreSQL backend is
* taking care of the memory and we want to use palloc family
*/
void
@@ -868,67 +859,6 @@
/**
- * Initialisation allocators
- *
- * These are used the first time any of the allocators are called to enable
- * executables/libraries that link into raster to be able to set up their own
- * allocators. This is mainly useful for older PostgreSQL versions that don't
- * have functions that are called upon startup.
- **/
-void *
-init_rt_allocator(size_t size)
-{
- rt_init_allocators();
-
- return ctx_t.alloc(size);
-}
-
-void
-init_rt_deallocator(void *mem)
-{
- rt_init_allocators();
-
- ctx_t.dealloc(mem);
-}
-
-
-void *
-init_rt_reallocator(void *mem, size_t size)
-{
- rt_init_allocators();
-
- return ctx_t.realloc(mem, size);
-}
-
-void
-init_rt_inforeporter(const char *fmt, va_list ap)
-{
- rt_init_allocators();
-
- (*ctx_t.info)(fmt, ap);
-}
-
-void
-init_rt_warnreporter(const char *fmt, va_list ap)
-{
- rt_init_allocators();
-
- (*ctx_t.warn)(fmt, ap);
-}
-
-
-void
-init_rt_errorreporter(const char *fmt, va_list ap)
-{
- rt_init_allocators();
-
- (*ctx_t.err)(fmt, ap);
-
-}
-
-
-
-/**
* Raster core memory management functions.
*
* They use the functions defined by the caller.
Modified: branches/2.1/raster/rt_core/rt_api.h
===================================================================
--- branches/2.1/raster/rt_core/rt_api.h 2016-02-26 11:19:07 UTC (rev 14704)
+++ branches/2.1/raster/rt_core/rt_api.h 2016-02-26 11:37:39 UTC (rev 14705)
@@ -122,9 +122,8 @@
* of non-PostGIS applications using rt_core.
*
* Programs using this library should set up the default memory managers and error
- * handlers by implementing an rt_init_allocators() function, which can be as
- * a wrapper around the rt_install_default_allocators() function if you want
- * no special handling for memory management and error reporting.
+ * handlers by calling rt_set_handlers() or the rt_install_default_allocators()
+ * function if you want no special handling for memory management and error reporting.
*
**/
@@ -219,27 +218,12 @@
typedef void (*rt_deallocator)(void *mem);
typedef void (*rt_message_handler)(const char* string, va_list ap);
-/****************************************************************************
- * Functions that must be implemented for the raster core function's caller
- * (for example: rt_pg functions, test functions, future loader/exporter)
- ****************************************************************************/
-
-/**
- * Supply the memory management and error handling functions you want your
- * application to use
- */
-extern void rt_init_allocators(void);
-
-/*********************************************************************/
-
-
/*******************************************************************
* Functions that may be used by the raster core function's caller
* (for example: rt_pg functions, test functions, future loader/exporter)
*******************************************************************/
/**
* Apply the default memory management (malloc() and free()) and error handlers.
- * Called inside rt_init_allocators() generally.
*/
extern void rt_install_default_allocators(void);
Modified: branches/2.1/raster/rt_pg/rt_pg.c
===================================================================
--- branches/2.1/raster/rt_pg/rt_pg.c 2016-02-26 11:19:07 UTC (rev 14704)
+++ branches/2.1/raster/rt_pg/rt_pg.c 2016-02-26 11:37:39 UTC (rev 14705)
@@ -95,6 +95,78 @@
#define ENV_POSTGIS_GDAL_ENABLED_DRIVERS "POSTGIS_GDAL_ENABLED_DRIVERS"
#define ENV_POSTGIS_ENABLE_OUTDB_RASTERS "POSTGIS_ENABLE_OUTDB_RASTERS"
+
+/* ---------------------------------------------------------------- */
+/* Memory allocation / error reporting hooks */
+/* ---------------------------------------------------------------- */
+
+static void *
+rt_pg_alloc(size_t size)
+{
+ void * result;
+
+ POSTGIS_RT_DEBUGF(5, "rt_pgalloc(%ld) called", (long int) size);
+
+ result = palloc(size);
+
+ return result;
+}
+
+static void *
+rt_pg_realloc(void *mem, size_t size)
+{
+ void * result;
+
+ POSTGIS_RT_DEBUGF(5, "rt_pg_realloc(%ld) called", (long int) size);
+
+ if (mem)
+ result = repalloc(mem, size);
+
+ else
+ result = palloc(size);
+
+ return result;
+}
+
+static void
+rt_pg_free(void *ptr)
+{
+ POSTGIS_RT_DEBUG(5, "rt_pfree called");
+ pfree(ptr);
+}
+
+static void
+rt_pg_error(const char *fmt, va_list ap)
+{
+#define ERRMSG_MAXLEN 256
+
+ char errmsg[ERRMSG_MAXLEN+1];
+
+ vsnprintf (errmsg, ERRMSG_MAXLEN, fmt, ap);
+
+ errmsg[ERRMSG_MAXLEN]='\0';
+ ereport(ERROR, (errmsg_internal("%s", errmsg)));
+}
+
+static void
+rt_pg_notice(const char *fmt, va_list ap)
+{
+ char *msg;
+
+ /*
+ * This is a GNU extension.
+ * Dunno how to handle errors here.
+ */
+ if (!lw_vasprintf (&msg, fmt, ap))
+ {
+ va_end (ap);
+ return;
+ }
+ ereport(NOTICE, (errmsg_internal("%s", msg)));
+ free(msg);
+}
+
+
/* rtpg_assignHookGDALEnabledDrivers() should only be called by _PG_init */
static void
rtpg_assignHookGDALEnabledDrivers() {
@@ -261,6 +333,12 @@
void _PG_init(void) {
char *env_postgis_enable_outdb_rasters = NULL;
+ /* Install liblwgeom handlers */
+ pg_install_lwgeom_handlers();
+
+ /* Install rt_api handlers */
+ rt_set_handlers(rt_pg_alloc, rt_pg_realloc, rt_pg_free, rt_pg_error, rt_pg_notice, rt_pg_notice);
+
/*
* use POSTGIS_ENABLE_OUTDB_RASTERS to enable access to out-db rasters
*/
@@ -290,10 +368,6 @@
*/
rtpg_assignHookGDALEnabledDrivers();
- /* Install liblwgeom handlers */
- pg_install_lwgeom_handlers();
-
- /* TODO: Install raster callbacks (see rt_init_allocators) */
}
/***************************************************************
@@ -19411,83 +19485,3 @@
PG_RETURN_POINTER(pgrtn);
}
-/* ---------------------------------------------------------------- */
-/* Memory allocation / error reporting hooks */
-/* TODO: reuse the ones in libpgcommon ? */
-/* ---------------------------------------------------------------- */
-
-static void *
-rt_pg_alloc(size_t size)
-{
- void * result;
-
- POSTGIS_RT_DEBUGF(5, "rt_pgalloc(%ld) called", (long int) size);
-
- result = palloc(size);
-
- return result;
-}
-
-static void *
-rt_pg_realloc(void *mem, size_t size)
-{
- void * result;
-
- POSTGIS_RT_DEBUGF(5, "rt_pg_realloc(%ld) called", (long int) size);
-
- if (mem)
- result = repalloc(mem, size);
-
- else
- result = palloc(size);
-
- return result;
-}
-
-static void
-rt_pg_free(void *ptr)
-{
- POSTGIS_RT_DEBUG(5, "rt_pfree called");
- pfree(ptr);
-}
-
-static void
-rt_pg_error(const char *fmt, va_list ap)
-{
-#define ERRMSG_MAXLEN 256
-
- char errmsg[ERRMSG_MAXLEN+1];
-
- vsnprintf (errmsg, ERRMSG_MAXLEN, fmt, ap);
-
- errmsg[ERRMSG_MAXLEN]='\0';
- ereport(ERROR, (errmsg_internal("%s", errmsg)));
-}
-
-static void
-rt_pg_notice(const char *fmt, va_list ap)
-{
- char *msg;
-
- /*
- * This is a GNU extension.
- * Dunno how to handle errors here.
- */
- if (!lw_vasprintf (&msg, fmt, ap))
- {
- va_end (ap);
- return;
- }
- ereport(NOTICE, (errmsg_internal("%s", msg)));
- free(msg);
-}
-
-
-void
-rt_init_allocators(void)
-{
- /* raster callback - install raster handlers */
- rt_set_handlers(rt_pg_alloc, rt_pg_realloc, rt_pg_free, rt_pg_error,
- rt_pg_notice, rt_pg_notice);
-}
-
Modified: branches/2.1/raster/test/cunit/cu_tester.c
===================================================================
--- branches/2.1/raster/test/cunit/cu_tester.c 2016-02-26 11:19:07 UTC (rev 14704)
+++ branches/2.1/raster/test/cunit/cu_tester.c 2016-02-26 11:37:39 UTC (rev 14705)
@@ -84,6 +84,15 @@
/* install the custom error handler */
lwgeom_set_handlers(0, 0, 0, cu_error_reporter, 0);
+ rt_set_handlers(
+ default_rt_allocator,
+ default_rt_reallocator,
+ default_rt_deallocator,
+ cu_error_reporter,
+ default_rt_info_handler,
+ default_rt_warning_handler
+ );
+
/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
{
@@ -262,13 +271,3 @@
return band;
}
-void rt_init_allocators(void) {
- rt_set_handlers(
- default_rt_allocator,
- default_rt_reallocator,
- default_rt_deallocator,
- cu_error_reporter,
- default_rt_info_handler,
- default_rt_warning_handler
- );
-}
More information about the postgis-tickets
mailing list