]> granicus.if.org Git - postgis/commitdiff
Check that ST_MapAlgebra strict callbacks get passed an user arg
authorSandro Santilli <strk@keybit.net>
Thu, 3 Jul 2014 12:32:40 +0000 (12:32 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 3 Jul 2014 12:32:40 +0000 (12:32 +0000)
Closes #2803
Includes a testcase

git-svn-id: http://svn.osgeo.org/postgis/trunk@12720 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rtpg_mapalgebra.c
raster/test/regress/rt_mapalgebra.sql
raster/test/regress/rt_mapalgebra_expected

index ff20754c07618758486ecc654aa5b55047ffd85c..539840303b83dd902ded8b3d6df20f8642b68871 100644 (file)
@@ -81,7 +81,6 @@ typedef struct {
        Oid ufc_noid;
        FmgrInfo ufl_info;
        FunctionCallInfoData ufc_info;
-       int ufc_nullcount;
 } rtpg_nmapalgebra_callback_arg;
 
 typedef struct rtpg_nmapalgebra_arg_t *rtpg_nmapalgebra_arg;
@@ -138,7 +137,6 @@ static rtpg_nmapalgebra_arg rtpg_nmapalgebra_arg_init() {
        arg->mask = NULL;
 
        arg->callback.ufc_noid = InvalidOid;
-       arg->callback.ufc_nullcount = 0;
 
        return arg;
 }
@@ -473,17 +471,6 @@ static int rtpg_nmapalgebra_callback(
        callback->ufc_info.arg[0] = PointerGetDatum(mdValues);
        callback->ufc_info.arg[1] = PointerGetDatum(mdPos);
 
-       /* function is strict and null parameter is passed */
-       /* http://archives.postgresql.org/pgsql-general/2011-11/msg00424.php */
-       if (callback->ufl_info.fn_strict && callback->ufc_nullcount) {
-               *nodata = 1;
-
-               pfree(mdValues);
-               pfree(mdPos);
-
-               return 1;
-       }
-
        /* call user callback function */
        datum = FunctionCallInvoke(&(callback->ufc_info));
        pfree(mdValues);
@@ -813,7 +800,11 @@ Datum RASTER_nMapAlgebra(PG_FUNCTION_ARGS)
                else {
                        arg->callback.ufc_info.arg[2] = (Datum) NULL;
                        arg->callback.ufc_info.argnull[2] = TRUE;
-                       arg->callback.ufc_nullcount++;
+      if ( arg->callback.ufl_info.fn_strict ) {
+             /* function is strict and null parameter is passed */
+             /* http://archives.postgresql.org/pgsql-general/2011-11/msg00424.php */
+                   elog(ERROR, "RASTER_nMapAlgebra: strict callback requires user argument");
+      }
                }
        }
        else {
index d0a8780570c10f0a515f8f02286a110d81c4bbb3..2e2a6564e4cae08f436ea326f6dfcfe87f8cdefa 100644 (file)
@@ -650,5 +650,15 @@ SELECT
        (ST_BandMetadata(rast, 1))
 FROM foo;
 
+-- Test that you can't pass a strict callback and no user argument
+-- Se http://trac.osgeo.org/postgis/ticket/2803
+CREATE FUNCTION strict_cb(float8[][][], int[][], text[])
+returns float8 AS $$ select 0::float8; $$ language 'sql' immutable strict;
+SELECT ST_MapAlgebra( t1.rast, 2,
+ 'strict_cb(float8[][][], int[][], text[])'::regprocedure)
+       FROM raster_nmapalgebra_in t1;
+DROP FUNCTION strict_cb(float8[][][],int[][],text[]);
+
 DROP FUNCTION IF EXISTS raster_nmapalgebra_test(double precision[], int[], text[]);
 DROP TABLE IF EXISTS raster_nmapalgebra_in;
+
index 81cc1f28afda0f0cfeb6b48104463980eeeae387..e271b485f367b03ef0b48badcf99bac6478c2863 100644 (file)
@@ -341,3 +341,8 @@ NOTICE:  value = {{{10}}}
 NOTICE:  pos = [0:1][1:2]={{2,2},{2,2}}
 NOTICE:  userargs = <NULL>
 30|(0,0,2,2,1,-1,0,0,0,1)|(8BUI,0,f,)
+NOTICE:  First argument (nband) of rastbandarg at index 0 is NULL. Assuming NULL raster
+NOTICE:  All input rasters are NULL. Returning NULL
+NOTICE:  All input rasters do not have bands at indicated indexes. Returning empty raster
+NOTICE:  All input rasters do not have bands at indicated indexes. Returning empty raster
+ERROR:  RASTER_nMapAlgebra: strict callback requires user argument