From ad2f5f4b6abc4b626708534b25effc96643518f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ra=C3=BAl=20Mar=C3=ADn=20Rodr=C3=ADguez?= Date: Tue, 17 Apr 2018 09:07:21 +0000 Subject: [PATCH] Fix travis build (C90 compatibility) References #4060 Closes https://github.com/postgis/postgis/pull/236 git-svn-id: http://svn.osgeo.org/postgis/trunk@16545 b70326c6-7e19-0410-871a-916f4a2858ee --- libpgcommon/lwgeom_transform.c | 3 +- postgis/geography_centroid.c | 43 ++++++++++-------- postgis/gserialized_estimate.c | 75 ++++++++++++++++++-------------- postgis/lwgeom_btree.c | 3 +- postgis/lwgeom_functions_basic.c | 4 +- postgis/lwgeom_geos_prepared.c | 3 +- postgis/lwgeom_rectree.c | 15 ++++--- 7 files changed, 86 insertions(+), 60 deletions(-) diff --git a/libpgcommon/lwgeom_transform.c b/libpgcommon/lwgeom_transform.c index b793635a9..0d73c3d92 100644 --- a/libpgcommon/lwgeom_transform.c +++ b/libpgcommon/lwgeom_transform.c @@ -504,6 +504,7 @@ static void AddToPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid, int other_srid) { MemoryContext PJMemoryContext; + MemoryContextCallback *callback; projPJ projection = NULL; char *proj_str = NULL; @@ -572,7 +573,7 @@ AddToPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid, int other_srid) /* 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); diff --git a/postgis/geography_centroid.c b/postgis/geography_centroid.c index 3b988fb85..411bd914d 100644 --- a/postgis/geography_centroid.c +++ b/postgis/geography_centroid.c @@ -252,15 +252,16 @@ LWPOINT* geography_centroid_from_mline(const LWMLINE* mline, SPHEROID* s) { 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++) { 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 @@ LWPOINT* geography_centroid_from_mline(const LWMLINE* mline, SPHEROID* s) 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 @@ LWPOINT* geography_centroid_from_mline(const LWMLINE* mline, SPHEROID* s) 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* geography_centroid_from_mline(const LWMLINE* mline, SPHEROID* s) } } - LWPOINT* result = geography_centroid_from_wpoints(mline->srid, points, size); + result = geography_centroid_from_wpoints(mline->srid, points, size); pfree(points); return result; } @@ -308,19 +310,23 @@ LWPOINT* geography_centroid_from_mline(const LWMLINE* mline, SPHEROID* s) */ 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; } } - 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 @@ LWPOINT* geography_centroid_from_mpoly(const LWMPOLY* mpoly, bool use_spheroid, 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,24 +350,22 @@ LWPOINT* geography_centroid_from_mpoly(const LWMPOLY* mpoly, bool use_spheroid, 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, * the weight is negative (e.g. for holes in polygons) */ - double_t weight; if ( use_spheroid ) weight = lwgeom_area_spheroid(geom_tri, s); else 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,19 +379,19 @@ LWPOINT* geography_centroid_from_mpoly(const LWMPOLY* mpoly, bool use_spheroid, 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); 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; } diff --git a/postgis/gserialized_estimate.c b/postgis/gserialized_estimate.c index 76a9e8d8f..c27755742 100644 --- a/postgis/gserialized_estimate.c +++ b/postgis/gserialized_estimate.c @@ -307,9 +307,10 @@ static int 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 @@ pg_nd_stats_from_tuple(HeapTuple stats_tuple, int mode) /* 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); -#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; + /* 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; + } - /* 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,25 +2478,31 @@ spatial_index_read_extent(Oid idx_oid, int key_type) 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); index_close(idx_rel, AccessExclusiveLock); return NULL; } - IndexTuple ituple = (IndexTuple) PageGetItem(page, iid); + ituple = (IndexTuple) PageGetItem(page, iid); if (!GistTupleIsInvalid(ituple)) { bool isnull; diff --git a/postgis/lwgeom_btree.c b/postgis/lwgeom_btree.c index d150f1161..c704364de 100644 --- a/postgis/lwgeom_btree.c +++ b/postgis/lwgeom_btree.c @@ -131,6 +131,7 @@ Datum lwgeom_cmp(PG_FUNCTION_ARGS) 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 @@ Datum lwgeom_hash(PG_FUNCTION_ARGS) /* 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); diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index f664c0f79..a84fc2cdf 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -3084,6 +3084,8 @@ Datum LWGEOM_FilterByM(PG_FUNCTION_ARGS) 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 @@ Datum LWGEOM_FilterByM(PG_FUNCTION_ARGS) lwgeom_in = lwgeom_from_gserialized(geom_in); - int hasm = FLAGS_GET_M(lwgeom_in->flags); + hasm = FLAGS_GET_M(lwgeom_in->flags); if(!hasm) { diff --git a/postgis/lwgeom_geos_prepared.c b/postgis/lwgeom_geos_prepared.c index a887f8556..4dfa5c085 100644 --- a/postgis/lwgeom_geos_prepared.c +++ b/postgis/lwgeom_geos_prepared.c @@ -320,6 +320,7 @@ PrepGeomCacheBuilder(const LWGEOM *lwgeom, GeomCache *cache) "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 @@ PrepGeomCacheBuilder(const LWGEOM *lwgeom, GeomCache *cache) /* 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); diff --git a/postgis/lwgeom_rectree.c b/postgis/lwgeom_rectree.c index 1c75a06f4..b96949f7d 100644 --- a/postgis/lwgeom_rectree.c +++ b/postgis/lwgeom_rectree.c @@ -121,6 +121,8 @@ Datum ST_DistanceRectTree(PG_FUNCTION_ARGS) { 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,16 +132,16 @@ Datum ST_DistanceRectTree(PG_FUNCTION_ARGS) 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) 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 @@ Datum ST_DistanceRectTreeCached(PG_FUNCTION_ARGS) 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 @@ Datum ST_DistanceRectTreeCached(PG_FUNCTION_ARGS) 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) -- 2.40.0