[postgis-tickets] r16546 - Fix dronie build

Raul raul at rmr.ninja
Tue Apr 17 03:05:54 PDT 2018


Author: algunenano
Date: 2018-04-17 03:05:54 -0700 (Tue, 17 Apr 2018)
New Revision: 16546

Modified:
   trunk/libpgcommon/lwgeom_transform.c
   trunk/postgis/geobuf.c
   trunk/postgis/lwgeom_out_mvt.c
   trunk/postgis/mvt.c
Log:
Fix dronie build

References #4060


Modified: trunk/libpgcommon/lwgeom_transform.c
===================================================================
--- trunk/libpgcommon/lwgeom_transform.c	2018-04-17 09:07:21 UTC (rev 16545)
+++ trunk/libpgcommon/lwgeom_transform.c	2018-04-17 10:05:54 UTC (rev 16546)
@@ -504,7 +504,6 @@
 AddToPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid, int other_srid)
 {
 	MemoryContext PJMemoryContext;
-	MemoryContextCallback *callback;
 	projPJ projection = NULL;
 	char *proj_str = NULL;
 
@@ -573,10 +572,12 @@
 	/* PgSQL comments suggest allocating callback in the context */
 	/* being managed, so that the callback object gets cleaned along with */
 	/* the context */
-	callback = MemoryContextAlloc(PJMemoryContext, sizeof(MemoryContextCallback));
-	callback->arg = (void*)PJMemoryContext;
-	callback->func = PROJ4SRSCacheDelete;
-	MemoryContextRegisterResetCallback(PJMemoryContext, callback);
+	{
+		MemoryContextCallback *callback = MemoryContextAlloc(PJMemoryContext, sizeof(MemoryContextCallback));
+		callback->arg = (void*)PJMemoryContext;
+		callback->func = PROJ4SRSCacheDelete;
+		MemoryContextRegisterResetCallback(PJMemoryContext, callback);
+	}
 #endif
 
  	/* Create the backend hash if it doesn't already exist */

Modified: trunk/postgis/geobuf.c
===================================================================
--- trunk/postgis/geobuf.c	2018-04-17 09:07:21 UTC (rev 16545)
+++ trunk/postgis/geobuf.c	2018-04-17 10:05:54 UTC (rev 16546)
@@ -114,6 +114,7 @@
 		char *type, *string_value;
 		Datum datum;
 		bool isnull;
+		Oid typoid;
 
 		if (i == ctx->geom_index)
 			continue;
@@ -127,9 +128,9 @@
 		if (isnull)
 			continue;
 #if POSTGIS_PGSQL_VERSION < 110
-		Oid typoid = getBaseType(tupdesc->attrs[i]->atttypid);
+		typoid = getBaseType(tupdesc->attrs[i]->atttypid);
 #else
-		Oid typoid = getBaseType(tupdesc->attrs[i].atttypid);
+		typoid = getBaseType(tupdesc->attrs[i].atttypid);
 #endif
 		if (strcmp(type, "int2") == 0) {
 			set_int_value(value, DatumGetInt16(datum));
@@ -605,9 +606,10 @@
  */
 uint8_t *geobuf_agg_finalfn(struct geobuf_agg_context *ctx)
 {
-	size_t i;
+	size_t i, len;
 	Data *data;
 	Data__FeatureCollection *fc;
+	uint8_t *buf;
 
 	data = ctx->data;
 	fc = data->feature_collection;
@@ -630,8 +632,8 @@
 	for (i = 0; i < fc->n_features; i++)
 		fc->features[i]->geometry = encode_geometry(ctx, ctx->lwgeoms[i]);
 
-	size_t len = data__get_packed_size(data);
-	uint8_t *buf = palloc(sizeof(*buf) * (len + VARHDRSZ));
+	len = data__get_packed_size(data);
+	buf = palloc(sizeof(*buf) * (len + VARHDRSZ));
 	data__pack(data, buf + VARHDRSZ);
 
 	SET_VARSIZE(buf, VARHDRSZ + len);

Modified: trunk/postgis/lwgeom_out_mvt.c
===================================================================
--- trunk/postgis/lwgeom_out_mvt.c	2018-04-17 09:07:21 UTC (rev 16545)
+++ trunk/postgis/lwgeom_out_mvt.c	2018-04-17 10:05:54 UTC (rev 16546)
@@ -177,12 +177,13 @@
 	PG_RETURN_NULL();
 #else
 	MemoryContext aggcontext, oldcontext;
+	mvt_agg_context *ctx;
 	elog(DEBUG2, "%s called", __func__);
 	if (!AggCheckCallContext(fcinfo, &aggcontext))
 		elog(ERROR, "%s called in non-aggregate context", __func__);
 
 	oldcontext = MemoryContextSwitchTo(aggcontext);
-	mvt_agg_context *ctx = mvt_ctx_deserialize(PG_GETARG_BYTEA_P(0));
+	ctx = mvt_ctx_deserialize(PG_GETARG_BYTEA_P(0));
 	MemoryContextSwitchTo(oldcontext);
 
 	PG_RETURN_POINTER(ctx);
@@ -197,11 +198,11 @@
 	PG_RETURN_NULL();
 #else
 	MemoryContext aggcontext, oldcontext;
+	mvt_agg_context *ctx, *ctx1, *ctx2;
 	elog(DEBUG2, "%s called", __func__);
 	if (!AggCheckCallContext(fcinfo, &aggcontext))
 		elog(ERROR, "%s called in non-aggregate context", __func__);
 
-	mvt_agg_context *ctx, *ctx1, *ctx2;
 	ctx1 = (mvt_agg_context*)PG_GETARG_POINTER(0);
 	ctx2 = (mvt_agg_context*)PG_GETARG_POINTER(1);
 	oldcontext = MemoryContextSwitchTo(aggcontext);

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2018-04-17 09:07:21 UTC (rev 16545)
+++ trunk/postgis/mvt.c	2018-04-17 10:05:54 UTC (rev 16546)
@@ -110,6 +110,7 @@
 	uint32_t offset = 0;
 	uint32_t i, c = 0;
 	int32_t dx, dy, x, y;
+	const POINT2D *p;
 
 	/* loop points and add to buffer */
 	for (i = 0; i < pa->npoints; i++) {
@@ -119,7 +120,7 @@
 		/* skip closing point for rings */
 		if (type == MVT_RING && i == pa->npoints - 1)
 			break;
-		const POINT2D *p = getPoint2d_cp(pa, i);
+		p = getPoint2d_cp(pa, i);
 		x = p->x;
 		y = p->y;
 		dx = x - *px;
@@ -366,21 +367,25 @@
 #define MVT_CREATE_VALUES(kvtype, hash, hasfield, valuefield) \
 { \
 	POSTGIS_DEBUG(2, "MVT_CREATE_VALUES called"); \
-	struct kvtype *kv; \
-	for (kv = ctx->hash; kv != NULL; kv=kv->hh.next) { \
-		VectorTile__Tile__Value *value = create_value(); \
-		value->hasfield = 1; \
-		value->valuefield = kv->valuefield; \
-		values[kv->id] = value; \
+	{ \
+		struct kvtype *kv; \
+		for (kv = ctx->hash; kv != NULL; kv=kv->hh.next) { \
+			VectorTile__Tile__Value *value = create_value(); \
+			value->hasfield = 1; \
+			value->valuefield = kv->valuefield; \
+			values[kv->id] = value; \
+		} \
 	} \
 }
 
 static void encode_values(mvt_agg_context *ctx)
 {
+	VectorTile__Tile__Value **values;
+	struct mvt_kv_string_value *kv;
+
 	POSTGIS_DEBUG(2, "encode_values called");
-	VectorTile__Tile__Value **values;
+
 	values = palloc(ctx->values_hash_i * sizeof(*values));
-	struct mvt_kv_string_value *kv;
 	for (kv = ctx->string_values_hash; kv != NULL; kv=kv->hh.next) {
 		VectorTile__Tile__Value *value = create_value();
 		value->string_value = kv->string_value;
@@ -412,19 +417,21 @@
 #define MVT_PARSE_VALUE(value, kvtype, hash, valuefield, size) \
 { \
 	POSTGIS_DEBUG(2, "MVT_PARSE_VALUE called"); \
-	struct kvtype *kv; \
-	HASH_FIND(hh, ctx->hash, &value, size, kv); \
-	if (!kv) { \
-		POSTGIS_DEBUG(4, "MVT_PARSE_VALUE value not found"); \
-		kv = palloc(sizeof(*kv)); \
-		POSTGIS_DEBUGF(4, "MVT_PARSE_VALUE new hash key: %d", \
-			ctx->values_hash_i); \
-		kv->id = ctx->values_hash_i++; \
-		kv->valuefield = value; \
-		HASH_ADD(hh, ctx->hash, valuefield, size, kv); \
+	{ \
+		struct kvtype *kv; \
+		HASH_FIND(hh, ctx->hash, &value, size, kv); \
+		if (!kv) { \
+			POSTGIS_DEBUG(4, "MVT_PARSE_VALUE value not found"); \
+			kv = palloc(sizeof(*kv)); \
+			POSTGIS_DEBUGF(4, "MVT_PARSE_VALUE new hash key: %d", \
+				ctx->values_hash_i); \
+			kv->id = ctx->values_hash_i++; \
+			kv->valuefield = value; \
+			HASH_ADD(hh, ctx->hash, valuefield, size, kv); \
+		} \
+		tags[ctx->c*2] = k; \
+		tags[ctx->c*2+1] = kv->id; \
 	} \
-	tags[ctx->c*2] = k; \
-	tags[ctx->c*2+1] = kv->id; \
 }
 
 #define MVT_PARSE_INT_VALUE(value) \
@@ -534,10 +541,12 @@
 				ctx->c++;
 			} else if (v.type == jbvNumeric) {
 				char *str;
+				double d;
+				long l;
 				str = DatumGetCString(DirectFunctionCall1(numeric_out,
 					PointerGetDatum(v.val.numeric)));
-				double d = strtod(str, NULL);
-				long l = strtol(str, NULL, 10);
+				d = strtod(str, NULL);
+				l = strtol(str, NULL, 10);
 				if ((long) d != l) {
 					MVT_PARSE_VALUE(d, mvt_kv_double_value, double_values_hash,
 						double_value, sizeof(double));
@@ -555,7 +564,6 @@
 
 static void parse_values(mvt_agg_context *ctx)
 {
-	POSTGIS_DEBUG(2, "parse_values called");
 	uint32_t n_keys = ctx->keys_hash_i;
 	uint32_t *tags = palloc(n_keys * 2 * sizeof(*tags));
 	bool isnull;
@@ -563,6 +571,7 @@
 	TupleDesc tupdesc = get_tuple_desc(ctx);
 	uint32_t natts = (uint32_t) tupdesc->natts;
 	ctx->c = 0;
+	POSTGIS_DEBUG(2, "parse_values called");
 
 	POSTGIS_DEBUGF(3, "parse_values natts: %d", natts);
 
@@ -655,6 +664,7 @@
 		/* by finding the largest basic type available and */
 		/* using that as the basis of a typed collection. */
 		LWCOLLECTION *g = (LWCOLLECTION*)geom;
+		LWCOLLECTION *gc;
 		uint32_t i, maxtype = 0;
 		for (i = 0; i < g->ngeoms; i++)
 		{
@@ -665,7 +675,7 @@
 		if (maxtype > 3) maxtype -= 3;
 		/* Force the working geometry to be a simpler version */
 		/* of itself */
-		LWCOLLECTION *gc = lwcollection_extract(g, maxtype);
+		gc = lwcollection_extract(g, maxtype);
 		*g = *gc;
 	}
 	return;
@@ -715,8 +725,9 @@
 
 	if (clip_geom)
 	{
+		GBOX bgbox;
 		const GBOX *lwgeom_gbox = lwgeom_get_bbox(lwgeom);;
-		GBOX bgbox = *gbox;
+		bgbox = *gbox;
 		gbox_expand(&bgbox, buffer_map_xunits);
 		if (!gbox_overlaps_2d(lwgeom_gbox, &bgbox))
 		{
@@ -875,11 +886,12 @@
 
 static VectorTile__Tile * mvt_ctx_to_tile(mvt_agg_context *ctx)
 {
+	int n_layers = 1;
+	VectorTile__Tile *tile;
 	encode_keys(ctx);
 	encode_values(ctx);
 
-	int n_layers = 1;
-	VectorTile__Tile *tile = palloc(sizeof(VectorTile__Tile));
+	tile = palloc(sizeof(VectorTile__Tile));
 	vector_tile__tile__init(tile);
 	tile->layers = palloc(sizeof(VectorTile__Tile__Layer*) * n_layers);
 	tile->layers[0] = ctx->layer;
@@ -893,6 +905,8 @@
 	/* We should only have a filled slow when all the work of building */
 	/* out the data is complete, so after a serialize/deserialize cycle */
 	/* or after a context combine */
+	size_t len;
+	bytea *ba;
 
 	if (!ctx->tile)
 	{
@@ -908,8 +922,8 @@
 	}
 
 	/* Serialize the Tile */
-	size_t len = VARHDRSZ + vector_tile__tile__get_packed_size(ctx->tile);
-	bytea *ba = palloc(len);
+	len = VARHDRSZ + vector_tile__tile__get_packed_size(ctx->tile);
+	ba = palloc(len);
 	vector_tile__tile__pack(ctx->tile, (uint8_t*)VARDATA(ba));
 	SET_VARSIZE(ba, len);
 	return ba;
@@ -961,12 +975,13 @@
 tile_feature_copy(const VectorTile__Tile__Feature *feature, int key_offset, int value_offset)
 {
 	uint32_t i;
+	VectorTile__Tile__Feature *nfeature;
 
 	/* Null in => Null out */
 	if (!feature) return NULL;
 
 	/* Init object */
-	VectorTile__Tile__Feature *nfeature = palloc(sizeof(VectorTile__Tile__Feature));
+	nfeature = palloc(sizeof(VectorTile__Tile__Feature));
 	vector_tile__tile__feature__init(nfeature);
 
 	/* Copy settings straight over */
@@ -1054,6 +1069,7 @@
 vectortile_tile_combine(VectorTile__Tile *tile1, VectorTile__Tile *tile2)
 {
 	uint32_t i, j;
+	VectorTile__Tile *tile;
 
 	/* Hopelessly messing up memory ownership here */
 	if (tile1->n_layers == 0 && tile2->n_layers == 0)
@@ -1063,7 +1079,7 @@
 	else if (tile2->n_layers == 0)
 		return tile1;
 
-	VectorTile__Tile *tile = palloc(sizeof(VectorTile__Tile));
+	tile = palloc(sizeof(VectorTile__Tile));
 	vector_tile__tile__init(tile);
 	tile->layers = palloc(sizeof(void*));
 	tile->n_layers = 0;



More information about the postgis-tickets mailing list