From d6d58efee5fc330024dd404b541534d2f0684e25 Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Mon, 29 Oct 2007 16:29:58 +0000 Subject: [PATCH] Apply parts of Charlie Savage's MSVC patch - mainly tidying up variable allocations so they appear at the start of functions, but also making better use of the pj_get_errno_ref() which gets rid of the auto-import warnings on MingW. git-svn-id: http://svn.osgeo.org/postgis/trunk@2715 b70326c6-7e19-0410-871a-916f4a2858ee --- loader/pgsql2shp.c | 5 ++-- lwgeom/lwcurve.c | 7 +++--- lwgeom/lwgeom_dump.c | 3 ++- lwgeom/lwgeom_rtree.c | 8 ++++--- lwgeom/lwgeom_transform.c | 50 ++++++++++++++++++++++++++------------- 5 files changed, 47 insertions(+), 26 deletions(-) diff --git a/loader/pgsql2shp.c b/loader/pgsql2shp.c index e49576b82..296e6f496 100644 --- a/loader/pgsql2shp.c +++ b/loader/pgsql2shp.c @@ -2333,12 +2333,13 @@ usage(char* me, int status, FILE* out) int parse_commandline(int ARGC, char **ARGV) { + int c, curindex; + char buf[1024]; + if ( ARGC == 1 ) { usage(ARGV[0], 0, stdout); } - int c, curindex; - char buf[1024]; buf[1023] = '\0'; /* just in case... */ diff --git a/lwgeom/lwcurve.c b/lwgeom/lwcurve.c index 2572835c0..db2d748c5 100644 --- a/lwgeom/lwcurve.c +++ b/lwgeom/lwcurve.c @@ -22,7 +22,7 @@ /*#define PGIS_DEBUG 1 */ #ifndef MAXFLOAT - #define MAXFLOAT 3.40282347e+38F + #define MAXFLOAT 3.402823466e+38F #endif /* @@ -32,7 +32,9 @@ LWCURVE * lwcurve_construct(int SRID, BOX2DFLOAT4 *bbox, POINTARRAY *points) { - /* + LWCURVE *result; + + /* * The first arc requires three points. Each additional * arc requires two more points. Thus the minimum point count * is three, and the count must be odd. @@ -43,7 +45,6 @@ lwcurve_construct(int SRID, BOX2DFLOAT4 *bbox, POINTARRAY *points) return NULL; } - LWCURVE *result; result = (LWCURVE*) lwalloc(sizeof(LWCURVE)); result->type = lwgeom_makeType_full( diff --git a/lwgeom/lwgeom_dump.c b/lwgeom/lwgeom_dump.c index e64c21310..b4a0d673d 100644 --- a/lwgeom/lwgeom_dump.c +++ b/lwgeom/lwgeom_dump.c @@ -272,6 +272,7 @@ Datum LWGEOM_dump_rings(PG_FUNCTION_ARGS) { LWPOLY* poly = state->poly; POINTARRAY *ring; + LWGEOM* ringgeom; /* Switch to an appropriate memory context for POINTARRAY * cloning and hexwkb allocation */ @@ -281,7 +282,7 @@ Datum LWGEOM_dump_rings(PG_FUNCTION_ARGS) ring = ptarray_clone(poly->rings[state->ringnum]); /* Construct another polygon with shell only */ - LWGEOM* ringgeom = (LWGEOM*)lwpoly_construct( + ringgeom = (LWGEOM*)lwpoly_construct( poly->SRID, NULL, /* TODO: could use input bounding box here */ 1, /* one ring */ diff --git a/lwgeom/lwgeom_rtree.c b/lwgeom/lwgeom_rtree.c index 3372de5ad..2bf3b0e8c 100644 --- a/lwgeom/lwgeom_rtree.c +++ b/lwgeom/lwgeom_rtree.c @@ -21,8 +21,8 @@ RTREE_NODE *createTree(POINTARRAY *pointArray) { RTREE_NODE *root; - RTREE_NODE *nodes[pointArray->npoints]; - int i, nodeCount; + RTREE_NODE** nodes = lwalloc(sizeof(RTREE_NODE*) * pointArray->npoints); + int i, nodeCount; int childNodes, parentNodes; #ifdef PGIS_DEBUG_CALLS @@ -378,7 +378,9 @@ Datum LWGEOM_polygon_index(PG_FUNCTION_ARGS) #ifdef PGIS_DEBUG lwnotice("returning result %p", result); #endif - PG_FREE_IF_COPY(igeom, 0); + lwfree(root); + + PG_FREE_IF_COPY(igeom, 0); lwgeom_release((LWGEOM *)poly); lwgeom_release((LWGEOM *)mline); PG_RETURN_POINTER(result); diff --git a/lwgeom/lwgeom_transform.c b/lwgeom/lwgeom_transform.c index 34de0a4dd..c1d435df3 100644 --- a/lwgeom/lwgeom_transform.c +++ b/lwgeom/lwgeom_transform.c @@ -427,6 +427,7 @@ AddToPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid, int other_srid) PJ *projection = NULL; char *proj_str; char proj4_spi_buffer[256]; + int* pj_errno_ref; /* Connect */ spi_result = SPI_connect(); @@ -452,11 +453,12 @@ AddToPROJ4SRSCache(PROJ4PortalCache *PROJ4Cache, int srid, int other_srid) strcpy(proj_str, SPI_getvalue(tuple, tupdesc, 1)); projection = make_project(proj_str); - if ( (projection == NULL) || pj_errno) + pj_errno_ref = pj_get_errno_ref(); + if ( (projection == NULL) || (*pj_errno_ref)) { /* we need this for error reporting */ /*pfree(projection); */ - elog(ERROR, "AddToPROJ4SRSCache: couldn't parse proj4 string: '%s': %s", proj_str, pj_strerrno(pj_errno)); + elog(ERROR, "AddToPROJ4SRSCache: couldn't parse proj4 string: '%s': %s", proj_str, pj_strerrno(*pj_errno_ref)); } /* @@ -571,7 +573,7 @@ int point_offset, double *x, double *y, double *z ) long i; /*int need_datum_shift; */ - pj_errno = 0; + int* pj_errno_ref; if( point_offset == 0 ) point_offset = 1; @@ -587,8 +589,10 @@ int point_offset, double *x, double *y, double *z ) projected_loc.v = y[point_offset*i]; geodetic_loc = pj_inv( projected_loc, srcdefn ); - if( pj_errno != 0 ) - return pj_errno; + + pj_errno_ref = pj_get_errno_ref(); + if( (*pj_errno_ref) != 0 ) + return *pj_errno_ref; x[point_offset*i] = geodetic_loc.u; y[point_offset*i] = geodetic_loc.v; @@ -606,8 +610,10 @@ int point_offset, double *x, double *y, double *z ) geodetic_loc.v = y[point_offset*i]; projected_loc = pj_fwd( geodetic_loc, dstdefn ); - if( pj_errno != 0 ) - return pj_errno; + + pj_errno_ref = pj_get_errno_ref(); + if( (*pj_errno_ref) != 0 ) + return *pj_errno_ref; x[point_offset*i] = projected_loc.u; y[point_offset*i] = projected_loc.v; @@ -910,6 +916,7 @@ Datum transform_geom(PG_FUNCTION_ARGS) text *output_proj4_text; int32 result_srid ; uchar *srl; + int* pj_errno_ref; result_srid = PG_GETARG_INT32(3); if (result_srid == -1) @@ -941,26 +948,30 @@ Datum transform_geom(PG_FUNCTION_ARGS) /* make input and output projection objects */ input_pj = make_project(input_proj4); - if ( (input_pj == NULL) || pj_errno) + + pj_errno_ref = pj_get_errno_ref(); + if ( (input_pj == NULL) || (*pj_errno_ref)) { /* we need this for error reporting */ /* pfree(input_proj4); */ pfree(output_proj4); pfree(geom); - elog(ERROR, "transform: couldn't parse proj4 input string: '%s': %s", input_proj4, pj_strerrno(pj_errno)); + elog(ERROR, "transform: couldn't parse proj4 input string: '%s': %s", input_proj4, pj_strerrno(*pj_errno_ref)); PG_RETURN_NULL(); } pfree(input_proj4); output_pj = make_project(output_proj4); - if ((output_pj == NULL)|| pj_errno) + + pj_errno_ref = pj_get_errno_ref(); + if ((output_pj == NULL)|| (*pj_errno_ref)) { /* we need this for error reporting */ /* pfree(output_proj4); */ pj_free(input_pj); pfree(geom); - elog(ERROR, "transform: couldn't parse proj4 output string: '%s': %s", output_proj4, pj_strerrno(pj_errno)); + elog(ERROR, "transform: couldn't parse proj4 output string: '%s': %s", output_proj4, pj_strerrno(*pj_errno_ref)); PG_RETURN_NULL(); } pfree(output_proj4); @@ -999,7 +1010,7 @@ Datum transform_geom(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(postgis_proj_version); Datum postgis_proj_version(PG_FUNCTION_ARGS) { - const char *ver = pj_release; + const char *ver = pj_get_release(); text *result; result = (text *) palloc(VARHDRSZ + strlen(ver)); SET_VARSIZE(result, VARHDRSZ + strlen(ver)); @@ -1011,23 +1022,28 @@ Datum postgis_proj_version(PG_FUNCTION_ARGS) int transform_point(POINT4D *pt, PJ *srcpj, PJ *dstpj) { + int* pj_errno_ref; + if (srcpj->is_latlong) to_rad(pt); pj_transform(srcpj, dstpj, 1, 2, &(pt->x), &(pt->y), &(pt->z)); - if (pj_errno) + + pj_errno_ref = pj_get_errno_ref(); + if (*pj_errno_ref) { - if (pj_errno == -38) /*2nd chance */ + if ((*pj_errno_ref) == -38) /*2nd chance */ { elog(WARNING, "transform: %i (%s)", - pj_errno, pj_strerrno(pj_errno)); + *pj_errno_ref, pj_strerrno(*pj_errno_ref)); /*couldnt do nadshift - do it without the datum */ pj_transform_nodatum(srcpj, dstpj, 1, 2, &(pt->x), &(pt->y), NULL); } - if (pj_errno) + pj_errno_ref = pj_get_errno_ref(); + if ((*pj_errno_ref)) { elog(ERROR,"transform: couldn't project point: %i (%s)", - pj_errno, pj_strerrno(pj_errno)); + *pj_errno_ref, pj_strerrno(*pj_errno_ref)); return 0; } } -- 2.49.0