[postgis-tickets] r16780 - Postgres 12 disallows variable length arrays in C, raster part
Darafei
komzpa at gmail.com
Thu Sep 13 10:25:51 PDT 2018
Author: komzpa
Date: 2018-09-13 10:25:51 -0700 (Thu, 13 Sep 2018)
New Revision: 16780
Modified:
trunk/raster/rt_pg/rtpg_band_properties.c
trunk/raster/rt_pg/rtpg_gdal.c
trunk/raster/rt_pg/rtpg_geometry.c
trunk/raster/rt_pg/rtpg_mapalgebra.c
trunk/raster/rt_pg/rtpg_pixel.c
trunk/raster/rt_pg/rtpg_raster_properties.c
trunk/raster/rt_pg/rtpg_statistics.c
Log:
Postgres 12 disallows variable length arrays in C, raster part
Patch by Laurenz Albe
Closes #4177
Modified: trunk/raster/rt_pg/rtpg_band_properties.c
===================================================================
--- trunk/raster/rt_pg/rtpg_band_properties.c 2018-09-13 17:25:17 UTC (rev 16779)
+++ trunk/raster/rt_pg/rtpg_band_properties.c 2018-09-13 17:25:51 UTC (rev 16780)
@@ -464,6 +464,8 @@
PG_RETURN_INT64(fileSize);
}
+#define VALUES_LENGTH 8
+
/**
* Get raster bands' meta data
*/
@@ -711,11 +713,10 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 8;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = UInt32GetDatum(bmd2[call_cntr].bandnum);
values[1] = CStringGetTextDatum(bmd2[call_cntr].pixeltype);
Modified: trunk/raster/rt_pg/rtpg_gdal.c
===================================================================
--- trunk/raster/rt_pg/rtpg_gdal.c 2018-09-13 17:25:17 UTC (rev 16779)
+++ trunk/raster/rt_pg/rtpg_gdal.c 2018-09-13 17:25:51 UTC (rev 16780)
@@ -330,6 +330,8 @@
PG_RETURN_POINTER(result);
}
+#define VALUES_LENGTH 6
+
/**
* Returns available GDAL drivers
*/
@@ -396,15 +398,14 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int32GetDatum(drv_set2[call_cntr].idx);
values[1] = CStringGetTextDatum(drv_set2[call_cntr].short_name);
Modified: trunk/raster/rt_pg/rtpg_geometry.c
===================================================================
--- trunk/raster/rt_pg/rtpg_geometry.c 2018-09-13 17:25:17 UTC (rev 16779)
+++ trunk/raster/rt_pg/rtpg_geometry.c 2018-09-13 17:25:51 UTC (rev 16780)
@@ -188,6 +188,8 @@
PG_RETURN_POINTER(gser);
}
+#define VALUES_LENGTH 2
+
PG_FUNCTION_INFO_V1(RASTER_dumpAsPolygons);
Datum RASTER_dumpAsPolygons(PG_FUNCTION_ARGS) {
FuncCallContext *funcctx;
@@ -309,9 +311,8 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
@@ -320,7 +321,7 @@
POSTGIS_RT_DEBUGF(3, "call number %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* convert LWGEOM to GSERIALIZED */
gser = gserialized_from_lwgeom(lwpoly_as_lwgeom(geomval2[call_cntr].geom), &gser_size);
@@ -344,6 +345,9 @@
}
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 4
+
/**
* Return the geographical shape of all pixels
*/
@@ -611,9 +615,8 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 4;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
@@ -622,7 +625,7 @@
POSTGIS_RT_DEBUGF(3, "call number %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* convert LWGEOM to GSERIALIZED */
gser = gserialized_from_lwgeom(pix2[call_cntr].geom, &gser_size);
Modified: trunk/raster/rt_pg/rtpg_mapalgebra.c
===================================================================
--- trunk/raster/rt_pg/rtpg_mapalgebra.c 2018-09-13 17:25:17 UTC (rev 16779)
+++ trunk/raster/rt_pg/rtpg_mapalgebra.c 2018-09-13 17:25:51 UTC (rev 16780)
@@ -6068,6 +6068,8 @@
PG_RETURN_POINTER(pgrtn);
}
+#define ARGKWCOUNT 8
+
/**
* Two raster MapAlgebra
*/
@@ -6115,11 +6117,10 @@
SPIPlanPtr spi_plan[3] = {NULL};
uint16_t spi_empty = 0;
Oid *argtype = NULL;
- const uint32_t argkwcount = 8;
uint8_t argpos[3][8] = {{0}};
char *argkw[] = {"[rast1.x]", "[rast1.y]", "[rast1.val]", "[rast1]", "[rast2.x]", "[rast2.y]", "[rast2.val]", "[rast2]"};
- Datum values[argkwcount];
- char nulls[argkwcount];
+ Datum values[ARGKWCOUNT];
+ char nulls[ARGKWCOUNT];
TupleDesc tupdesc;
SPITupleTable *tuptable = NULL;
HeapTuple tuple;
@@ -6639,7 +6640,7 @@
expr = text_to_cstring(PG_GETARG_TEXT_P(spi_exprpos[i]));
POSTGIS_RT_DEBUGF(3, "raw expr #%d: %s", i, expr);
- for (j = 0, k = 1; j < argkwcount; j++) {
+ for (j = 0, k = 1; j < ARGKWCOUNT; j++) {
/* attempt to replace keyword with placeholder */
len = 0;
tmp = rtpg_strreplace(expr, argkw[j], place, &len);
@@ -6704,7 +6705,7 @@
}
/* specify datatypes of parameters */
- for (j = 0, k = 0; j < argkwcount; j++) {
+ for (j = 0, k = 0; j < ARGKWCOUNT; j++) {
if (argpos[i][j] < 1) continue;
/* positions are INT4 */
@@ -7003,14 +7004,14 @@
POSTGIS_RT_DEBUGF(4, "Using prepared plan: %d", i);
/* reset values to (Datum) NULL */
- memset(values, (Datum) NULL, sizeof(Datum) * argkwcount);
+ memset(values, (Datum) NULL, sizeof(Datum) * ARGKWCOUNT);
/* reset nulls to FALSE */
- memset(nulls, FALSE, sizeof(char) * argkwcount);
+ memset(nulls, FALSE, sizeof(char) * ARGKWCOUNT);
/* expression has argument(s) */
if (spi_argcount[i]) {
/* set values and nulls */
- for (j = 0; j < argkwcount; j++) {
+ for (j = 0; j < ARGKWCOUNT; j++) {
idx = argpos[i][j];
if (idx < 1) continue;
idx--; /* 1-based becomes 0-based */
Modified: trunk/raster/rt_pg/rtpg_pixel.c
===================================================================
--- trunk/raster/rt_pg/rtpg_pixel.c 2018-09-13 17:25:17 UTC (rev 16779)
+++ trunk/raster/rt_pg/rtpg_pixel.c 2018-09-13 17:25:51 UTC (rev 16780)
@@ -197,6 +197,8 @@
pfree(arg);
}
+#define VALUES_LENGTH 2
+
PG_FUNCTION_INFO_V1(RASTER_dumpValues);
Datum RASTER_dumpValues(PG_FUNCTION_ARGS)
{
@@ -514,9 +516,8 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
ArrayType *mdValues = NULL;
@@ -527,7 +528,7 @@
POSTGIS_RT_DEBUGF(3, "call number %d", call_cntr);
POSTGIS_RT_DEBUGF(4, "dim = %d, %d", dim[0], dim[1]);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int32GetDatum(arg2->nbands[call_cntr] + 1);
@@ -1601,6 +1602,9 @@
PG_RETURN_POINTER(pgrtn);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 3
+
/**
* Get pixels of value
*/
@@ -1799,13 +1803,12 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 3;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* 0-based to 1-based */
pixels2[call_cntr].x += 1;
Modified: trunk/raster/rt_pg/rtpg_raster_properties.c
===================================================================
--- trunk/raster/rt_pg/rtpg_raster_properties.c 2018-09-13 17:25:17 UTC (rev 16779)
+++ trunk/raster/rt_pg/rtpg_raster_properties.c 2018-09-13 17:25:51 UTC (rev 16780)
@@ -429,6 +429,8 @@
PG_RETURN_FLOAT8(pheight);
}
+#define VALUES_LENGTH 6
+
/**
* Calculates the physically relevant parameters of the supplied raster's
* geotransform. Returns them as a set.
@@ -449,9 +451,8 @@
*/
TupleDesc result_tuple; /* for returning a composite */
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple heap_tuple ; /* instance of the tuple to return */
Datum result;
@@ -503,7 +504,7 @@
values[4] = Float8GetDatum(rt_raster_get_x_offset(raster));
values[5] = Float8GetDatum(rt_raster_get_y_offset(raster));
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* stick em on the heap */
heap_tuple = heap_form_tuple(result_tuple, values, nulls);
@@ -581,6 +582,9 @@
PG_RETURN_BOOL(hasnoband);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 10
+
/**
* Get raster's meta data
*/
@@ -602,9 +606,8 @@
uint32_t height;
TupleDesc tupdesc;
- int values_length = 10;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
@@ -672,7 +675,7 @@
values[8] = Int32GetDatum(srid);
values[9] = UInt32GetDatum(numBands);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* build a tuple */
tuple = heap_form_tuple(tupdesc, values, nulls);
@@ -683,6 +686,9 @@
PG_RETURN_DATUM(result);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 2
+
PG_FUNCTION_INFO_V1(RASTER_rasterToWorldCoord);
Datum RASTER_rasterToWorldCoord(PG_FUNCTION_ARGS)
{
@@ -694,9 +700,8 @@
double cw[2] = {0};
TupleDesc tupdesc;
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
@@ -767,7 +772,7 @@
values[0] = Float8GetDatum(cw[0]);
values[1] = Float8GetDatum(cw[1]);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* build a tuple */
tuple = heap_form_tuple(tupdesc, values, nulls);
@@ -790,9 +795,8 @@
bool skewed = false;
TupleDesc tupdesc;
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
@@ -868,7 +872,7 @@
values[0] = Int32GetDatum(cr[0]);
values[1] = Int32GetDatum(cr[1]);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
/* build a tuple */
tuple = heap_form_tuple(tupdesc, values, nulls);
Modified: trunk/raster/rt_pg/rtpg_statistics.c
===================================================================
--- trunk/raster/rt_pg/rtpg_statistics.c 2018-09-13 17:25:17 UTC (rev 16779)
+++ trunk/raster/rt_pg/rtpg_statistics.c 2018-09-13 17:25:51 UTC (rev 16780)
@@ -64,6 +64,8 @@
Datum RASTER_valueCount(PG_FUNCTION_ARGS);
Datum RASTER_valueCountCoverage(PG_FUNCTION_ARGS);
+#define VALUES_LENGTH 6
+
/**
* Get summary stats of a band
*/
@@ -80,9 +82,8 @@
rt_bandstats stats = NULL;
TupleDesc tupdesc;
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
@@ -160,7 +161,7 @@
BlessTupleDesc(tupdesc);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int64GetDatum(stats->count);
if (stats->count > 0) {
@@ -224,9 +225,8 @@
rt_bandstats stats = NULL;
rt_bandstats rtn = NULL;
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
Datum result;
/* tablename is null, return null */
@@ -458,7 +458,7 @@
BlessTupleDesc(tupdesc);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int64GetDatum(rtn->count);
if (rtn->count > 0) {
@@ -829,9 +829,8 @@
TupleDesc tupdesc;
HeapTuple tuple;
- int values_length = 6;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
Datum result;
POSTGIS_RT_DEBUG(3, "Starting...");
@@ -878,7 +877,7 @@
BlessTupleDesc(tupdesc);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Int64GetDatum(state->stats->count);
if (state->stats->count > 0) {
@@ -908,6 +907,9 @@
PG_RETURN_DATUM(result);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 4
+
/**
* Returns histogram for a band
*/
@@ -1153,15 +1155,14 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 4;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(hist2[call_cntr].min);
values[1] = Float8GetDatum(hist2[call_cntr].max);
@@ -1680,15 +1681,14 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 4;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(covhist2[call_cntr].min);
values[1] = Float8GetDatum(covhist2[call_cntr].max);
@@ -1710,6 +1710,9 @@
}
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 2
+
/**
* Returns quantiles for a band
*/
@@ -1932,15 +1935,14 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(quant2[call_cntr].quantile);
values[1] = Float8GetDatum(quant2[call_cntr].value);
@@ -2359,15 +2361,14 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 2;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(covquant2[call_cntr].quantile);
if (covquant2[call_cntr].has_value)
@@ -2391,6 +2392,9 @@
}
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 3
+
/* get counts of values */
PG_FUNCTION_INFO_V1(RASTER_valueCount);
Datum RASTER_valueCount(PG_FUNCTION_ARGS) {
@@ -2573,15 +2577,14 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 3;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(vcnts2[call_cntr].value);
values[1] = UInt32GetDatum(vcnts2[call_cntr].count);
@@ -3001,15 +3004,14 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 3;
- Datum values[values_length];
- bool nulls[values_length];
+ Datum values[VALUES_LENGTH];
+ bool nulls[VALUES_LENGTH];
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "Result %d", call_cntr);
- memset(nulls, FALSE, sizeof(bool) * values_length);
+ memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
values[0] = Float8GetDatum(covvcnts2[call_cntr].value);
values[1] = UInt32GetDatum(covvcnts2[call_cntr].count);
More information about the postgis-tickets
mailing list