]> granicus.if.org Git - postgis/commitdiff
Restore debug log and improve memory context/allocations
authorBjörn Harrtell <bjorn@wololo.org>
Tue, 25 Apr 2017 21:10:58 +0000 (21:10 +0000)
committerBjörn Harrtell <bjorn@wololo.org>
Tue, 25 Apr 2017 21:10:58 +0000 (21:10 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@15370 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_out_geobuf.c
postgis/lwgeom_out_mvt.c
postgis/mvt.c
postgis/uthash.h

index 30aaf5ee757dd36f86f525f279eb7a9ca3ab77e8..5d1cdcba170dd8f1ecda16a727259f8a7f4e52c4 100644 (file)
@@ -49,12 +49,11 @@ Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS)
        lwerror("Missing libprotobuf-c");
        PG_RETURN_NULL();
 #else
-       MemoryContext aggcontext;
+       MemoryContext aggcontext, oldcxt = NULL;
        struct geobuf_agg_context *ctx;
 
        if (!AggCheckCallContext(fcinfo, &aggcontext))
-               lwerror("pgis_asmvt_transfn: called in non-aggregate context");
-       MemoryContextSwitchTo(aggcontext);
+               aggcontext = CurrentMemoryContext;
 
        if (PG_ARGISNULL(0)) {
                ctx = palloc(sizeof(*ctx));
@@ -63,6 +62,7 @@ Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS)
                ctx->geom_name = text_to_cstring(PG_GETARG_TEXT_P(1));
                geobuf_agg_init_context(ctx);
        } else {
+               oldcxt = MemoryContextSwitchTo(aggcontext);
                ctx = (struct geobuf_agg_context *) PG_GETARG_POINTER(0);
        }
 
@@ -71,6 +71,10 @@ Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS)
        ctx->row = PG_GETARG_HEAPTUPLEHEADER(2);
 
        geobuf_agg_transfn(ctx);
+
+       if (oldcxt)
+               MemoryContextSwitchTo(oldcxt);
+
        PG_RETURN_POINTER(ctx);
 #endif
 }
index b797773c83f466f3e02bbeda480b02be94585a61..562fe424e0fe0b4d6c3f4b2157ce78355580deb8 100644 (file)
@@ -79,12 +79,11 @@ Datum pgis_asmvt_transfn(PG_FUNCTION_ARGS)
        lwerror("Missing libprotobuf-c");
        PG_RETURN_NULL();
 #else
-       MemoryContext aggcontext;
+       MemoryContext aggcontext, oldcxt = NULL;
        struct mvt_agg_context *ctx;
 
        if (!AggCheckCallContext(fcinfo, &aggcontext))
-               lwerror("pgis_asmvt_transfn: called in non-aggregate context");
-       MemoryContextSwitchTo(aggcontext);
+               aggcontext = CurrentMemoryContext;
 
        if (PG_ARGISNULL(0)) {
                ctx = palloc(sizeof(*ctx));
@@ -101,6 +100,7 @@ Datum pgis_asmvt_transfn(PG_FUNCTION_ARGS)
                PG_FREE_IF_COPY(geom_name, 3);
                mvt_agg_init_context(ctx);
        } else {
+               oldcxt = MemoryContextSwitchTo(aggcontext);
                ctx = (struct mvt_agg_context *) PG_GETARG_POINTER(0);
        }
 
@@ -109,7 +109,11 @@ Datum pgis_asmvt_transfn(PG_FUNCTION_ARGS)
        ctx->row = PG_GETARG_HEAPTUPLEHEADER(4);
 
        mvt_agg_transfn(ctx);
+
        PG_FREE_IF_COPY(ctx->row, 4);
+       if (oldcxt)
+               MemoryContextSwitchTo(oldcxt);
+
        PG_RETURN_POINTER(ctx);
 #endif
 }
index f4780ca8ef585e318f471029dcd277aac20ce103..d956e1d9b6551cbabcc76f231c55a24e009b606f 100644 (file)
@@ -619,8 +619,7 @@ void mvt_agg_transfn(struct mvt_agg_context *ctx)
        GSERIALIZED *gs = (GSERIALIZED *) PG_DETOAST_DATUM(datum);
        LWGEOM *lwgeom = lwgeom_from_gserialized(gs);
 
-       // TODO: find out why a POSTGIS_DEBUGF affects encoding/uthash (memory issue?)
-       //POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %d", layer->n_features);
+       POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %d", layer->n_features);
        layer->features[layer->n_features++] = feature;
 
        encode_geometry(ctx, lwgeom);
index 57df956c57528a8c79d58403bfba39fba27a5658..5758e9fe7ab664911185d99cbdf3e7c38bfeb8e0 100644 (file)
@@ -80,13 +80,13 @@ typedef unsigned char uint8_t;
 #endif
 
 #ifndef uthash_fatal
-#define uthash_fatal(msg) exit(-1)        /* fatal error (out of memory,etc) */
+#define uthash_fatal(msg) lwerror("uthash: fatal error (out of memory,etc)")
 #endif
 #ifndef uthash_malloc
-#define uthash_malloc(sz) malloc(sz)      /* malloc fcn                      */
+#define uthash_malloc(sz) palloc(sz)      /* malloc fcn                      */
 #endif
 #ifndef uthash_free
-#define uthash_free(ptr,sz) free(ptr)     /* free fcn                        */
+#define uthash_free(ptr,sz) pfree(ptr)     /* free fcn                        */
 #endif
 #ifndef uthash_strlen
 #define uthash_strlen(s) strlen(s)