Commit 014ba45b authored by Paul Ramsey's avatar Paul Ramsey

Backport support for Pg11 to 2.4 branch. Closes #3946


git-svn-id: http://svn.osgeo.org/postgis/branches/2.4@16320 b70326c6-7e19-0410-871a-916f4a2858ee
parent f32859be
Pipeline #16222209 passed with stage
in 16 minutes and 31 seconds
......@@ -144,6 +144,13 @@ char* text2cstring(const text *textptr);
#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);
......
......@@ -96,63 +96,25 @@ static void DeleteFromPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid);
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);
#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 =
{
NULL,
NULL,
NULL,
PROJ4SRSCacheInit,
PROJ4SRSCacheReset,
PROJ4SRSCacheDelete,
NULL,
PROJ4SRSCacheIsEmpty,
PROJ4SRSCacheStats
#ifdef MEMORY_CONTEXT_CHECKING
,PROJ4SRSCacheCheck
#endif
};
static void
PROJ4SRSCacheInit(MemoryContext context)
{
/*
* Do nothing as the cache is initialised when the transform()
* function is first called
*/
}
static void
#if POSTGIS_PGSQL_VERSION < 110
PROJ4SRSCacheDelete(MemoryContext context)
{
#else
PROJ4SRSCacheDelete(void *ptr)
{
MemoryContext context = (MemoryContext)ptr;
#endif
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,6 +122,17 @@ PROJ4SRSCacheDelete(MemoryContext context)
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 @@ PROJ4SRSCacheIsEmpty(MemoryContext context)
* Always return false since this call is mandatory according to tgl
* (see postgis-devel archives July 2007)
*/
return FALSE;
return false;
}
static void
......@@ -203,7 +176,26 @@ PROJ4SRSCacheCheck(MemoryContext context)
* 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 */
/*
......@@ -572,10 +564,24 @@ AddToPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid, int other_srid)
*/
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)
......
......@@ -94,57 +94,24 @@ static void AddPrepGeomHashEntry(PrepGeomHashEntry pghe);
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 =
{
NULL,
NULL,
NULL,
PreparedCacheInit,
PreparedCacheReset,
PreparedCacheDelete,
NULL,
PreparedCacheIsEmpty,
PreparedCacheStats
#ifdef MEMORY_CONTEXT_CHECKING
, PreparedCacheCheck
#endif
};
static void
PreparedCacheInit(MemoryContext context)
{
/*
* Do nothing as the cache is initialised when the transform()
* function is first called
*/
}
static void
#if POSTGIS_PGSQL_VERSION < 110
PreparedCacheDelete(MemoryContext context)
{
#else
PreparedCacheDelete(void *ptr)
{
MemoryContext context = (MemoryContext)ptr;
#endif
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,6 +125,17 @@ PreparedCacheDelete(MemoryContext context)
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 @@ PreparedCacheIsEmpty(MemoryContext context)
* Always return false since this call is mandatory according to tgl
* (see postgis-devel archives July 2007)
*/
return FALSE;
return false;
}
static void
......@@ -201,7 +179,28 @@ PreparedCacheCheck(MemoryContext context)
* 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
......@@ -320,10 +319,25 @@ PrepGeomCacheBuilder(const LWGEOM *lwgeom, GeomCache *cache)
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment