[postgis-tickets] r16971 - Remove use of variable length arrays
Paul Ramsey
pramsey at cleverelephant.ca
Thu Nov 1 12:40:16 PDT 2018
Author: pramsey
Date: 2018-11-01 12:40:15 -0700 (Thu, 01 Nov 2018)
New Revision: 16971
Modified:
branches/2.4/NEWS
branches/2.4/raster/rt_pg/rtpg_band_properties.c
branches/2.4/raster/rt_pg/rtpg_gdal.c
branches/2.4/raster/rt_pg/rtpg_geometry.c
branches/2.4/raster/rt_pg/rtpg_mapalgebra.c
branches/2.4/raster/rt_pg/rtpg_pixel.c
branches/2.4/raster/rt_pg/rtpg_raster_properties.c
branches/2.4/raster/rt_pg/rtpg_statistics.c
Log:
Remove use of variable length arrays
References #4177
Modified: branches/2.4/NEWS
===================================================================
--- branches/2.4/NEWS 2018-11-01 19:31:24 UTC (rev 16970)
+++ branches/2.4/NEWS 2018-11-01 19:40:15 UTC (rev 16971)
@@ -12,6 +12,7 @@
- #4206, Fix support for PostgreSQL 12 dev branch (Laurenz Albe)
- #3457, Fix raster envelope shortcut in ST_Clip (Sai-bot)
- #4215, Use floating point compare in ST_DumpAsPolygons (Darafei Praliaskouski)
+ - #4059, #4177, Remove use of variable length arrays
PostGIS 2.4.5
Modified: branches/2.4/raster/rt_pg/rtpg_band_properties.c
===================================================================
--- branches/2.4/raster/rt_pg/rtpg_band_properties.c 2018-11-01 19:31:24 UTC (rev 16970)
+++ branches/2.4/raster/rt_pg/rtpg_band_properties.c 2018-11-01 19:40:15 UTC (rev 16971)
@@ -340,6 +340,8 @@
PG_RETURN_TEXT_P(result);
}
+#define VALUES_LENGTH 8
+
/**
* Get raster bands' meta data
*/
@@ -564,11 +566,10 @@
/* do when there is more left to send */
if (call_cntr < max_calls) {
- int values_length = 5;
- 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: branches/2.4/raster/rt_pg/rtpg_gdal.c
===================================================================
--- branches/2.4/raster/rt_pg/rtpg_gdal.c 2018-11-01 19:31:24 UTC (rev 16970)
+++ branches/2.4/raster/rt_pg/rtpg_gdal.c 2018-11-01 19:40:15 UTC (rev 16971)
@@ -337,6 +337,8 @@
PG_RETURN_POINTER(result);
}
+#define VALUES_LENGTH 6
+
/**
* Returns available GDAL drivers
*/
@@ -403,15 +405,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] = Int32GetDatum(drv_set2[call_cntr].idx);
values[1] = CStringGetTextDatum(drv_set2[call_cntr].short_name);
Modified: branches/2.4/raster/rt_pg/rtpg_geometry.c
===================================================================
--- branches/2.4/raster/rt_pg/rtpg_geometry.c 2018-11-01 19:31:24 UTC (rev 16970)
+++ branches/2.4/raster/rt_pg/rtpg_geometry.c 2018-11-01 19:40:15 UTC (rev 16971)
@@ -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: branches/2.4/raster/rt_pg/rtpg_mapalgebra.c
===================================================================
--- branches/2.4/raster/rt_pg/rtpg_mapalgebra.c 2018-11-01 19:31:24 UTC (rev 16970)
+++ branches/2.4/raster/rt_pg/rtpg_mapalgebra.c 2018-11-01 19:40:15 UTC (rev 16971)
@@ -6070,6 +6070,8 @@
PG_RETURN_POINTER(pgrtn);
}
+#define ARGKWCOUNT 8
+
/**
* Two raster MapAlgebra
*/
@@ -6117,11 +6119,10 @@
SPIPlanPtr spi_plan[3] = {NULL};
uint16_t spi_empty = 0;
Oid *argtype = NULL;
- const int 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];
- bool nulls[argkwcount];
+ Datum values[ARGKWCOUNT];
+ bool nulls[ARGKWCOUNT];
TupleDesc tupdesc;
SPITupleTable *tuptable = NULL;
HeapTuple tuple;
@@ -6640,7 +6641,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);
@@ -6705,7 +6706,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 */
@@ -7006,12 +7007,12 @@
/* expression has argument(s) */
if (spi_argcount[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(bool) * argkwcount);
+ memset(nulls, FALSE, sizeof(bool) * ARGKWCOUNT);
/* 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: branches/2.4/raster/rt_pg/rtpg_pixel.c
===================================================================
--- branches/2.4/raster/rt_pg/rtpg_pixel.c 2018-11-01 19:31:24 UTC (rev 16970)
+++ branches/2.4/raster/rt_pg/rtpg_pixel.c 2018-11-01 19:40:15 UTC (rev 16971)
@@ -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: branches/2.4/raster/rt_pg/rtpg_raster_properties.c
===================================================================
--- branches/2.4/raster/rt_pg/rtpg_raster_properties.c 2018-11-01 19:31:24 UTC (rev 16970)
+++ branches/2.4/raster/rt_pg/rtpg_raster_properties.c 2018-11-01 19:40:15 UTC (rev 16971)
@@ -427,6 +427,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.
@@ -447,9 +449,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;
@@ -501,7 +502,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);
@@ -579,6 +580,9 @@
PG_RETURN_BOOL(hasnoband);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 10
+
/**
* Get raster's meta data
*/
@@ -600,9 +604,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;
@@ -670,7 +673,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);
@@ -681,6 +684,9 @@
PG_RETURN_DATUM(result);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 2
+
PG_FUNCTION_INFO_V1(RASTER_rasterToWorldCoord);
Datum RASTER_rasterToWorldCoord(PG_FUNCTION_ARGS)
{
@@ -692,9 +698,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;
@@ -765,7 +770,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);
@@ -788,9 +793,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;
@@ -866,7 +870,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: branches/2.4/raster/rt_pg/rtpg_statistics.c
===================================================================
--- branches/2.4/raster/rt_pg/rtpg_statistics.c 2018-11-01 19:31:24 UTC (rev 16970)
+++ branches/2.4/raster/rt_pg/rtpg_statistics.c 2018-11-01 19:40:15 UTC (rev 16971)
@@ -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 */
@@ -462,7 +462,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) {
@@ -833,9 +833,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...");
@@ -882,7 +881,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) {
@@ -912,6 +911,9 @@
PG_RETURN_DATUM(result);
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 4
+
/**
* Returns histogram for a band
*/
@@ -1157,15 +1159,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);
@@ -1688,15 +1689,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);
@@ -1718,6 +1718,9 @@
}
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 2
+
/**
* Returns quantiles for a band
*/
@@ -1940,15 +1943,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);
@@ -2369,15 +2371,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)
@@ -2401,6 +2402,9 @@
}
}
+#undef VALUES_LENGTH
+#define VALUES_LENGTH 3
+
/* get counts of values */
PG_FUNCTION_INFO_V1(RASTER_valueCount);
Datum RASTER_valueCount(PG_FUNCTION_ARGS) {
@@ -2583,15 +2587,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);
@@ -3015,15 +3018,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