[postgis-tickets] r16320 - Backport support for Pg11 to 2.4 branch. Closes #3946
Paul Ramsey
pramsey at cleverelephant.ca
Tue Jan 16 06:46:56 PST 2018
Author: pramsey
Date: 2018-01-16 06:46:55 -0800 (Tue, 16 Jan 2018)
New Revision: 16320
Modified:
branches/2.4/libpgcommon/lwgeom_pg.h
branches/2.4/libpgcommon/lwgeom_transform.c
branches/2.4/postgis/lwgeom_geos_prepared.c
Log:
Backport support for Pg11 to 2.4 branch. Closes #3946
Modified: branches/2.4/libpgcommon/lwgeom_pg.h
===================================================================
--- branches/2.4/libpgcommon/lwgeom_pg.h 2018-01-16 14:21:44 UTC (rev 16319)
+++ branches/2.4/libpgcommon/lwgeom_pg.h 2018-01-16 14:46:55 UTC (rev 16320)
@@ -144,6 +144,13 @@
#define STATRELATT STATRELATTINH
#endif
+#if POSTGIS_PGSQL_VERSION >= 110
+#ifndef FALSE
+#define FALSE 0
+#define TRUE 1
+#endif
+#endif
+
/* PG-exposed */
Datum BOX2D_same(PG_FUNCTION_ARGS);
Datum BOX2D_overlap(PG_FUNCTION_ARGS);
Modified: branches/2.4/libpgcommon/lwgeom_transform.c
===================================================================
--- branches/2.4/libpgcommon/lwgeom_transform.c 2018-01-16 14:21:44 UTC (rev 16319)
+++ branches/2.4/libpgcommon/lwgeom_transform.c 2018-01-16 14:46:55 UTC (rev 16320)
@@ -96,63 +96,25 @@
static bool IsPROJ4LibPathSet = false;
void SetPROJ4LibPath(void);
-/* Memory context cache functions */
-static void PROJ4SRSCacheInit(MemoryContext context);
-static void PROJ4SRSCacheDelete(MemoryContext context);
-static void PROJ4SRSCacheReset(MemoryContext context);
-static bool PROJ4SRSCacheIsEmpty(MemoryContext context);
-#if POSTGIS_PGSQL_VERSION >= 96
-static void PROJ4SRSCacheStats(MemoryContext context, int level, bool print, MemoryContextCounters *totals);
+static void
+#if POSTGIS_PGSQL_VERSION < 110
+PROJ4SRSCacheDelete(MemoryContext context)
+{
#else
-static void PROJ4SRSCacheStats(MemoryContext context, int level);
-#endif
-
-#ifdef MEMORY_CONTEXT_CHECKING
-static void PROJ4SRSCacheCheck(MemoryContext context);
-#endif
-
-
-/* Memory context definition must match the current version of PostgreSQL */
-static MemoryContextMethods PROJ4SRSCacheContextMethods =
+PROJ4SRSCacheDelete(void *ptr)
{
- NULL,
- NULL,
- NULL,
- PROJ4SRSCacheInit,
- PROJ4SRSCacheReset,
- PROJ4SRSCacheDelete,
- NULL,
- PROJ4SRSCacheIsEmpty,
- PROJ4SRSCacheStats
-#ifdef MEMORY_CONTEXT_CHECKING
- ,PROJ4SRSCacheCheck
+ MemoryContext context = (MemoryContext)ptr;
#endif
-};
-
-
-static void
-PROJ4SRSCacheInit(MemoryContext context)
-{
- /*
- * Do nothing as the cache is initialised when the transform()
- * function is first called
- */
-}
-
-static void
-PROJ4SRSCacheDelete(MemoryContext context)
-{
projPJ projection;
/* Lookup the projPJ pointer in the global hash table so we can free it */
projection = GetPJHashEntry(context);
if (!projection)
- elog(ERROR, "PROJ4SRSCacheDelete: Trying to delete non-existant projection object with MemoryContext key (%p)", (void *)context);
+ elog(ERROR, "%s: Trying to delete non-existant projection object with MemoryContext key (%p)", __func__, (void *)context);
POSTGIS_DEBUGF(3, "deleting projection object (%p) with MemoryContext key (%p)", projection, context);
-
/* Free it */
pj_free(projection);
@@ -160,7 +122,18 @@
DeletePJHashEntry(context);
}
+#if POSTGIS_PGSQL_VERSION < 110
+
static void
+PROJ4SRSCacheInit(MemoryContext context)
+{
+ /*
+ * Do nothing as the cache is initialised when the transform()
+ * function is first called
+ */
+}
+
+static void
PROJ4SRSCacheReset(MemoryContext context)
{
/*
@@ -176,7 +149,7 @@
* Always return false since this call is mandatory according to tgl
* (see postgis-devel archives July 2007)
*/
- return FALSE;
+ return false;
}
static void
@@ -203,9 +176,28 @@
* with MEMORY_CONTEXT_CHECKING defined
*/
}
+#endif /* MEMORY_CONTEXT_CHECKING */
+
+/* Memory context definition must match the current version of PostgreSQL */
+static MemoryContextMethods PROJ4SRSCacheContextMethods =
+{
+ NULL,
+ NULL,
+ NULL,
+ PROJ4SRSCacheInit,
+ PROJ4SRSCacheReset,
+ PROJ4SRSCacheDelete,
+ NULL,
+ PROJ4SRSCacheIsEmpty,
+ PROJ4SRSCacheStats
+#ifdef MEMORY_CONTEXT_CHECKING
+ ,PROJ4SRSCacheCheck
#endif
+};
+#endif /* POSTGIS_PGSQL_VERSION < 110 */
+
/*
* PROJ4 projPJ Hash Table functions
*/
@@ -572,11 +564,25 @@
*/
POSTGIS_DEBUGF(3, "adding SRID %d with proj4text \"%s\" to query cache at index %d", srid, proj_str, PROJ4Cache->PROJ4SRSCacheCount);
+#if POSTGIS_PGSQL_VERSION < 110
PJMemoryContext = MemoryContextCreate(T_AllocSetContext, 8192,
&PROJ4SRSCacheContextMethods,
PROJ4Cache->PROJ4SRSCacheContext,
"PostGIS PROJ4 PJ Memory Context");
+#else
+ PJMemoryContext = AllocSetContextCreate(PROJ4Cache->PROJ4SRSCacheContext,
+ "PostGIS PROJ4 PJ Memory Context",
+ ALLOCSET_SMALL_SIZES);
+ /* PgSQL comments suggest allocating callback in the context */
+ /* being managed, so that the callback object gets cleaned along with */
+ /* the context */
+ MemoryContextCallback *callback = MemoryContextAlloc(PJMemoryContext, sizeof(MemoryContextCallback));
+ callback->arg = (void*)PJMemoryContext;
+ callback->func = PROJ4SRSCacheDelete;
+ MemoryContextRegisterResetCallback(PJMemoryContext, callback);
+#endif
+
/* Create the backend hash if it doesn't already exist */
if (!PJHash)
PJHash = CreatePJHash();
Modified: branches/2.4/postgis/lwgeom_geos_prepared.c
===================================================================
--- branches/2.4/postgis/lwgeom_geos_prepared.c 2018-01-16 14:21:44 UTC (rev 16319)
+++ branches/2.4/postgis/lwgeom_geos_prepared.c 2018-01-16 14:46:55 UTC (rev 16320)
@@ -94,57 +94,24 @@
static PrepGeomHashEntry *GetPrepGeomHashEntry(MemoryContext mcxt);
static void DeletePrepGeomHashEntry(MemoryContext mcxt);
-/* Memory context cache function prototypes */
-static void PreparedCacheInit(MemoryContext context);
-static void PreparedCacheReset(MemoryContext context);
-static void PreparedCacheDelete(MemoryContext context);
-static bool PreparedCacheIsEmpty(MemoryContext context);
-#if POSTGIS_PGSQL_VERSION >= 96
-static void PreparedCacheStats(MemoryContext context, int level, bool print, MemoryContextCounters *totals);
-#else
-static void PreparedCacheStats(MemoryContext context, int level);
-#endif
-#ifdef MEMORY_CONTEXT_CHECKING
-static void PreparedCacheCheck(MemoryContext context);
-#endif
-
-/* Memory context definition must match the current version of PostgreSQL */
-static MemoryContextMethods PreparedCacheContextMethods =
+static void
+#if POSTGIS_PGSQL_VERSION < 110
+PreparedCacheDelete(MemoryContext context)
{
- NULL,
- NULL,
- NULL,
- PreparedCacheInit,
- PreparedCacheReset,
- PreparedCacheDelete,
- NULL,
- PreparedCacheIsEmpty,
- PreparedCacheStats
-#ifdef MEMORY_CONTEXT_CHECKING
- , PreparedCacheCheck
+#else
+PreparedCacheDelete(void *ptr)
+{
+ MemoryContext context = (MemoryContext)ptr;
#endif
-};
-static void
-PreparedCacheInit(MemoryContext context)
-{
- /*
- * Do nothing as the cache is initialised when the transform()
- * function is first called
- */
-}
-
-static void
-PreparedCacheDelete(MemoryContext context)
-{
PrepGeomHashEntry* pghe;
/* Lookup the hash entry pointer in the global hash table so we can free it */
pghe = GetPrepGeomHashEntry(context);
if (!pghe)
- elog(ERROR, "PreparedCacheDelete: Trying to delete non-existant hash entry object with MemoryContext key (%p)", (void *)context);
+ elog(ERROR, "%s: Trying to delete non-existant hash entry object with MemoryContext key (%p)", __func__, (void *)context);
POSTGIS_DEBUGF(3, "deleting geom object (%p) and prepared geom object (%p) with MemoryContext key (%p)", pghe->geom, pghe->prepared_geom, context);
@@ -158,7 +125,18 @@
DeletePrepGeomHashEntry(context);
}
+
+#if POSTGIS_PGSQL_VERSION < 110
static void
+PreparedCacheInit(MemoryContext context)
+{
+ /*
+ * Do nothing as the cache is initialised when the transform()
+ * function is first called
+ */
+}
+
+static void
PreparedCacheReset(MemoryContext context)
{
/*
@@ -174,7 +152,7 @@
* Always return false since this call is mandatory according to tgl
* (see postgis-devel archives July 2007)
*/
- return FALSE;
+ return false;
}
static void
@@ -201,8 +179,29 @@
* with MEMORY_CONTEXT_CHECKING defined
*/
}
+#endif /* MEMORY_CONTEXT_CHECKING */
+
+
+/* Memory context definition must match the current version of PostgreSQL */
+static MemoryContextMethods PreparedCacheContextMethods =
+{
+ NULL,
+ NULL,
+ NULL,
+ PreparedCacheInit,
+ PreparedCacheReset,
+ PreparedCacheDelete,
+ NULL,
+ PreparedCacheIsEmpty,
+ PreparedCacheStats
+#ifdef MEMORY_CONTEXT_CHECKING
+ , PreparedCacheCheck
#endif
+};
+#endif /* POSTGIS_PGSQL_VERSION < 110 */
+
+
/* TODO: put this in common are for both transform and prepared
** mcxt_ptr_hash
** Build a key from a pointer and a size value.
@@ -320,10 +319,25 @@
if ( ! prepcache->context_callback )
{
PrepGeomHashEntry pghe;
+#if POSTGIS_PGSQL_VERSION < 110
prepcache->context_callback = MemoryContextCreate(T_AllocSetContext, 8192,
&PreparedCacheContextMethods,
prepcache->context_statement,
"PostGIS Prepared Geometry Context");
+
+#else
+ prepcache->context_callback = AllocSetContextCreate(prepcache->context_statement,
+ "PostGIS Prepared Geometry Context",
+ ALLOCSET_SMALL_SIZES);
+
+ /* PgSQL comments suggest allocating callback in the context */
+ /* being managed, so that the callback object gets cleaned along with */
+ /* the context */
+ MemoryContextCallback *callback = MemoryContextAlloc(prepcache->context_callback, sizeof(MemoryContextCallback));
+ callback->arg = (void*)(prepcache->context_callback);
+ callback->func = PreparedCacheDelete;
+ MemoryContextRegisterResetCallback(prepcache->context_callback, callback);
+#endif
pghe.context = prepcache->context_callback;
pghe.geom = 0;
pghe.prepared_geom = 0;
More information about the postgis-tickets
mailing list