[postgis-tickets] r16545 - Fix travis build (C90 compatibility)

Raul raul at rmr.ninja
Tue Apr 17 02:07:21 PDT 2018


Author: algunenano
Date: 2018-04-17 02:07:21 -0700 (Tue, 17 Apr 2018)
New Revision: 16545

Modified:
   trunk/libpgcommon/lwgeom_transform.c
   trunk/postgis/geography_centroid.c
   trunk/postgis/gserialized_estimate.c
   trunk/postgis/lwgeom_btree.c
   trunk/postgis/lwgeom_functions_basic.c
   trunk/postgis/lwgeom_geos_prepared.c
   trunk/postgis/lwgeom_rectree.c
Log:
Fix travis build (C90 compatibility)

References #4060
Closes https://github.com/postgis/postgis/pull/236


Modified: trunk/libpgcommon/lwgeom_transform.c
===================================================================
--- trunk/libpgcommon/lwgeom_transform.c	2018-04-17 09:02:22 UTC (rev 16544)
+++ trunk/libpgcommon/lwgeom_transform.c	2018-04-17 09:07:21 UTC (rev 16545)
@@ -504,6 +504,7 @@
 AddToPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid, int other_srid)
 {
 	MemoryContext PJMemoryContext;
+	MemoryContextCallback *callback;
 	projPJ projection = NULL;
 	char *proj_str = NULL;
 
@@ -572,7 +573,7 @@
 	/* PgSQL comments suggest allocating callback in the context */
 	/* being managed, so that the callback object gets cleaned along with */
 	/* the context */
-	MemoryContextCallback *callback = MemoryContextAlloc(PJMemoryContext, sizeof(MemoryContextCallback));
+	callback = MemoryContextAlloc(PJMemoryContext, sizeof(MemoryContextCallback));
 	callback->arg = (void*)PJMemoryContext;
 	callback->func = PROJ4SRSCacheDelete;
 	MemoryContextRegisterResetCallback(PJMemoryContext, callback);

Modified: trunk/postgis/geography_centroid.c
===================================================================
--- trunk/postgis/geography_centroid.c	2018-04-17 09:02:22 UTC (rev 16544)
+++ trunk/postgis/geography_centroid.c	2018-04-17 09:07:21 UTC (rev 16545)
@@ -252,7 +252,9 @@
 {
     double_t tolerance = 0.0;
     uint32_t size = 0;
-	uint32_t i, k;
+    uint32_t i, k, j = 0;
+    POINT3DM* points;
+    LWPOINT* result;
 
     /* get total number of points */
     for (i = 0; i < mline->ngeoms; i++) {
@@ -259,8 +261,7 @@
         size += (mline->geoms[i]->points->npoints - 1) * 2;
     }
 
-    POINT3DM* points = palloc(size*sizeof(POINT3DM));
-    uint32_t j = 0;
+    points = palloc(size*sizeof(POINT3DM));
 
     for (i = 0; i < mline->ngeoms; i++) {
         LWLINE* line = mline->geoms[i];
@@ -269,6 +270,7 @@
         for (k = 0; k < line->points->npoints - 1; k++) {
             const POINT2D* p1 = getPoint2d_cp(line->points, k);
             const POINT2D* p2 = getPoint2d_cp(line->points, k+1);
+            double_t weight;
 
             /* use line-segment length as weight */
             LWPOINT* lwp1 = lwpoint_make2d(mline->srid, p1->x, p1->y);
@@ -279,7 +281,7 @@
             lwgeom_set_geodetic(lwgeom2, LW_TRUE);
 
             /* use point distance as weight */
-            double_t weight = lwgeom_distance_spheroid(lwgeom1, lwgeom2, s, tolerance);
+            weight = lwgeom_distance_spheroid(lwgeom1, lwgeom2, s, tolerance);
 
             points[j].x = p1->x;
             points[j].y = p1->y;
@@ -296,7 +298,7 @@
         }
     }
 
-    LWPOINT* result = geography_centroid_from_wpoints(mline->srid, points, size);
+    result = geography_centroid_from_wpoints(mline->srid, points, size);
     pfree(points);
     return result;
 }
@@ -308,8 +310,12 @@
  */
 LWPOINT* geography_centroid_from_mpoly(const LWMPOLY* mpoly, bool use_spheroid, SPHEROID* s)
 {
-    uint32_t size = 0;
-	uint32_t i, ir, ip;
+	uint32_t size = 0;
+	uint32_t i, ir, ip, j = 0;
+	POINT3DM* points;
+	POINT4D* reference_point = NULL;
+	LWPOINT* result = NULL;
+
     for (ip = 0; ip < mpoly->ngeoms; ip++) {
 		for (ir = 0; ir < mpoly->geoms[ip]->nrings; ir++) {
         	size += mpoly->geoms[ip]->rings[ir]->npoints - 1;
@@ -316,11 +322,11 @@
 		}
     }
 
-    POINT3DM* points = palloc(size*sizeof(POINT3DM));
-    uint32_t j = 0;
+    points = palloc(size*sizeof(POINT3DM));
 
+
     /* use first point as reference to create triangles */
-    const POINT4D* reference_point = (const POINT4D*) getPoint2d_cp(mpoly->geoms[0]->rings[0], 0);
+    reference_point = (POINT4D*) getPoint2d_cp(mpoly->geoms[0]->rings[0], 0);
 
     for (ip = 0; ip < mpoly->ngeoms; ip++) {
         LWPOLY* poly = mpoly->geoms[ip];
@@ -332,6 +338,11 @@
             for (i = 0; i < ring->npoints - 1; i++) {
                 const POINT4D* p1 = (const POINT4D*) getPoint2d_cp(ring, i);
                 const POINT4D* p2 = (const POINT4D*) getPoint2d_cp(ring, i+1);
+		LWPOLY* poly_tri;
+		LWGEOM* geom_tri;
+		double_t weight;
+		POINT3DM triangle[3];
+		LWPOINT* tri_centroid;
 
                 POINTARRAY* pa = ptarray_construct_empty(0, 0, 4);
                 ptarray_insert_point(pa, p1, 0);
@@ -339,10 +350,10 @@
                 ptarray_insert_point(pa, reference_point, 2);
                 ptarray_insert_point(pa, p1, 3);
 
-                LWPOLY* poly_tri = lwpoly_construct_empty(mpoly->srid, 0, 0);
+                poly_tri = lwpoly_construct_empty(mpoly->srid, 0, 0);
                 lwpoly_add_ring(poly_tri, pa);
 
-                LWGEOM* geom_tri = lwpoly_as_lwgeom(poly_tri);
+                geom_tri = lwpoly_as_lwgeom(poly_tri);
                 lwgeom_set_geodetic(geom_tri, LW_TRUE);
 
             	/* Calculate the weight of the triangle. If counter clockwise,
@@ -349,7 +360,6 @@
                  * the weight is negative (e.g. for holes in polygons)
                  */
 
-                double_t weight;
             	if ( use_spheroid )
             		weight = lwgeom_area_spheroid(geom_tri, s);
             	else
@@ -356,7 +366,6 @@
             		weight = lwgeom_area_sphere(geom_tri, s);
 
 
-                POINT3DM triangle[3];
                 triangle[0].x = p1->x;
                 triangle[0].y = p1->y;
                 triangle[0].m = 1;
@@ -370,7 +379,7 @@
                 triangle[2].m = 1;
 
                 /* get center of triangle */
-                LWPOINT* tri_centroid = geography_centroid_from_wpoints(mpoly->srid, triangle, 3);
+                tri_centroid = geography_centroid_from_wpoints(mpoly->srid, triangle, 3);
 
                 points[j].x = lwpoint_get_x(tri_centroid);
                 points[j].y = lwpoint_get_y(tri_centroid);
@@ -377,12 +386,12 @@
                 points[j].m = weight;
                 j++;
 
-				lwpoint_free(tri_centroid);
+                lwpoint_free(tri_centroid);
                 lwgeom_free(geom_tri);
             }
         }
     }
-    LWPOINT* result = geography_centroid_from_wpoints(mpoly->srid, points, size);
+    result = geography_centroid_from_wpoints(mpoly->srid, points, size);
     pfree(points);
     return result;
 }

