[postgis-commits] svn - r2715 - in trunk: loader lwgeom

postgis-commits at postgis.refractions.net postgis-commits at postgis.refractions.net
Mon Oct 29 09:30:00 PDT 2007


Author: mcayland
Date: 2007-10-29 09:29:58 -0700 (Mon, 29 Oct 2007)
New Revision: 2715

Modified:
   trunk/loader/pgsql2shp.c
   trunk/lwgeom/lwcurve.c
   trunk/lwgeom/lwgeom_dump.c
   trunk/lwgeom/lwgeom_rtree.c
   trunk/lwgeom/lwgeom_transform.c
Log:
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.

Modified: trunk/loader/pgsql2shp.c
===================================================================
--- trunk/loader/pgsql2shp.c	2007-10-29 14:22:26 UTC (rev 2714)
+++ trunk/loader/pgsql2shp.c	2007-10-29 16:29:58 UTC (rev 2715)
@@ -2333,12 +2333,13 @@
 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... */
 

Modified: trunk/lwgeom/lwcurve.c
===================================================================
--- trunk/lwgeom/lwcurve.c	2007-10-29 14:22:26 UTC (rev 2714)
+++ trunk/lwgeom/lwcurve.c	2007-10-29 16:29:58 UTC (rev 2715)
@@ -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 @@
                 return NULL;
         }
         
-        LWCURVE *result;
         result = (LWCURVE*) lwalloc(sizeof(LWCURVE));
 
         result->type = lwgeom_makeType_full(

Modified: trunk/lwgeom/lwgeom_dump.c
===================================================================
--- trunk/lwgeom/lwgeom_dump.c	2007-10-29 14:22:26 UTC (rev 2714)
+++ trunk/lwgeom/lwgeom_dump.c	2007-10-29 16:29:58 UTC (rev 2715)
@@ -272,6 +272,7 @@
 	{
 		LWPOLY* poly = state->poly;
 		POINTARRAY *ring;
+		LWGEOM* ringgeom;
 
 		/* Switch to an appropriate memory context for POINTARRAY
 		 * cloning and hexwkb allocation */
@@ -281,7 +282,7 @@
 		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 */

Modified: trunk/lwgeom/lwgeom_rtree.c
===================================================================
--- trunk/lwgeom/lwgeom_rtree.c	2007-10-29 14:22:26 UTC (rev 2714)
+++ trunk/lwgeom/lwgeom_rtree.c	2007-10-29 16:29:58 UTC (rev 2715)
@@ -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 @@
 #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);

Modified: trunk/lwgeom/lwgeom_transform.c
===================================================================
--- trunk/lwgeom/lwgeom_transform.c	2007-10-29 14:22:26 UTC (rev 2714)
+++ trunk/lwgeom/lwgeom_transform.c	2007-10-29 16:29:58 UTC (rev 2715)
@@ -427,6 +427,7 @@
 	PJ *projection = NULL;
 	char *proj_str;
 	char proj4_spi_buffer[256];
+	int* pj_errno_ref;
 
 	/* Connect */
 	spi_result = SPI_connect();
@@ -452,11 +453,12 @@
 		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 @@
     long      i;
     /*int       need_datum_shift; */
 
-    pj_errno = 0;
+    int* pj_errno_ref;
 
     if( point_offset == 0 )
         point_offset = 1;
@@ -587,8 +589,10 @@
             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,9 +610,11 @@
             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 @@
 	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 @@
 
 	/* 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 @@
 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 @@
 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;
 		}
 	}



More information about the postgis-commits mailing list