Commit 9cb9e4a1 authored by Raúl Marín's avatar Raúl Marín

PostgreSQL 12 compatibility

Initial patch by Laurenz Albe
References #4313


git-svn-id: http://svn.osgeo.org/postgis/trunk@17223 b70326c6-7e19-0410-871a-916f4a2858ee
parent e0e17a15
Pipeline #45625384 (#3228) passed with stage
in 29 minutes and 54 seconds
......@@ -67,6 +67,7 @@ PostGIS 3.0.0
- #4296, Use `server_version_num` instead of parsing `version()` (Raúl Marín)
- #4272, Improve notice message when unable to compute stats (Raúl Marín)
- #4314, ST_ClipByBox2D: Do not throw when the geometry is invalid (Raúl Marín)
- #4313, #4307, PostgreSQL 12 compatibility (Laurenz Albe, Raúl Marín)
PostGIS 2.5.0
......
......@@ -52,7 +52,7 @@ typedef struct {
* info data.
*/
static MemoryContext
FIContext(FunctionCallInfoData* fcinfo)
FIContext(FunctionCallInfo fcinfo)
{
return fcinfo->flinfo->fn_mcxt;
}
......@@ -61,8 +61,8 @@ FIContext(FunctionCallInfoData* fcinfo)
* Get the generic collection off the statement, allocate a
* new one if we don't have one already.
*/
static GenericCacheCollection*
GetGenericCacheCollection(FunctionCallInfoData* fcinfo)
static GenericCacheCollection *
GetGenericCacheCollection(FunctionCallInfo fcinfo)
{
GenericCacheCollection* cache = fcinfo->flinfo->fn_extra;
......@@ -80,8 +80,8 @@ GetGenericCacheCollection(FunctionCallInfoData* fcinfo)
* Get the Proj4 entry from the generic cache if one exists.
* If it doesn't exist, make a new empty one and return it.
*/
PROJ4PortalCache*
GetPROJ4SRSCache(FunctionCallInfoData* fcinfo)
PROJ4PortalCache *
GetPROJ4SRSCache(FunctionCallInfo fcinfo)
{
GenericCacheCollection* generic_cache = GetGenericCacheCollection(fcinfo);
PROJ4PortalCache* cache = (PROJ4PortalCache*)(generic_cache->entry[PROJ_CACHE_ENTRY]);
......@@ -120,8 +120,11 @@ GetPROJ4SRSCache(FunctionCallInfoData* fcinfo)
* Returns a cache pointer if there is a cache hit and we have an
* index built and ready to use. Returns NULL otherwise.
*/
GeomCache*
GetGeomCache(FunctionCallInfoData* fcinfo, const GeomCacheMethods* cache_methods, const GSERIALIZED* g1, const GSERIALIZED* g2)
GeomCache *
GetGeomCache(FunctionCallInfo fcinfo,
const GeomCacheMethods *cache_methods,
const GSERIALIZED *g1,
const GSERIALIZED *g2)
{
GeomCache* cache;
int cache_hit = 0;
......
......@@ -103,7 +103,10 @@ typedef struct
/*
* Cache retrieval functions
*/
PROJ4PortalCache* GetPROJ4SRSCache(FunctionCallInfoData *fcinfo);
GeomCache* GetGeomCache(FunctionCallInfoData *fcinfo, const GeomCacheMethods* cache_methods, const GSERIALIZED* g1, const GSERIALIZED* g2);
PROJ4PortalCache *GetPROJ4SRSCache(FunctionCallInfo fcinfo);
GeomCache *GetGeomCache(FunctionCallInfo fcinfo,
const GeomCacheMethods *cache_methods,
const GSERIALIZED *g1,
const GSERIALIZED *g2);
#endif /* LWGEOM_CACHE_H_ */
......@@ -89,8 +89,8 @@ static GeomCacheMethods CircTreeCacheMethods =
CircTreeAllocator
};
static CircTreeGeomCache*
GetCircTreeGeomCache(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2)
static CircTreeGeomCache *
GetCircTreeGeomCache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2)
{
return (CircTreeGeomCache*)GetGeomCache(fcinfo, &CircTreeCacheMethods, g1, g2);
}
......@@ -151,9 +151,13 @@ CircTreePIP(const CIRC_NODE* tree1, const GSERIALIZED* g1, const POINT4D* in_poi
}
}
static int
geography_distance_cache_tolerance(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2, const SPHEROID* s, double tolerance, double* distance)
geography_distance_cache_tolerance(FunctionCallInfo fcinfo,
const GSERIALIZED *g1,
const GSERIALIZED *g2,
const SPHEROID *s,
double tolerance,
double *distance)
{
CircTreeGeomCache* tree_cache = NULL;
......@@ -242,15 +246,23 @@ geography_distance_cache_tolerance(FunctionCallInfoData* fcinfo, const GSERIALIZ
}
}
int
geography_distance_cache(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2, const SPHEROID* s, double* distance)
geography_distance_cache(FunctionCallInfo fcinfo,
const GSERIALIZED *g1,
const GSERIALIZED *g2,
const SPHEROID *s,
double *distance)
{
return geography_distance_cache_tolerance(fcinfo, g1, g2, s, FP_TOLERANCE, distance);
}
int
geography_dwithin_cache(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2, const SPHEROID* s, double tolerance, int* dwithin)
geography_dwithin_cache(FunctionCallInfo fcinfo,
const GSERIALIZED *g1,
const GSERIALIZED *g2,
const SPHEROID *s,
double tolerance,
int *dwithin)
{
double distance;
/* Ticket #2422, difference between sphere and spheroid distance can trip up the */
......
......@@ -26,6 +26,15 @@
#include "lwgeodetic_tree.h"
#include "lwgeom_cache.h"
int geography_dwithin_cache(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2, const SPHEROID* s, double tolerance, int* dwithin);
int geography_distance_cache(FunctionCallInfoData* fcinfo, const GSERIALIZED* g1, const GSERIALIZED* g2, const SPHEROID* s, double* distance);
int geography_dwithin_cache(FunctionCallInfo fcinfo,
const GSERIALIZED *g1,
const GSERIALIZED *g2,
const SPHEROID *s,
double tolerance,
int *dwithin);
int geography_distance_cache(FunctionCallInfo fcinfo,
const GSERIALIZED *g1,
const GSERIALIZED *g2,
const SPHEROID *s,
double *distance);
int geography_tree_distance(const GSERIALIZED* g1, const GSERIALIZED* g2, const SPHEROID* s, double tolerance, double* distance);
......@@ -90,7 +90,11 @@ dimensionality cases. (2D geometry) &&& (3D column), etc.
#include "executor/spi.h"
#include "fmgr.h"
#include "commands/vacuum.h"
#if PG_VERSION_NUM < 120000
#include "nodes/relation.h"
#else
#include "nodes/pathnodes.h"
#endif
#include "parser/parsetree.h"
#include "utils/array.h"
#include "utils/lsyscache.h"
......
......@@ -359,6 +359,7 @@ pgis_geometry_clusterwithin_finalfn(PG_FUNCTION_ARGS)
Datum
PGISDirectFunctionCall1(PGFunction func, Datum arg1)
{
#if POSTGIS_PGSQL_VERSION < 120
FunctionCallInfoData fcinfo;
Datum result;
......@@ -376,6 +377,23 @@ PGISDirectFunctionCall1(PGFunction func, Datum arg1)
return (Datum) 0;
return result;
#else
LOCAL_FCINFO(fcinfo, 1);
Datum result;
InitFunctionCallInfoData(*fcinfo, NULL, 1, InvalidOid, NULL, NULL);
fcinfo->args[0].value = arg1;
fcinfo->args[0].isnull = false;
result = (*func)(fcinfo);
/* Check for null result, returning a "NULL" Datum if indicated */
if (fcinfo->isnull)
return (Datum)0;
return result;
#endif /* POSTGIS_PGSQL_VERSION < 120 */
}
/**
......@@ -385,16 +403,11 @@ PGISDirectFunctionCall1(PGFunction func, Datum arg1)
Datum
PGISDirectFunctionCall2(PGFunction func, Datum arg1, Datum arg2)
{
#if POSTGIS_PGSQL_VERSION < 120
FunctionCallInfoData fcinfo;
Datum result;
#if POSTGIS_PGSQL_VERSION > 90
InitFunctionCallInfoData(fcinfo, NULL, 2, InvalidOid, NULL, NULL);
#else
InitFunctionCallInfoData(fcinfo, NULL, 2, NULL, NULL);
#endif
fcinfo.arg[0] = arg1;
fcinfo.arg[1] = arg2;
......@@ -408,4 +421,23 @@ PGISDirectFunctionCall2(PGFunction func, Datum arg1, Datum arg2)
return (Datum) 0;
return result;
#else
LOCAL_FCINFO(fcinfo, 2);
Datum result;
InitFunctionCallInfoData(*fcinfo, NULL, 2, InvalidOid, NULL, NULL);
fcinfo->args[0].value = arg1;
fcinfo->args[1].value = arg2;
fcinfo->args[0].isnull = false;
fcinfo->args[1].isnull = false;
result = (*func)(fcinfo);
/* Check for null result, returning a "NULL" Datum if indicated */
if (fcinfo->isnull)
return (Datum)0;
return result;
#endif /* POSTGIS_PGSQL_VERSION < 120 */
}
......@@ -458,8 +458,8 @@ static GeomCacheMethods PrepGeomCacheMethods =
* and freeing the GEOS PreparedGeometry structures
* we need for this particular caching strategy.
*/
PrepGeomCache*
GetPrepGeomCache(FunctionCallInfoData* fcinfo, GSERIALIZED* g1, GSERIALIZED* g2)
PrepGeomCache *
GetPrepGeomCache(FunctionCallInfo fcinfo, GSERIALIZED *g1, GSERIALIZED *g2)
{
return (PrepGeomCache*)GetGeomCache(fcinfo, &PrepGeomCacheMethods, g1, g2);
}
......
......@@ -70,6 +70,6 @@ typedef struct {
** If you are only caching one argument (e.g., in contains) supply 0 as the
** value for pg_geom2.
*/
PrepGeomCache *GetPrepGeomCache(FunctionCallInfoData *fcinfo, GSERIALIZED *pg_geom1, GSERIALIZED *pg_geom2);
PrepGeomCache *GetPrepGeomCache(FunctionCallInfo fcinfo, GSERIALIZED *pg_geom1, GSERIALIZED *pg_geom2);
#endif /* LWGEOM_GEOS_PREPARED_H_ */
......@@ -106,7 +106,7 @@ static GeomCacheMethods RectTreeCacheMethods =
};
static RectTreeGeomCache *
GetRectTreeGeomCache(FunctionCallInfoData *fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2)
GetRectTreeGeomCache(FunctionCallInfo fcinfo, const GSERIALIZED *g1, const GSERIALIZED *g2)
{
return (RectTreeGeomCache*)GetGeomCache(fcinfo, &RectTreeCacheMethods, g1, g2);
}
......
......@@ -428,8 +428,8 @@ static GeomCacheMethods RTreeCacheMethods =
RTreeAllocator
};
RTREE_POLY_CACHE*
GetRtreeCache(FunctionCallInfoData* fcinfo, GSERIALIZED* g1)
RTREE_POLY_CACHE *
GetRtreeCache(FunctionCallInfo fcinfo, GSERIALIZED *g1)
{
RTreeGeomCache* cache = (RTreeGeomCache*)GetGeomCache(fcinfo, &RTreeCacheMethods, g1, NULL);
RTREE_POLY_CACHE* index = NULL;
......
......@@ -80,7 +80,6 @@ LWMLINE *RTreeFindLineSegments(RTREE_NODE *root, double value);
* a pre-built index structure (RTREE_POLY_CACHE) if one exists. Otherwise
* builds a new one and returns that.
*/
RTREE_POLY_CACHE* GetRtreeCache(FunctionCallInfoData* fcinfo, GSERIALIZED* g1);
RTREE_POLY_CACHE *GetRtreeCache(FunctionCallInfo fcinfo, GSERIALIZED *g1);
#endif /* !defined _LWGEOM_RTREE_H */
This diff is collapsed.
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