[postgis-users] MSVC Patch #1

Charlie Savage cfis at savagexi.com
Tue Aug 28 22:22:21 PDT 2007


I've divided up the MSVC++ patch into two parts.  This is the 
interesting part - it includes the change needed to the current PostGis 
code base plus the addition of a file config.h.vc.

The most debatable part of the patch are changes to lex.yy.c since I'm 
sure its autogenerated.  The problem is that it includes a reference too 
  unistd.h.  Taking out for MSVC++ doesn't seem to break anything - 
suppose we could just stub out that file for MSVC++.

The second patch is much bigger and much less interesting - thus I 
haven't included it.  It contains the MSVC++ project files and the extra 
files required that don't exist on Windows (inttypes.h, stdint.h, and a 
rint implementation).

------------------------------

Only in .: build
Only in .: config.h
Only in .: config.h.vc
Only in ./java/ejb2: lib
diff -u -r /c/temp/postgis-1.3.1/loader/pgsql2shp.c ./loader/pgsql2shp.c
--- /c/temp/postgis-1.3.1/loader/pgsql2shp.c	2007-08-28 21:25:32 -0600
+++ ./loader/pgsql2shp.c	2007-08-28 22:04:23 -0600
@@ -34,8 +34,18 @@
  #include "shapefil.h"
  #include "getopt.h"
  #include "compat.h"
+#include "../config.h"
+
+#ifdef _MSC_VER
+#include <process.h> // for getpid()
+#include <windows.h> // for lstrcmpi
+#define snprintf _snprintf
+#define strcasecmp lstrcmpi
+#define strncasecmp strnicmp
+#else
  #include <sys/types.h> // for getpid()
  #include <unistd.h> // for getpid()
+#endif

  #ifdef __CYGWIN__
  #include <sys/param.h>
@@ -2333,12 +2343,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... */

Only in ./loader: pgsql2shp.exe
diff -u -r /c/temp/postgis-1.3.1/loader/shp2pgsql.c ./loader/shp2pgsql.c
--- /c/temp/postgis-1.3.1/loader/shp2pgsql.c	2007-08-28 21:25:32 -0600
+++ ./loader/shp2pgsql.c	2007-08-28 21:24:59 -0600
@@ -30,7 +30,11 @@
  #include <ctype.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#else
  #include <unistd.h>
+#endif
  #include <errno.h>
  #include "getopt.h"
  #ifdef HAVE_ICONV_H
Only in ./loader: shp2pgsql.exe
diff -u -r /c/temp/postgis-1.3.1/lwgeom/lex.yy.c ./lwgeom/lex.yy.c
--- /c/temp/postgis-1.3.1/lwgeom/lex.yy.c	2007-08-28 21:25:32 -0600
+++ ./lwgeom/lex.yy.c	2007-08-28 22:18:09 -0600
@@ -28,7 +28,9 @@
  #define YY_FLEX_MINOR_VERSION 5

  #include <stdio.h>
+#ifndef _MSC_VER
  #include <unistd.h>
+#endif


  /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
@@ -3264,7 +3266,9 @@

  #line 11 "wktparse.lex"
  #include "wktparse.tab.h"
+#ifndef _MSC_VER
  #include <unistd.h>
+#endif
  #include <stdlib.h> // need stdlib for atof() definition

  void init_parser(const char *src);
Only in ./lwgeom: liblwgeom.a
Only in ./lwgeom: liblwgeom.dll
diff -u -r /c/temp/postgis-1.3.1/lwgeom/liblwgeom.h ./lwgeom/liblwgeom.h
--- /c/temp/postgis-1.3.1/lwgeom/liblwgeom.h	2007-08-28 21:25:36 -0600
+++ ./lwgeom/liblwgeom.h	2007-08-28 21:24:56 -0600
@@ -3,6 +3,7 @@

  #include <stdio.h>
  #include "compat.h"
+#include "../config.h"

  #define INTEGRITY_CHECKS 1
  /* #define DEBUG_ALLOCS 1 */
diff -u -r /c/temp/postgis-1.3.1/lwgeom/lwcurve.c ./lwgeom/lwcurve.c
--- /c/temp/postgis-1.3.1/lwgeom/lwcurve.c	2007-08-28 21:25:32 -0600
+++ ./lwgeom/lwcurve.c	2007-08-28 21:24:59 -0600
@@ -22,7 +22,7 @@
  /*#define PGIS_DEBUG 1 */

  #ifndef MAXFLOAT
-  #define MAXFLOAT      3.40282347e+38F
+  #define MAXFLOAT      3.402823466e+38F
  #endif

  /*
@@ -32,6 +32,8 @@
  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
@@ -43,7 +45,6 @@
                  return NULL;
          }

-        LWCURVE *result;
          result = (LWCURVE*) lwalloc(sizeof(LWCURVE));

          result->type = lwgeom_makeType_full(
Only in ./lwgeom: lwgeom.def
diff -u -r /c/temp/postgis-1.3.1/lwgeom/lwgeom_dump.c ./lwgeom/lwgeom_dump.c
--- /c/temp/postgis-1.3.1/lwgeom/lwgeom_dump.c	2007-08-28 21:25:32 -0600
+++ ./lwgeom/lwgeom_dump.c	2007-08-28 21:24:59 -0600
@@ -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 */
diff -u -r /c/temp/postgis-1.3.1/lwgeom/lwgeom_rtree.c 
./lwgeom/lwgeom_rtree.c
--- /c/temp/postgis-1.3.1/lwgeom/lwgeom_rtree.c	2007-08-28 21:25:32 -0600
+++ ./lwgeom/lwgeom_rtree.c	2007-08-28 21:24:59 -0600
@@ -21,7 +21,8 @@
  RTREE_NODE *createTree(POINTARRAY *pointArray)
  {
          RTREE_NODE *root;
-        RTREE_NODE *nodes[pointArray->npoints];
+        RTREE_NODE** nodes = palloc(sizeof(RTREE_NODE*) * 
pointArray->npoints);
+
          int i, nodeCount;
          int childNodes, parentNodes;

@@ -81,6 +82,7 @@
  #ifdef PGIS_DEBUG
          lwnotice("createTree returning %p", root);
  #endif
+        free(nodes);
          return root;
  }

diff -u -r /c/temp/postgis-1.3.1/lwgeom/lwgeom_transform.c 
./lwgeom/lwgeom_transform.c
--- /c/temp/postgis-1.3.1/lwgeom/lwgeom_transform.c	2007-08-28 21:25:32 
-0600
+++ ./lwgeom/lwgeom_transform.c	2007-08-28 21:24:59 -0600
@@ -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,8 +610,10 @@
              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;
  		}
  	}
Only in .: lwpostgis.sql
Only in .: msvc.patch
Only in .: msvc_new.patch
Only in ./regress: lwpostgis.sql
--- /c/temp/postgis-1.3.1/config.h.vc	1969-12-31 17:00:00 -0700
+++ ./config.h.vc	2007-08-28 16:27:19 -0600
@@ -0,0 +1,9 @@
+#define POSTGIS_VERSION "1.3.1"
+#define REL_MAJOR_VERSION "1"
+#define REL_MINOR_VERSION "3"
+#define REL_MICRO_VERSION "1"
+#define POSTGIS_LIB_VERSION POSTGIS_VERSION
+#define POSTGIS_BUILD_DATE "2007-08-23"
+#define POSTGIS_SCRIPTS_VERSION POSTGIS_LIB_VERSION
+
+#define USE_GEOS 1
\ No newline at end of file

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070828/2b21b053/attachment.bin>


More information about the postgis-users mailing list