From: Raúl Marín Rodríguez Date: Thu, 31 Jan 2019 15:51:02 +0000 (+0000) Subject: PostgreSQL 12 compatibility X-Git-Tag: 2.4.7~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4ee8b95d0197a1d630a446c2bd5adf332f9270a7;p=postgis PostgreSQL 12 compatibility Initial patch by Laurenz Albe Closes #4313 Closes https://github.com/postgis/postgis/pull/368/ git-svn-id: http://svn.osgeo.org/postgis/branches/2.4@17225 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 7ddb99f8b..f893c609a 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ PostGIS 2.4.7 - #4296, Use `server_version_num` instead of parsing `version()` (Raúl Marín) - #4298, Geodetic tolerance issue in 32-bit (Paul Ramsey) - #4283, Avoid final point duplicates for circle stroking (Paul Ramsey) + - #4313, #4307, PostgreSQL 12 compatibility (Laurenz Albe, Raúl Marín) PostGIS 2.4.6 diff --git a/libpgcommon/lwgeom_cache.c b/libpgcommon/lwgeom_cache.c index ea5099019..32ff40c99 100644 --- a/libpgcommon/lwgeom_cache.c +++ b/libpgcommon/lwgeom_cache.c @@ -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; diff --git a/libpgcommon/lwgeom_cache.h b/libpgcommon/lwgeom_cache.h index 91b0d99a8..909443e32 100644 --- a/libpgcommon/lwgeom_cache.h +++ b/libpgcommon/lwgeom_cache.h @@ -101,7 +101,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_ */ diff --git a/postgis/geography_measurement_trees.c b/postgis/geography_measurement_trees.c index 52e21f78f..ab2a6907d 100644 --- a/postgis/geography_measurement_trees.c +++ b/postgis/geography_measurement_trees.c @@ -94,8 +94,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); } @@ -156,9 +156,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; @@ -247,15 +251,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 */ diff --git a/postgis/geography_measurement_trees.h b/postgis/geography_measurement_trees.h index 2d8582617..fac792ed7 100644 --- a/postgis/geography_measurement_trees.h +++ b/postgis/geography_measurement_trees.h @@ -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); diff --git a/postgis/gserialized_estimate.c b/postgis/gserialized_estimate.c index 2efc1c298..046842165 100644 --- a/postgis/gserialized_estimate.c +++ b/postgis/gserialized_estimate.c @@ -63,7 +63,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" diff --git a/postgis/lwgeom_accum.c b/postgis/lwgeom_accum.c index 8ebba7e7a..ca51fded3 100644 --- a/postgis/lwgeom_accum.c +++ b/postgis/lwgeom_accum.c @@ -383,6 +383,7 @@ pgis_geometry_clusterwithin_finalfn(PG_FUNCTION_ARGS) Datum PGISDirectFunctionCall1(PGFunction func, Datum arg1) { +#if POSTGIS_PGSQL_VERSION < 120 FunctionCallInfoData fcinfo; Datum result; @@ -400,6 +401,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 */ } /** @@ -409,16 +427,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; @@ -432,4 +445,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 */ } diff --git a/postgis/lwgeom_geos_prepared.c b/postgis/lwgeom_geos_prepared.c index 921b1657b..b50a17b0f 100644 --- a/postgis/lwgeom_geos_prepared.c +++ b/postgis/lwgeom_geos_prepared.c @@ -462,8 +462,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); } diff --git a/postgis/lwgeom_geos_prepared.h b/postgis/lwgeom_geos_prepared.h index d59871c1c..d1d7ac56d 100644 --- a/postgis/lwgeom_geos_prepared.h +++ b/postgis/lwgeom_geos_prepared.h @@ -74,6 +74,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_ */ diff --git a/postgis/lwgeom_rtree.c b/postgis/lwgeom_rtree.c index 27169e934..82015ffb2 100644 --- a/postgis/lwgeom_rtree.c +++ b/postgis/lwgeom_rtree.c @@ -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; diff --git a/postgis/lwgeom_rtree.h b/postgis/lwgeom_rtree.h index e29fc481a..92d7150ca 100644 --- a/postgis/lwgeom_rtree.h +++ b/postgis/lwgeom_rtree.h @@ -86,7 +86,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 */ diff --git a/raster/rt_pg/rtpg_mapalgebra.c b/raster/rt_pg/rtpg_mapalgebra.c index e95bc6586..729215cfd 100644 --- a/raster/rt_pg/rtpg_mapalgebra.c +++ b/raster/rt_pg/rtpg_mapalgebra.c @@ -81,7 +81,16 @@ typedef struct { Oid ufc_noid; Oid ufc_rettype; FmgrInfo ufl_info; +#if POSTGIS_PGSQL_VERSION < 120 FunctionCallInfoData ufc_info; +#else + /* copied from LOCAL_FCINFO in fmgr.h */ + union { + FunctionCallInfoBaseData fcinfo; + char fcinfo_data[SizeForFunctionCallInfo(FUNC_MAX_ARGS)]; /* Could be optimized */ + } ufc_info_data; + FunctionCallInfo ufc_info; +#endif } rtpg_nmapalgebra_callback_arg; typedef struct rtpg_nmapalgebra_arg_t *rtpg_nmapalgebra_arg; @@ -137,6 +146,9 @@ static rtpg_nmapalgebra_arg rtpg_nmapalgebra_arg_init() { arg->cextent = NULL; arg->mask = NULL; +#if POSTGIS_PGSQL_VERSION >= 120 + arg->callback.ufc_info = &(arg->callback.ufc_info_data.fcinfo); +#endif arg->callback.ufc_noid = InvalidOid; arg->callback.ufc_rettype = InvalidOid; @@ -470,16 +482,30 @@ static int rtpg_nmapalgebra_callback( pfree(_pos); pfree(_null); +#if POSTGIS_PGSQL_VERSION < 120 callback->ufc_info.arg[0] = PointerGetDatum(mdValues); callback->ufc_info.arg[1] = PointerGetDatum(mdPos); +#else + callback->ufc_info->args[0].value = PointerGetDatum(mdValues); + callback->ufc_info->args[1].value = PointerGetDatum(mdPos); +#endif /* call user callback function */ +#if POSTGIS_PGSQL_VERSION < 120 datum = FunctionCallInvoke(&(callback->ufc_info)); +#else + datum = FunctionCallInvoke(callback->ufc_info); +#endif pfree(mdValues); pfree(mdPos); /* result is not null*/ +#if POSTGIS_PGSQL_VERSION < 120 if (!callback->ufc_info.isnull) { +#else + if (!callback->ufc_info->isnull) + { +#endif switch (callback->ufc_rettype) { case FLOAT8OID: *value = DatumGetFloat8(datum); @@ -836,25 +862,52 @@ Datum RASTER_nMapAlgebra(PG_FUNCTION_ARGS) elog(NOTICE, "Function provided is VOLATILE. Unless required and for best performance, function should be IMMUTABLE or STABLE"); /* prep function call data */ +#if POSTGIS_PGSQL_VERSION < 120 InitFunctionCallInfoData(arg->callback.ufc_info, &(arg->callback.ufl_info), arg->callback.ufl_info.fn_nargs, InvalidOid, NULL, NULL); memset(arg->callback.ufc_info.argnull, FALSE, sizeof(bool) * arg->callback.ufl_info.fn_nargs); +#else + InitFunctionCallInfoData(*(arg->callback.ufc_info), + &(arg->callback.ufl_info), + arg->callback.ufl_info.fn_nargs, + InvalidOid, + NULL, + NULL); + + arg->callback.ufc_info->args[0].isnull = FALSE; + arg->callback.ufc_info->args[1].isnull = FALSE; + arg->callback.ufc_info->args[2].isnull = FALSE; +#endif /* userargs (7) */ if (!PG_ARGISNULL(9)) +#if POSTGIS_PGSQL_VERSION < 120 arg->callback.ufc_info.arg[2] = PG_GETARG_DATUM(9); +#else + arg->callback.ufc_info->args[2].value = PG_GETARG_DATUM(9); +#endif else { if (arg->callback.ufl_info.fn_strict) { /* build and assign an empty TEXT array */ /* TODO: manually free the empty array? */ +#if POSTGIS_PGSQL_VERSION < 120 arg->callback.ufc_info.arg[2] = PointerGetDatum( construct_empty_array(TEXTOID) ); arg->callback.ufc_info.argnull[2] = FALSE; +#else + arg->callback.ufc_info->args[2].value = PointerGetDatum(construct_empty_array(TEXTOID)); + arg->callback.ufc_info->args[2].isnull = FALSE; +#endif } else { +#if POSTGIS_PGSQL_VERSION < 120 arg->callback.ufc_info.arg[2] = (Datum) NULL; arg->callback.ufc_info.argnull[2] = TRUE; +#else + arg->callback.ufc_info->args[2].value = (Datum)NULL; + arg->callback.ufc_info->args[2].isnull = TRUE; +#endif } } } @@ -873,7 +926,7 @@ Datum RASTER_nMapAlgebra(PG_FUNCTION_ARGS) case ET_SECOND: if (arg->numraster > 1) { i = 1; - break; + break; } default: i = 0; @@ -1466,9 +1519,9 @@ Datum RASTER_nMapAlgebraExpr(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - strncpy(sql, "SELECT (", strlen("SELECT (")); - strncpy(sql + strlen("SELECT ("), expr, strlen(expr)); - strncpy(sql + strlen("SELECT (") + strlen(expr), ")::double precision", strlen(")::double precision")); + memcpy(sql, "SELECT (", strlen("SELECT (")); + memcpy(sql + strlen("SELECT ("), expr, strlen(expr)); + memcpy(sql + strlen("SELECT (") + strlen(expr), ")::double precision", strlen(")::double precision")); sql[len] = '\0'; POSTGIS_RT_DEBUGF(3, "sql #%d: %s", exprpos[i], sql); @@ -5087,7 +5140,11 @@ Datum RASTER_mapAlgebraFct(PG_FUNCTION_ARGS) int ret = -1; Oid oid; FmgrInfo cbinfo; +#if POSTGIS_PGSQL_VERSION < 120 FunctionCallInfoData cbdata; +#else + LOCAL_FCINFO(cbdata, FUNC_MAX_ARGS); /* Could be optimized */ +#endif Datum tmpnewval; char * strFromText = NULL; int k = 0; @@ -5327,9 +5384,19 @@ Datum RASTER_mapAlgebraFct(PG_FUNCTION_ARGS) } /* prep function call data */ +#if POSTGIS_PGSQL_VERSION < 120 InitFunctionCallInfoData(cbdata, &cbinfo, 2, InvalidOid, NULL, NULL); - memset(cbdata.argnull, FALSE, sizeof(bool) * cbinfo.fn_nargs); + cbdata.argnull[0] = FALSE; + cbdata.argnull[1] = FALSE; + cbdata.argnull[2] = FALSE; +#else + InitFunctionCallInfoData(*cbdata, &cbinfo, 2, InvalidOid, NULL, NULL); + + cbdata->args[0].isnull = FALSE; + cbdata->args[1].isnull = FALSE; + cbdata->args[2].isnull = FALSE; +#endif /* check that the function isn't strict if the args are null. */ if (PG_ARGISNULL(4)) { @@ -5343,11 +5410,20 @@ Datum RASTER_mapAlgebraFct(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - cbdata.arg[k] = (Datum)NULL; - cbdata.argnull[k] = TRUE; +#if POSTGIS_PGSQL_VERSION < 120 + cbdata.arg[k] = (Datum)NULL; + cbdata.argnull[k] = TRUE; +#else + cbdata->args[k].value = (Datum)NULL; + cbdata->args[k].isnull = TRUE; +#endif } else { - cbdata.arg[k] = PG_GETARG_DATUM(4); +#if POSTGIS_PGSQL_VERSION < 120 + cbdata.arg[k] = PG_GETARG_DATUM(4); +#else + cbdata->args[k].value = PG_GETARG_DATUM(4); +#endif } /** @@ -5424,13 +5500,23 @@ Datum RASTER_mapAlgebraFct(PG_FUNCTION_ARGS) POSTGIS_RT_DEBUG(3, "RASTER_mapAlgebraFct: Strict callbacks cannot accept NULL arguments, skipping NODATA cell."); continue; } - cbdata.argnull[0] = TRUE; - cbdata.arg[0] = (Datum)NULL; - } +#if POSTGIS_PGSQL_VERSION < 120 + cbdata.argnull[0] = TRUE; + cbdata.arg[0] = (Datum)NULL; +#else + cbdata->args[0].isnull = TRUE; + cbdata->args[0].value = (Datum)NULL; +#endif + } else { - cbdata.argnull[0] = FALSE; - cbdata.arg[0] = Float8GetDatum(r); - } +#if POSTGIS_PGSQL_VERSION < 120 + cbdata.argnull[0] = FALSE; + cbdata.arg[0] = Float8GetDatum(r); +#else + cbdata->args[0].isnull = FALSE; + cbdata->args[0].value = Float8GetDatum(r); +#endif + } /* Add pixel positions if callback has proper # of args */ if (cbinfo.fn_nargs == 3) { @@ -5442,19 +5528,33 @@ Datum RASTER_mapAlgebraFct(PG_FUNCTION_ARGS) a = construct_array(d, 2, INT4OID, sizeof(int32), true, 'i'); - cbdata.argnull[1] = FALSE; - cbdata.arg[1] = PointerGetDatum(a); - } +#if POSTGIS_PGSQL_VERSION < 120 + cbdata.argnull[1] = FALSE; + cbdata.arg[1] = PointerGetDatum(a); +#else + cbdata->args[1].isnull = FALSE; + cbdata->args[1].value = PointerGetDatum(a); +#endif + } POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFct: (%dx%d), r = %f", x, y, r); - tmpnewval = FunctionCallInvoke(&cbdata); +#if POSTGIS_PGSQL_VERSION < 120 + tmpnewval = FunctionCallInvoke(&cbdata); if (cbdata.isnull) { newval = newnodatavalue; } - else { +#else + tmpnewval = FunctionCallInvoke(cbdata); + + if (cbdata->isnull) + { + newval = newnodatavalue; + } +#endif + else { newval = DatumGetFloat8(tmpnewval); } @@ -5509,7 +5609,11 @@ Datum RASTER_mapAlgebraFctNgb(PG_FUNCTION_ARGS) int ret = -1; Oid oid; FmgrInfo cbinfo; +#if POSTGIS_PGSQL_VERSION < 120 FunctionCallInfoData cbdata; +#else + LOCAL_FCINFO(cbdata, FUNC_MAX_ARGS); /* Could be optimized */ +#endif Datum tmpnewval; ArrayType * neighborDatum; char * strFromText = NULL; @@ -5756,12 +5860,15 @@ Datum RASTER_mapAlgebraFctNgb(PG_FUNCTION_ARGS) } /* prep function call data */ -#if POSTGIS_PGSQL_VERSION <= 90 - InitFunctionCallInfoData(cbdata, &cbinfo, 3, InvalidOid, NULL); -#else +#if POSTGIS_PGSQL_VERSION < 120 InitFunctionCallInfoData(cbdata, &cbinfo, 3, InvalidOid, NULL, NULL); -#endif memset(cbdata.argnull, FALSE, sizeof(bool) * 3); +#else + InitFunctionCallInfoData(*cbdata, &cbinfo, 3, InvalidOid, NULL, NULL); + cbdata->args[0].isnull = FALSE; + cbdata->args[1].isnull = FALSE; + cbdata->args[2].isnull = FALSE; +#endif /* check that the function isn't strict if the args are null. */ if (PG_ARGISNULL(7)) { @@ -5775,11 +5882,20 @@ Datum RASTER_mapAlgebraFctNgb(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - cbdata.arg[2] = (Datum)NULL; +#if POSTGIS_PGSQL_VERSION < 120 + cbdata.arg[2] = (Datum)NULL; cbdata.argnull[2] = TRUE; +#else + cbdata->args[2].value = (Datum)NULL; + cbdata->args[2].isnull = TRUE; +#endif } else { - cbdata.arg[2] = PG_GETARG_DATUM(7); +#if POSTGIS_PGSQL_VERSION < 120 + cbdata.arg[2] = PG_GETARG_DATUM(7); +#else + cbdata->args[2].value = PG_GETARG_DATUM(7); +#endif } /** @@ -5899,7 +6015,11 @@ Datum RASTER_mapAlgebraFctNgb(PG_FUNCTION_ARGS) memcpy((void *)VARDATA(txtCallbackParam), (void *)VARDATA(txtNodataMode), VARSIZE(txtNodataMode) - VARHDRSZ); /* pass the nodata mode into the user function */ +#if POSTGIS_PGSQL_VERSION < 120 cbdata.arg[1] = CStringGetDatum(txtCallbackParam); +#else + cbdata->args[1].value = CStringGetDatum(txtCallbackParam); +#endif strFromText = text_to_cstring(txtNodataMode); strFromText = rtpg_strtoupper(strFromText); @@ -6018,7 +6138,8 @@ Datum RASTER_mapAlgebraFctNgb(PG_FUNCTION_ARGS) neighborDatum = construct_md_array((void *)neighborData, neighborNulls, 2, neighborDims, neighborLbs, FLOAT8OID, typlen, typbyval, typalign); - /* Assign the neighbor matrix as the first argument to the user function */ +#if POSTGIS_PGSQL_VERSION < 120 + /* Assign the neighbor matrix as the first argument to the user function */ cbdata.arg[0] = PointerGetDatum(neighborDatum); /* Invoke the user function */ @@ -6028,7 +6149,20 @@ Datum RASTER_mapAlgebraFctNgb(PG_FUNCTION_ARGS) if (cbdata.isnull) { newval = newnodatavalue; } - else { +#else + /* Assign the neighbor matrix as the first argument to the user function */ + cbdata->args[0].value = PointerGetDatum(neighborDatum); + + /* Invoke the user function */ + tmpnewval = FunctionCallInvoke(cbdata); + + /* Get the return value of the user function */ + if (cbdata->isnull) + { + newval = newnodatavalue; + } +#endif + else { newval = DatumGetFloat8(tmpnewval); } @@ -6136,7 +6270,11 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) Oid ufc_noid = InvalidOid; FmgrInfo ufl_info; +#if POSTGIS_PGSQL_VERSION < 120 FunctionCallInfoData ufc_info; +#else + LOCAL_FCINFO(ufc_info, FUNC_MAX_ARGS); /* Could be optimized */ +#endif int ufc_nullcount = 0; int idx = 0; @@ -6372,6 +6510,7 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) switch (extenttype) { case ET_FIRST: i = 0; + /* fall through */ case ET_SECOND: if (i > 1) i = 1; @@ -6862,17 +7001,24 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) } /* prep function call data */ -#if POSTGIS_PGSQL_VERSION <= 90 - InitFunctionCallInfoData(ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL); -#else +#if POSTGIS_PGSQL_VERSION < 120 InitFunctionCallInfoData(ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL); -#endif memset(ufc_info.argnull, FALSE, sizeof(bool) * ufl_info.fn_nargs); +#else + InitFunctionCallInfoData( + *ufc_info, &ufl_info, ufl_info.fn_nargs, InvalidOid, NULL, NULL); + ufc_info->args[0].isnull = FALSE; + ufc_info->args[1].isnull = FALSE; + ufc_info->args[2].isnull = FALSE; + if (ufl_info.fn_nargs == 4) + ufc_info->args[3].isnull = FALSE; +#endif if (ufl_info.fn_nargs != 4) k = 2; else k = 3; +#if POSTGIS_PGSQL_VERSION < 120 if (!PG_ARGISNULL(7)) { ufc_info.arg[k] = PG_GETARG_DATUM(7); } @@ -6881,6 +7027,18 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) ufc_info.argnull[k] = TRUE; ufc_nullcount++; } +#else + if (!PG_ARGISNULL(7)) + { + ufc_info->args[k].value = PG_GETARG_DATUM(7); + } + else + { + ufc_info->args[k].value = (Datum)NULL; + ufc_info->args[k].isnull = TRUE; + ufc_nullcount++; + } +#endif } break; } @@ -7107,15 +7265,27 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) /* build fcnarg */ for (i = 0; i < set_count; i++) { +#if POSTGIS_PGSQL_VERSION < 120 ufc_info.arg[i] = Float8GetDatum(_pixel[i]); +#else + ufc_info->args[i].value = Float8GetDatum(_pixel[i]); +#endif if (_haspixel[i]) { +#if POSTGIS_PGSQL_VERSION < 120 ufc_info.argnull[i] = FALSE; +#else + ufc_info->args[i].isnull = FALSE; +#endif ufc_nullcount--; } else { +#if POSTGIS_PGSQL_VERSION < 120 ufc_info.argnull[i] = TRUE; - ufc_nullcount++; +#else + ufc_info->args[i].isnull = TRUE; +#endif + ufc_nullcount++; } } @@ -7140,10 +7310,16 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) } a = construct_array(d, 4, INT4OID, sizeof(int32), true, 'i'); +#if POSTGIS_PGSQL_VERSION < 120 ufc_info.arg[2] = PointerGetDatum(a); ufc_info.argnull[2] = FALSE; +#else + ufc_info->args[2].value = PointerGetDatum(a); + ufc_info->args[2].isnull = FALSE; +#endif } +#if POSTGIS_PGSQL_VERSION < 120 datum = FunctionCallInvoke(&ufc_info); /* result is not null*/ @@ -7151,6 +7327,16 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) haspixel = 1; pixel = DatumGetFloat8(datum); } +#else + datum = FunctionCallInvoke(ufc_info); + + /* result is not null*/ + if (!ufc_info->isnull) + { + haspixel = 1; + pixel = DatumGetFloat8(datum); + } +#endif } break; } @@ -7205,4 +7391,4 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) SET_VARSIZE(pgrtn, pgrtn->size); PG_RETURN_POINTER(pgrtn); -} +} \ No newline at end of file