]> granicus.if.org Git - postgis/commitdiff
PostgreSQL 12 compatibility
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Thu, 31 Jan 2019 15:51:02 +0000 (15:51 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Thu, 31 Jan 2019 15:51:02 +0000 (15:51 +0000)
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

12 files changed:
NEWS
libpgcommon/lwgeom_cache.c
libpgcommon/lwgeom_cache.h
postgis/geography_measurement_trees.c
postgis/geography_measurement_trees.h
postgis/gserialized_estimate.c
postgis/lwgeom_accum.c
postgis/lwgeom_geos_prepared.c
postgis/lwgeom_geos_prepared.h
postgis/lwgeom_rtree.c
postgis/lwgeom_rtree.h
raster/rt_pg/rtpg_mapalgebra.c

diff --git a/NEWS b/NEWS
index 7ddb99f8b1e80428cda1021d5d68a3dd23cf8d99..f893c609ac6ce9243a9e369845cbf81d5518f182 100644 (file)
--- 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
index ea509901946cb1e6da10b041465fd39780721f2b..32ff40c99b365b41baf4b230a087576de6ce204b 100644 (file)
@@ -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;
index 91b0d99a8abc0329d0004571b146d7a631f634b1..909443e3259129575c62f88a23c07d3fa6c06bfa 100644 (file)
@@ -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_ */
index 52e21f78fcd5f1dc14e73baff9da4f0f27c296c7..ab2a6907df6d9dd8052607cbbb206dd4230a753b 100644 (file)
@@ -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 */
index 2d858261732d64f68b5dbcfdb784ce0326c5c5eb..fac792ed79dff4c5ff8c629c577b94b64e8a283a 100644 (file)
 #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);
index 2efc1c298f44696b6cc1611332287efc3bd244c4..0468421656776bcb207310db04ab992f2990f58c 100644 (file)
@@ -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"
index 8ebba7e7a41f4b30a0eabb6cd8dda0da85e555f1..ca51fded3842d6f106abc92bc568874f6aad874d 100644 (file)
@@ -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 */
 }
index 921b1657b5c6c5296689735939f95c9b6b5289da..b50a17b0f3e8580a63064740d0296a327d084a74 100644 (file)
@@ -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);
 }
index d59871c1c82af6ae61371b42a7ec5555a9f1b881..d1d7ac56deaffa07c9cc643caf01bd66b6c6ebb9 100644 (file)
@@ -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_ */
index 27169e9345e1e2a53bb2b25b8e995bfa73b62a8c..82015ffb21dc4c28b53f5afbf43da84b135664e4 100644 (file)
@@ -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;
index e29fc481af455b1ca756824079107e5a9ecad34c..92d7150ca9a8edfd728bdea17d622cf8722a9794 100644 (file)
@@ -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 */
index e95bc6586203d45305d2c3e7dd7251df8e1c1b61..729215cfd7f089c98db0001b377e8c6ddb0d5967 100644 (file)
@@ -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