[postgis-tickets] r16576 - Backport PG 11 compatibility

Raul raul at rmr.ninja
Fri May 18 02:10:04 PDT 2018


Author: algunenano
Date: 2018-05-18 02:10:03 -0700 (Fri, 18 May 2018)
New Revision: 16576

Modified:
   branches/2.4/.gitignore
   branches/2.4/extensions/address_standardizer/std_pg_hash.c
   branches/2.4/libpgcommon/lwgeom_transform.c
   branches/2.4/postgis/Makefile.in
   branches/2.4/postgis/lwgeom_geos_prepared.c
   branches/2.4/raster/test/regress/check_gdal.sql
   branches/2.4/raster/test/regress/check_gdal_expected
Log:
Backport PG 11 compatibility

Closes #4090
Closes https://github.com/postgis/postgis/pull/242


Modified: branches/2.4/.gitignore
===================================================================
--- branches/2.4/.gitignore	2018-05-16 21:39:45 UTC (rev 16575)
+++ branches/2.4/.gitignore	2018-05-18 09:10:03 UTC (rev 16576)
@@ -167,3 +167,7 @@
 *.pdf
 .idea/*
 .syntastic_c_config
+
+# LLVM JIT
+*.bc
+*.ll

Modified: branches/2.4/extensions/address_standardizer/std_pg_hash.c
===================================================================
--- branches/2.4/extensions/address_standardizer/std_pg_hash.c	2018-05-16 21:39:45 UTC (rev 16575)
+++ branches/2.4/extensions/address_standardizer/std_pg_hash.c	2018-05-18 09:10:03 UTC (rev 16576)
@@ -91,22 +91,7 @@
 static StdHashEntry *GetStdHashEntry(MemoryContext mcxt);
 static void DeleteStdHashEntry(MemoryContext mcxt);
 
-/* Memory context cache function prototypes */
-static void StdCacheInit(MemoryContext context);
-static void StdCacheReset(MemoryContext context);
-static void StdCacheDelete(MemoryContext context);
-static bool StdCacheIsEmpty(MemoryContext context);
 
-#if POSTGIS_PGSQL_VERSION >= 96
-static void StdCacheStats(MemoryContext context, int level, bool print, MemoryContextCounters *totals);
-#else
-static void StdCacheStats(MemoryContext context, int level);
-#endif
-
-#ifdef MEMORY_CONTEXT_CHECKING
-static void StdCacheCheck(MemoryContext context);
-#endif
-
 static bool IsInStdPortalCache(StdPortalCache *STDCache,  char *lextab, char *gaztab, char *rultab);
 static STANDARDIZER *GetStdFromPortalCache(StdPortalCache *STDCache,  char *lextab, char *gaztab, char *rultab);
 static void AddToStdPortalCache(StdPortalCache *STDCache, char *lextab, char *gaztab, char *rultab);
@@ -124,41 +109,19 @@
 static int load_rules(RULES *rules, char *tabname);
 
 
-/* Memory context definition must match the current version of PostgreSQL */
-static MemoryContextMethods StdCacheContextMethods =
-{
-    NULL,
-    NULL,
-    NULL,
-    StdCacheInit,
-    StdCacheReset,
-    StdCacheDelete,
-    NULL,
-    StdCacheIsEmpty,
-    StdCacheStats
-#ifdef MEMORY_CONTEXT_CHECKING
-    , StdCacheCheck
-#endif
-};
 
 
-static void
-StdCacheInit(MemoryContext context)
-{
-    /* NOP - initialized when first used. */
-}
 
-
 static void
-StdCacheReset(MemoryContext context)
-{
-    // NOP - Seems to be a required function
-}
+#if POSTGIS_PGSQL_VERSION < 95
 
