From 70c8b42d6c3e6cbce806c9e72b8d9a09546cee32 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ra=C3=BAl=20Mar=C3=ADn=20Rodr=C3=ADguez?= Date: Tue, 17 Apr 2018 10:05:54 +0000 Subject: [PATCH] Fix dronie build References #4060 git-svn-id: http://svn.osgeo.org/postgis/trunk@16546 b70326c6-7e19-0410-871a-916f4a2858ee --- libpgcommon/lwgeom_transform.c | 11 ++--- postgis/geobuf.c | 12 ++--- postgis/lwgeom_out_mvt.c | 5 ++- postgis/mvt.c | 80 ++++++++++++++++++++-------------- 4 files changed, 64 insertions(+), 44 deletions(-) diff --git a/libpgcommon/lwgeom_transform.c b/libpgcommon/lwgeom_transform.c index 0d73c3d92..f308d3ed7 100644 --- a/libpgcommon/lwgeom_transform.c +++ b/libpgcommon/lwgeom_transform.c @@ -504,7 +504,6 @@ static void AddToPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid, int other_srid) { MemoryContext PJMemoryContext; - MemoryContextCallback *callback; projPJ projection = NULL; char *proj_str = NULL; @@ -573,10 +572,12 @@ 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 */ - 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 */ diff --git a/postgis/geobuf.c b/postgis/geobuf.c index 1aebe65ae..8c729f1bc 100644 --- a/postgis/geobuf.c +++ b/postgis/geobuf.c @@ -114,6 +114,7 @@ static void encode_properties(struct geobuf_agg_context *ctx, char *type, *string_value; Datum datum; bool isnull; + Oid typoid; if (i == ctx->geom_index) continue; @@ -127,9 +128,9 @@ static void encode_properties(struct geobuf_agg_context *ctx, 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 @@ void geobuf_agg_transfn(struct geobuf_agg_context *ctx) */ 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 @@ uint8_t *geobuf_agg_finalfn(struct geobuf_agg_context *ctx) 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); diff --git a/postgis/lwgeom_out_mvt.c b/postgis/lwgeom_out_mvt.c index be66559e5..601237056 100644 --- a/postgis/lwgeom_out_mvt.c +++ b/postgis/lwgeom_out_mvt.c @@ -177,12 +177,13 @@ Datum pgis_asmvt_deserialfn(PG_FUNCTION_ARGS) 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 @@ Datum pgis_asmvt_combinefn(PG_FUNCTION_ARGS) 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); diff --git a/postgis/mvt.c b/postgis/mvt.c index 53d4e9bba..5a4b150ce 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -110,6 +110,7 @@ static uint32_t encode_ptarray(__attribute__((__unused__)) mvt_agg_context *ctx, 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 @@ static uint32_t encode_ptarray(__attribute__((__unused__)) mvt_agg_context *ctx, /* 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 @@ static VectorTile__Tile__Value *create_value() #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) { - POSTGIS_DEBUG(2, "encode_values called"); VectorTile__Tile__Value **values; - values = palloc(ctx->values_hash_i * sizeof(*values)); struct mvt_kv_string_value *kv; + + POSTGIS_DEBUG(2, "encode_values called"); + + values = palloc(ctx->values_hash_i * sizeof(*values)); 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 @@ static void encode_values(mvt_agg_context *ctx) #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 @@ static uint32_t *parse_jsonb(mvt_agg_context *ctx, Jsonb *jb, 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 uint32_t *parse_jsonb(mvt_agg_context *ctx, Jsonb *jb, 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 @@ static void parse_values(mvt_agg_context *ctx) 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 @@ lwgeom_to_basic_type(LWGEOM *geom) /* 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 @@ lwgeom_to_basic_type(LWGEOM *geom) 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 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buf 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 @@ void mvt_agg_transfn(mvt_agg_context *ctx) 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 @@ static bytea *mvt_ctx_to_bytea(mvt_agg_context *ctx) /* 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 @@ static bytea *mvt_ctx_to_bytea(mvt_agg_context *ctx) } /* 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 @@ static VectorTile__Tile__Feature * 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 @@ static VectorTile__Tile * 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 @@ vectortile_tile_combine(VectorTile__Tile *tile1, VectorTile__Tile *tile2) 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; -- 2.40.0