Modified: trunk/postgis/gserialized_estimate.c
===================================================================
--- trunk/postgis/gserialized_estimate.c	2018-04-17 09:02:22 UTC (rev 16544)
+++ trunk/postgis/gserialized_estimate.c	2018-04-17 09:07:21 UTC (rev 16545)
@@ -307,9 +307,10 @@
 text_p_get_mode(const text *txt)
 {
 	int mode = 2;
+	char *modestr;
 	if (VARSIZE(txt) - VARHDRSZ <= 0)
 		return mode;
-	char *modestr = (char*)VARDATA(txt);
+	modestr = (char*)VARDATA(txt);
 	if ( modestr[0] == 'N' )
 		mode = 0;
 	return mode;
@@ -883,39 +884,41 @@
     /* Then read the geom status histogram from that */
 
 #if POSTGIS_PGSQL_VERSION < 100
-	float4 *floatptr;
-	int nvalues;
+	{
+		float4 *floatptr;
+		int nvalues;
 
-	rv = get_attstatsslot(stats_tuple, 0, 0, stats_kind, InvalidOid,
-						NULL, NULL, NULL, &floatptr, &nvalues);
+		rv = get_attstatsslot(stats_tuple, 0, 0, stats_kind, InvalidOid,
+							NULL, NULL, NULL, &floatptr, &nvalues);
 
-	if ( ! rv ) {
-		POSTGIS_DEBUGF(2,
-				"no slot of kind %d in stats tuple", stats_kind);
-		return NULL;
-	}
+		if ( ! rv ) {
+			POSTGIS_DEBUGF(2, "no slot of kind %d in stats tuple", stats_kind);
+			return NULL;
+		}
 
-	/* Clone the stats here so we can release the attstatsslot immediately */
-	nd_stats = palloc(sizeof(float) * nvalues);
-	memcpy(nd_stats, floatptr, sizeof(float) * nvalues);
+		/* Clone the stats here so we can release the attstatsslot immediately */
+		nd_stats = palloc(sizeof(float) * nvalues);
+		memcpy(nd_stats, floatptr, sizeof(float) * nvalues);
 
-	/* Clean up */
-	free_attstatsslot(0, NULL, 0, floatptr, nvalues);
+		/* Clean up */
+		free_attstatsslot(0, NULL, 0, floatptr, nvalues);
+	}
 #else /* PostgreSQL 10 or higher */
-	AttStatsSlot sslot;
-	rv = get_attstatsslot(&sslot, stats_tuple, stats_kind, InvalidOid,
-						 ATTSTATSSLOT_NUMBERS);
-	if ( ! rv ) {
-		POSTGIS_DEBUGF(2,
-				"no slot of kind %d in stats tuple", stats_kind);
-		return NULL;
-	}
+	{
+		AttStatsSlot sslot;
+		rv = get_attstatsslot(&sslot, stats_tuple, stats_kind, InvalidOid,
+							 ATTSTATSSLOT_NUMBERS);
+		if ( ! rv ) {
+			POSTGIS_DEBUGF(2, "no slot of kind %d in stats tuple", stats_kind);
+			return NULL;
+		}
 
-	/* Clone the stats here so we can release the attstatsslot immediately */
-	nd_stats = palloc(sizeof(float4) * sslot.nnumbers);
-	memcpy(nd_stats, sslot.numbers, sizeof(float4) * sslot.nnumbers);
+		/* Clone the stats here so we can release the attstatsslot immediately */
+		nd_stats = palloc(sizeof(float4) * sslot.nnumbers);
+		memcpy(nd_stats, sslot.numbers, sizeof(float4) * sslot.nnumbers);
 
-	free_attstatsslot(&sslot);
+		free_attstatsslot(&sslot);
+	}
 #endif
 
 	return nd_stats;
@@ -2475,18 +2478,24 @@
 	BOX2DF *bounds_2df = NULL;
 	GIDX *bounds_gidx = NULL;
 	GBOX *gbox = NULL;
+	Relation idx_rel;
+	Buffer buffer;
+	Page page;
+	OffsetNumber offset;
+	unsigned long offset_max;
 
 	if (!idx_oid)
 		return NULL;
 
-	Relation idx_rel = index_open(idx_oid, AccessExclusiveLock);
-	Buffer buffer = ReadBuffer(idx_rel, GIST_ROOT_BLKNO);
-	Page page = (Page) BufferGetPage(buffer);
-	OffsetNumber offset = FirstOffsetNumber;
-	unsigned long offset_max = PageGetMaxOffsetNumber(page);
+	idx_rel = index_open(idx_oid, AccessExclusiveLock);
+	buffer = ReadBuffer(idx_rel, GIST_ROOT_BLKNO);
+	page = (Page) BufferGetPage(buffer);
+	offset = FirstOffsetNumber;
+	offset_max = PageGetMaxOffsetNumber(page);
 	while (offset <= offset_max)
 	{
 		ItemId iid = PageGetItemId(page, offset);
+		IndexTuple ituple;
 		if (!iid)
 		{
 			ReleaseBuffer(buffer);
@@ -2493,7 +2502,7 @@
 			index_close(idx_rel, AccessExclusiveLock);
 			return NULL;
 		}
-		IndexTuple ituple = (IndexTuple) PageGetItem(page, iid);
+		ituple = (IndexTuple) PageGetItem(page, iid);
 		if (!GistTupleIsInvalid(ituple))
 		{
 			bool isnull;

Modified: trunk/postgis/lwgeom_btree.c
===================================================================
--- trunk/postgis/lwgeom_btree.c	2018-04-17 09:02:22 UTC (rev 16544)
+++ trunk/postgis/lwgeom_btree.c	2018-04-17 09:07:21 UTC (rev 16545)
@@ -131,6 +131,7 @@
 PG_FUNCTION_INFO_V1(lwgeom_hash);
 Datum lwgeom_hash(PG_FUNCTION_ARGS)
 {
+	Datum hval;
 	GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
 	/* Point to just the type/coordinate part of buffer */
 	size_t hsz1 = gserialized_header_size(g1);
@@ -147,7 +148,7 @@
 	/* Copy type/coordinates into rest of combined buffer */
 	memcpy(b2+sizeof(int), b1, bsz1);
 	/* Hash combined buffer */
-	Datum hval = hash_any(b2, bsz2);
+	hval = hash_any(b2, bsz2);
 	pfree(b2);
 	PG_FREE_IF_COPY(g1, 0);
 	PG_RETURN_DATUM(hval);

Modified: trunk/postgis/lwgeom_functions_basic.c
===================================================================
--- trunk/postgis/lwgeom_functions_basic.c	2018-04-17 09:02:22 UTC (rev 16544)
+++ trunk/postgis/lwgeom_functions_basic.c	2018-04-17 09:07:21 UTC (rev 16545)
@@ -3084,6 +3084,8 @@
 	LWGEOM *lwgeom_out;
 	double min, max;
 	int returnm;
+	int hasm;
+
 	if ( PG_NARGS() > 0 && ! PG_ARGISNULL(0))
 	{
 		geom_in = PG_GETARG_GSERIALIZED_P(0);
@@ -3120,7 +3122,7 @@
 
 	lwgeom_in = lwgeom_from_gserialized(geom_in);
 
-	int hasm = FLAGS_GET_M(lwgeom_in->flags);
+	hasm = FLAGS_GET_M(lwgeom_in->flags);
 
 	if(!hasm)
 	{

Modified: trunk/postgis/lwgeom_geos_prepared.c
===================================================================
--- trunk/postgis/lwgeom_geos_prepared.c	2018-04-17 09:02:22 UTC (rev 16544)
+++ trunk/postgis/lwgeom_geos_prepared.c	2018-04-17 09:07:21 UTC (rev 16545)
@@ -320,6 +320,7 @@
 		                             "PostGIS Prepared Geometry Context");
 
 #else
+		MemoryContextCallback *callback;
 		prepcache->context_callback = AllocSetContextCreate(prepcache->context_statement,
 	                                   "PostGIS Prepared Geometry Context",
 	                                   ALLOCSET_SMALL_SIZES);
@@ -327,7 +328,7 @@
 		/* PgSQL comments suggest allocating callback in the context */
 		/* being managed, so that the callback object gets cleaned along with */
 		/* the context */
-		MemoryContextCallback *callback = MemoryContextAlloc(prepcache->context_callback, sizeof(MemoryContextCallback));
+		callback = MemoryContextAlloc(prepcache->context_callback, sizeof(MemoryContextCallback));
 		callback->arg = (void*)(prepcache->context_callback);
 		callback->func = PreparedCacheDelete;
 		MemoryContextRegisterResetCallback(prepcache->context_callback, callback);

Modified: trunk/postgis/lwgeom_rectree.c
===================================================================
--- trunk/postgis/lwgeom_rectree.c	2018-04-17 09:02:22 UTC (rev 16544)
+++ trunk/postgis/lwgeom_rectree.c	2018-04-17 09:07:21 UTC (rev 16545)
@@ -121,6 +121,8 @@
 {
 	GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
 	GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
+	LWGEOM *lwg1, *lwg2;
+	RECT_NODE *n1, *n2;
 
 	/* Return NULL on empty arguments. */
 	if (gserialized_is_empty(g1) || gserialized_is_empty(g2))
@@ -130,8 +132,8 @@
 		PG_RETURN_NULL();
 	}
 
-	LWGEOM *lwg1 = lwgeom_from_gserialized(g1);
-	LWGEOM *lwg2 = lwgeom_from_gserialized(g2);
+	lwg1 = lwgeom_from_gserialized(g1);
+	lwg2 = lwgeom_from_gserialized(g2);
 
 	/* Two points? Get outa here... */
 	if (lwg1->type == POINTTYPE && lwg2->type == POINTTYPE)
@@ -138,8 +140,8 @@
 		PG_RETURN_FLOAT8(lwgeom_mindistance2d(lwg1, lwg2));
 
 
-	RECT_NODE *n1 = rect_tree_from_lwgeom(lwg1);
-	RECT_NODE *n2 = rect_tree_from_lwgeom(lwg2);
+	n1 = rect_tree_from_lwgeom(lwg1);
+	n2 = rect_tree_from_lwgeom(lwg2);
 	PG_RETURN_FLOAT8(rect_tree_distance_tree(n1, n2, 0.0));
 }
 
@@ -149,6 +151,7 @@
 	RectTreeGeomCache *tree_cache = NULL;
 	GSERIALIZED *g1 = PG_GETARG_GSERIALIZED_P(0);
 	GSERIALIZED *g2 = PG_GETARG_GSERIALIZED_P(1);
+	LWGEOM *lwg1, *lwg2;
 
 	/* Return NULL on empty arguments. */
 	if (gserialized_is_empty(g1) || gserialized_is_empty(g2))
@@ -158,8 +161,8 @@
 		PG_RETURN_NULL();
 	}
 
-	LWGEOM *lwg1 = lwgeom_from_gserialized(g1);
-	LWGEOM *lwg2 = lwgeom_from_gserialized(g2);
+	lwg1 = lwgeom_from_gserialized(g1);
+	lwg2 = lwgeom_from_gserialized(g2);
 
 	/* Two points? Get outa here... */
 	if (lwg1->type == POINTTYPE && lwg2->type == POINTTYPE)



More information about the postgis-tickets mailing list