-
-static void
 StdCacheDelete(MemoryContext context)
 {
+#else
+StdCacheDelete(void *ptr)
+{
+	MemoryContext context = (MemoryContext)ptr;
+#endif
     StdHashEntry *she;
 
     DBG("Enter: StdCacheDelete");
@@ -177,7 +140,21 @@
     DeleteStdHashEntry(context);
 }
 
+#if POSTGIS_PGSQL_VERSION < 95
 
+static void
+StdCacheInit(MemoryContext context)
+{
+    /* NOP - initialized when first used. */
+}
+
+
+static void
+StdCacheReset(MemoryContext context)
+{
+    // NOP - Seems to be a required function
+}
+
 static bool
 StdCacheIsEmpty(MemoryContext context)
 {
@@ -185,24 +162,13 @@
     return FALSE;
 }
 
-
-#if POSTGIS_PGSQL_VERSION >= 96
 static void
-StdCacheStats(MemoryContext context, int level, bool print, MemoryContextCounters *totals)
-{
-    // another required function
-    fprintf(stderr, "%s: STANDARDIZER context\n", context->name);
-}
-#else
-static void
 StdCacheStats(MemoryContext context, int level)
 {
     // another required function
     fprintf(stderr, "%s: STANDARDIZER context\n", context->name);
 }
-#endif
 
-
 #ifdef MEMORY_CONTEXT_CHECKING
 static void
 StdCacheCheck(MemoryContext context)
@@ -211,7 +177,26 @@
 }
 #endif
 
+/* Memory context definition must match the current version of PostgreSQL */
+static MemoryContextMethods StdCacheContextMethods =
+{
+    NULL,
+    NULL,
+    NULL,
+    StdCacheInit,
+    StdCacheReset,
+    StdCacheDelete,
+    NULL,
+    StdCacheIsEmpty,
+    StdCacheStats
+#ifdef MEMORY_CONTEXT_CHECKING
+    , StdCacheCheck
+#endif
+};
 
