[postgis-tickets] r16777 - Postgres 12 disallows variable length arrays in C

Darafei komzpa at gmail.com
Thu Sep 13 07:54:02 PDT 2018


Author: komzpa
Date: 2018-09-13 07:54:02 -0700 (Thu, 13 Sep 2018)
New Revision: 16777

Modified:
   trunk/NEWS
   trunk/postgis/gserialized_estimate.c
Log:
Postgres 12 disallows variable length arrays in C 

Patch by Laurenz Albe

Closes #4177



Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2018-09-13 13:48:42 UTC (rev 16776)
+++ trunk/NEWS	2018-09-13 14:54:02 UTC (rev 16777)
@@ -13,6 +13,7 @@
   - #4172, Fix memory leak in lwgeom_offsetcurve (Raúl Marín)
   - #4173, Fix undefined behaviour in ptarray_segmentize2d (Raúl Marín)
   - #4176, ST_Intersects supports GEOMETRYCOLLECTION (Darafei Praliaskouski)
+  - #4177, Postgres 12 disallows variable length arrays in C (Laurenz Albe)
 
 PostGIS 2.5.0rc1
 2018/08/19

Modified: trunk/postgis/gserialized_estimate.c
===================================================================
--- trunk/postgis/gserialized_estimate.c	2018-09-13 13:48:42 UTC (rev 16776)
+++ trunk/postgis/gserialized_estimate.c	2018-09-13 14:54:02 UTC (rev 16777)
@@ -740,6 +740,8 @@
 	return ivol / vol2;
 }
 
+/* How many bins shall we use in figuring out the distribution? */
+#define NUM_BINS 50
 
 /**
 * Calculate how much a set of boxes is homogenously distributed
@@ -759,10 +761,8 @@
 static int
 nd_box_array_distribution(const ND_BOX **nd_boxes, int num_boxes, const ND_BOX *extent, int ndims, double *distribution)
 {
-	/* How many bins shall we use in figuring out the distribution? */
-	static int num_bins = 50;
 	int d, i, k, range;
-	int counts[num_bins];
+	int counts[NUM_BINS];
 	double smin, smax;   /* Spatial min, spatial max */
 	double swidth;       /* Spatial width of dimension */
 #if POSTGIS_DEBUG_LEVEL >= 3
@@ -775,7 +775,7 @@
 	for ( d = 0; d < ndims; d++ )
 	{
 		/* Initialize counts for this dimension */
-		memset(counts, 0, sizeof(int)*num_bins);
+		memset(counts, 0, sizeof(int)*NUM_BINS);
 
 		smin = extent->min[d];
 		smax = extent->max[d];
@@ -809,8 +809,8 @@
 			}
 
 			/* What bins does this range correspond to? */
-			bmin = num_bins * (minoffset) / swidth;
-			bmax = num_bins * (maxoffset) / swidth;
+			bmin = NUM_BINS * (minoffset) / swidth;
+			bmax = NUM_BINS * (maxoffset) / swidth;
 
 			POSTGIS_DEBUGF(4, " dimension %d, feature %d: bin %d to bin %d", d, i, bmin, bmax);
 
@@ -823,11 +823,11 @@
 		}
 
 		/* How dispersed is the distribution of features across bins? */
-		range = range_quintile(counts, num_bins);
+		range = range_quintile(counts, NUM_BINS);
 
 #if POSTGIS_DEBUG_LEVEL >= 3
-		average = avg(counts, num_bins);
-		sdev = stddev(counts, num_bins);
+		average = avg(counts, NUM_BINS);
+		sdev = stddev(counts, NUM_BINS);
 		sdev_ratio = sdev/average;
 
 		POSTGIS_DEBUGF(3, " dimension %d: range = %d", d, range);



More information about the postgis-tickets mailing list