+#endif /* POSTGIS_PGSQL_VERSION < 95 */
+
+
 uint32
 mcxt_ptr_hash_std(const void *key, Size keysize)
 {
@@ -397,11 +382,28 @@
 
     DBG("Adding item to STD cache ('%s', '%s', '%s') index %d", lextab, gaztab, rultab, STDCache->NextSlot);
 
+
+#if POSTGIS_PGSQL_VERSION < 95
     STDMemoryContext = MemoryContextCreate(T_AllocSetContext, 8192,
                                            &StdCacheContextMethods,
                                            STDCache->StdCacheContext,
                                            "PAGC STD Memory Context");
+#else
+	STDMemoryContext =  AllocSetContextCreate(STDCache->StdCacheContext,
+	                                          "PAGC STD 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(STDMemoryContext, sizeof(MemoryContextCallback));
+	callback->arg = (void*)(STDMemoryContext);
+	callback->func = StdCacheDelete;
+	MemoryContextRegisterResetCallback(STDMemoryContext, callback);
+#endif
+
+
+
     /* Create the backend hash if it doesn't already exist */
     DBG("Check if StdHash exists (%p)", StdHash);
     if (!StdHash)

Modified: branches/2.4/libpgcommon/lwgeom_transform.c
===================================================================
--- branches/2.4/libpgcommon/lwgeom_transform.c	2018-05-16 21:39:45 UTC (rev 16575)
+++ branches/2.4/libpgcommon/lwgeom_transform.c	2018-05-18 09:10:03 UTC (rev 16576)
@@ -98,7 +98,7 @@
 
 
 static void
-#if POSTGIS_PGSQL_VERSION < 110
+#if POSTGIS_PGSQL_VERSION < 96
 PROJ4SRSCacheDelete(MemoryContext context)
 {
 #else
@@ -112,7 +112,7 @@
 	projection = GetPJHashEntry(context);
 
 	if (!projection)
-		elog(ERROR, "%s: Trying to delete non-existant projection object with MemoryContext key (%p)", __func__, (void *)context);
+		elog(ERROR, "PROJ4SRSCacheDelete: Trying to delete non-existant projection object with MemoryContext key (%p)", (void *)context);
 
 	POSTGIS_DEBUGF(3, "deleting projection object (%p) with MemoryContext key (%p)", projection, context);
 	/* Free it */
@@ -122,7 +122,7 @@
 	DeletePJHashEntry(context);
 }
 
-#if POSTGIS_PGSQL_VERSION < 110
+#if POSTGIS_PGSQL_VERSION < 96
 
 static void
 PROJ4SRSCacheInit(MemoryContext context)
@@ -153,11 +153,7 @@
 }
 
 static void
-#if POSTGIS_PGSQL_VERSION >= 96
-PROJ4SRSCacheStats(MemoryContext context, int level, bool print, MemoryContextCounters *totals)
-#else
 PROJ4SRSCacheStats(MemoryContext context, int level)
-#endif
 {
 	/*
 	 * Simple stats display function - we must supply a function since this call is mandatory according to tgl
@@ -195,9 +191,8 @@
 #endif
 };
 
-#endif /* POSTGIS_PGSQL_VERSION < 110 */
+#endif /* POSTGIS_PGSQL_VERSION < 96 */
 
-
 /*
  * PROJ4 projPJ Hash Table functions
  */
@@ -564,7 +559,7 @@
 	 */
 	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
+#if POSTGIS_PGSQL_VERSION < 95
 	PJMemoryContext = MemoryContextCreate(T_AllocSetContext, 8192,
 	                                      &PROJ4SRSCacheContextMethods,
 	                                      PROJ4Cache->PROJ4SRSCacheContext,
@@ -583,7 +578,7 @@
 	MemoryContextRegisterResetCallback(PJMemoryContext, callback);
 #endif
 
-	/* Create the backend hash if it doesn't already exist */
+ 	/* Create the backend hash if it doesn't already exist */
 	if (!PJHash)
 		PJHash = CreatePJHash();
 
@@ -683,52 +678,7 @@
 	return (Proj4Cache)GetPROJ4SRSCache(fcinfo);
 }
 
-#if 0
-static PROJ4PortalCache *GetPROJ4SRSCache(FunctionCallInfo fcinfo)
-{
-	PROJ4PortalCache *PROJ4Cache = (GetGeomCache(fcinfo))->proj;
 
-	/*
-	 * If we have not already created PROJ4 cache for this portal
-	 * then create it
-	 */
-	if (fcinfo->flinfo->fn_extra == NULL)
-	{
-		MemoryContext old_context;
-
-		old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
-		PROJ4Cache = palloc(sizeof(PROJ4PortalCache));
-		MemoryContextSwitchTo(old_context);
-
-		if (PROJ4Cache)
-		{
-			int i;
-
-			POSTGIS_DEBUGF(3, "Allocating PROJ4Cache for portal with transform() MemoryContext %p", fcinfo->flinfo->fn_mcxt);
-			/* Put in any required defaults */
-			for (i = 0; i < PROJ4_CACHE_ITEMS; i++)
-			{
-				PROJ4Cache->PROJ4SRSCache[i].srid = SRID_UNKNOWN;
-				PROJ4Cache->PROJ4SRSCache[i].projection = NULL;
-				PROJ4Cache->PROJ4SRSCache[i].projection_mcxt = NULL;
-			}
-			PROJ4Cache->PROJ4SRSCacheCount = 0;
-			PROJ4Cache->PROJ4SRSCacheContext = fcinfo->flinfo->fn_mcxt;
-
-			/* Store the pointer in fcinfo->flinfo->fn_extra */
-			fcinfo->flinfo->fn_extra = PROJ4Cache;
-		}
-	}
-	else
-	{
-		/* Use the existing cache */
-		PROJ4Cache = fcinfo->flinfo->fn_extra;
-	}
-
-	return PROJ4Cache ;
-}
-#endif
-
 /*
 * Given a function call context, figure out what namespace the
 * function is being called from, and copy that into a global

Modified: branches/2.4/postgis/Makefile.in
===================================================================
--- branches/2.4/postgis/Makefile.in	2018-05-16 21:39:45 UTC (rev 16575)
+++ branches/2.4/postgis/Makefile.in	2018-05-18 09:10:03 UTC (rev 16576)
@@ -118,8 +118,7 @@
 # to an existing liblwgeom.so in the PostgreSQL $libdir supplied by an
 # older version of PostGIS, rather than with the static liblwgeom.a
 # supplied with newer versions of PostGIS
-override CFLAGS := -I../liblwgeom @CFLAGS@
-PG_CPPFLAGS += -I../libpgcommon @CPPFLAGS@ -fPIC
+PG_CPPFLAGS += -I../liblwgeom @CFLAGS@ -I../libpgcommon @CPPFLAGS@ -fPIC
 SHLIB_LINK_F = ../libpgcommon/libpgcommon.a ../liblwgeom/.libs/liblwgeom.a @SHLIB_LINK@
 
 # Add SFCGAL Flags if defined

Modified: branches/2.4/postgis/lwgeom_geos_prepared.c
===================================================================
--- branches/2.4/postgis/lwgeom_geos_prepared.c	2018-05-16 21:39:45 UTC (rev 16575)
+++ branches/2.4/postgis/lwgeom_geos_prepared.c	2018-05-18 09:10:03 UTC (rev 16576)
@@ -96,7 +96,7 @@
 
 
 static void
-#if POSTGIS_PGSQL_VERSION < 110
+#if POSTGIS_PGSQL_VERSION < 96
 PreparedCacheDelete(MemoryContext context)
 {
 #else
@@ -111,7 +111,7 @@
 	pghe = GetPrepGeomHashEntry(context);
 
 	if (!pghe)
-		elog(ERROR, "%s: Trying to delete non-existant hash entry object with MemoryContext key (%p)", __func__, (void *)context);
+		elog(ERROR, "PreparedCacheDelete: Trying to delete non-existant hash entry object with MemoryContext key (%p)", (void *)context);
 
 	POSTGIS_DEBUGF(3, "deleting geom object (%p) and prepared geom object (%p) with MemoryContext key (%p)", pghe->geom, pghe->prepared_geom, context);
 
@@ -125,8 +125,7 @@
 	DeletePrepGeomHashEntry(context);
 }
 
-
-#if POSTGIS_PGSQL_VERSION < 110
+#if POSTGIS_PGSQL_VERSION < 96
 static void
 PreparedCacheInit(MemoryContext context)
 {
@@ -167,7 +166,6 @@
 	 * (see postgis-devel archives July 2007)
 	   fprintf(stderr, "%s: Prepared context\n", context->name);
 	 */
-
 }
 
 #ifdef MEMORY_CONTEXT_CHECKING
@@ -199,7 +197,7 @@
 #endif
 };
 
-#endif /* POSTGIS_PGSQL_VERSION < 110 */
+#endif /* POSTGIS_PGSQL_VERSION < 96 */
 
 
 /* TODO: put this in common are for both transform and prepared
@@ -319,7 +317,7 @@
 	if ( ! prepcache->context_callback )
 	{
 		PrepGeomHashEntry pghe;
-#if POSTGIS_PGSQL_VERSION < 110
+#if POSTGIS_PGSQL_VERSION < 96
 		prepcache->context_callback = MemoryContextCreate(T_AllocSetContext, 8192,
 		                             &PreparedCacheContextMethods,
 		                             prepcache->context_statement,
@@ -338,6 +336,8 @@
 		callback->func = PreparedCacheDelete;
 		MemoryContextRegisterResetCallback(prepcache->context_callback, callback);
 #endif
+
+
 		pghe.context = prepcache->context_callback;
 		pghe.geom = 0;
 		pghe.prepared_geom = 0;

Modified: branches/2.4/raster/test/regress/check_gdal.sql
===================================================================
--- branches/2.4/raster/test/regress/check_gdal.sql	2018-05-16 21:39:45 UTC (rev 16575)
+++ branches/2.4/raster/test/regress/check_gdal.sql	2018-05-18 09:10:03 UTC (rev 16576)
@@ -5,13 +5,8 @@
 			THEN false
 		ELSE NULL
 	END;
-SET postgis.gdal_datapath = '';
-SELECT
-	CASE
-		WHEN strpos(postgis_gdal_version(), 'GDAL_DATA') <> 0
-			THEN NULL
-		ELSE TRUE
-	END;
+SET postgis.gdal_datapath = 'invalid_path';
+SHOW postgis.gdal_datapath;
 SET postgis.gdal_datapath = default;
 SELECT
 	CASE

Modified: branches/2.4/raster/test/regress/check_gdal_expected
===================================================================
--- branches/2.4/raster/test/regress/check_gdal_expected	2018-05-16 21:39:45 UTC (rev 16575)
+++ branches/2.4/raster/test/regress/check_gdal_expected	2018-05-18 09:10:03 UTC (rev 16576)
@@ -1,3 +1,4 @@
+invalid_path
 t
 DISABLE_ALL
 ENABLE_ALL



More information about the postgis-tickets mailing list