[postgis-tickets] r15662 - #3837, --enable-debug to set PARANOIA level

Paul Ramsey pramsey at cleverelephant.ca
Fri Sep 8 12:20:47 PDT 2017


Author: pramsey
Date: 2017-09-08 12:20:46 -0700 (Fri, 08 Sep 2017)
New Revision: 15662

Modified:
   trunk/configure.ac
   trunk/liblwgeom/lwgeom.c
   trunk/liblwgeom/lwgeom_api.c
   trunk/liblwgeom/lwgeom_geos.c
   trunk/liblwgeom/lwgeom_geos_split.c
   trunk/liblwgeom/ptarray.c
   trunk/libpgcommon/lwgeom_pg.c
   trunk/postgis_config.h.in
Log:
#3837, --enable-debug to set PARANOIA level

This required some re-working of the protobuf sections,
for reasons that aren't clear. However, hopefully that
re-working will also fix things for others. Basically,
the pkg-config portions seemed to only work by accident
for the folks who wrote them initially, so they are 
improved, and the use of --without is more strongly
enforced in the conditional blocks


Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2017-09-08 13:04:38 UTC (rev 15661)
+++ trunk/configure.ac	2017-09-08 19:20:46 UTC (rev 15662)
@@ -857,7 +857,7 @@
 	[AS_HELP_STRING([--without-json], [build without json-c support])],
 	[CHECK_JSON="$withval"], [])
 
-if test "$CHECK_JSON" != "no"; then dnl {
+if test "$CHECK_JSON" != "no"; then 
 
 AC_ARG_WITH([jsondir],
 	[AS_HELP_STRING([--with-jsondir=PATH], [specify the json-c installation directory])],
@@ -903,7 +903,7 @@
 AC_SUBST([JSON_LDFLAGS])
 AC_SUBST([HAVE_JSON])
 
-fi dnl }
+fi 
 
 
 dnl ===========================================================================
@@ -927,63 +927,77 @@
 	[AS_HELP_STRING([--without-protobuf], [build without protobuf-c support])],
 	[CHECK_PROTOBUF="$withval"], [])
 
-if test "$CHECK_PROTOBUF" != "no"; then dnl {
+dnl User didn't turn off protobuf support so...
+if test "$CHECK_PROTOBUF" != "no"; then 
 
-AC_ARG_WITH([protobufdir],
-	[AS_HELP_STRING([--with-protobufdir=PATH], [specify the protobuf-c installation directory])],
-	[PROTOBUFDIR="$withval"], [PROTOBUFDIR=])
+    AC_ARG_WITH([protobufdir],
+    	[AS_HELP_STRING([--with-protobufdir=PATH], [specify the protobuf-c installation directory])],
+    	[PROTOBUFDIR="$withval"], [PROTOBUFDIR=])
 
-if test ! "x$PROTOBUFDIR" = "x"; then
-	dnl Make sure that the directory exists
-	if test "x$PROTOBUFDIR" = "xyes"; then
-		AC_MSG_ERROR([you must specify a parameter to --with-protobufdir, e.g. --with-protobufdir=/path/to])
-	else
-		AC_MSG_RESULT([Using user-specified protobuf-c directory: $PROTOBUFDIR])
+    dnl User specified the directory to find protobuf in, check that and
+    dnl fail if it doesn't work
+    if test ! "x$PROTOBUFDIR" = "x"; then
+    	dnl Make sure that the directory exists
+    	if test "x$PROTOBUFDIR" = "xyes"; then
+    		AC_MSG_ERROR([you must specify a parameter to --with-protobufdir, e.g. --with-protobufdir=/path/to])
+    	else
+    		AC_MSG_RESULT([Using user-specified protobuf-c directory: $PROTOBUFDIR])
 
-		dnl Add the include directory to PROTOBUF_CPPFLAGS
-		PROTOBUF_CPPFLAGS="-I$PROTOBUFDIR/include"
-		PROTOBUF_LDFLAGS="-L$PROTOBUFDIR/lib"
-	fi
-fi
+    		dnl Add the include directory to PROTOBUF_CPPFLAGS
+    		PROTOBUF_CPPFLAGS="-I$PROTOBUFDIR/include"
+    		PROTOBUF_LDFLAGS="-L$PROTOBUFDIR/lib"
+    	fi
+        
+        dnl Check that we can find the protobuf/protobuf.h header file
+        CPPFLAGS_SAVE="$CPPFLAGS"
+        CPPFLAGS="$PROTOBUF_CPPFLAGS"
+        AC_CHECK_HEADER([protobuf-c/protobuf-c.h], [], 
+		    AC_MSG_ERROR([unable to find $PROTOBUFDIR/include/protobuf-c/protobuf-c.h])
+        )
+        CPPFLAGS="$CPPFLAGS_SAVE"
 
-dnl Check that we can find the protobuf/protobuf.h header file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$PROTOBUF_CPPFLAGS"
-AC_CHECK_HEADER([protobuf-c/protobuf-c.h], [HAVE_PROTOBUF=yes], [])
-CPPFLAGS="$CPPFLAGS_SAVE"
+        dnl Ensure we can link against libprotobuf-c
+        LIBS_SAVE="$LIBS"
+        LIBS="$PROTOBUF_LDFLAGS"
+        AC_CHECK_LIB([protobuf-c], [protobuf_c_message_check], [], 
+            AC_MSG_ERROR([unable to link protobuf-c from $PROTOBUFDIR/lib])
+        )
+        HAVE_PROTOBUF=yes
+        PROTOBUF_LDFLAGS="-L$PROTOBUFDIR/lib -lprotobuf-c"
+        LIBS="$LIBS_SAVE"
 
-dnl Ensure we can link against libprotobuf-c
-LIBS_SAVE="$LIBS"
-LIBS="$PROTOBUF_LDFLAGS"
-AC_CHECK_LIB([protobuf-c], [protobuf_c_message_check], [HAVE_PROTOBUF=yes; PROTOBUF_LDFLAGS="${PROTOBUF_LDFLAGS} -lprotobuf-c"], [HAVE_PROTOBUF=no])
-LIBS="$LIBS_SAVE"
+    dnl No user-specified protobuf dir, try to find one using pkg-config  
+    else
+        if test "$PKG_CONFIG" = "no"; then
+        	AC_MSG_WARN([Cannot find pkg-config, disabling protobuf support.])
+        	HAVE_PROTOBUF=no
+        else
+        	dnl Ensure libprotobuf-c is of minimum required version
+        	PKG_CHECK_MODULES([PROTOBUFC], [libprotobuf-c >= 1.1.0], [
+                    HAVE_PROTOBUF=yes; 
+                    PROTOBUF_CPPFLAGS=$PROTOBUFC_CFLAGS;
+                    PROTOBUF_LDFLAGS=$PROTOBUFC_LIBS
+                ], 
+                [HAVE_PROTOBUF=no])
+        fi
+    fi
 
-if test "$PKG_CONFIG" = "no"; then
-	AC_MSG_WARN([Cannot find pkg-config, disabling protobuf support.])
-	HAVE_PROTOBUF=no
-else
-	dnl Ensure libprotobuf-c is of minimum required version
-	PKG_CHECK_MODULES([PROTOBUFC], [libprotobuf-c >= 1.1.0], [HAVE_PROTOBUF=yes], [HAVE_PROTOBUF=no])
-fi
+    if test "$HAVE_PROTOBUF" = "yes"; then
+    	AC_PATH_PROG(PROTOCC, protoc-c)
+    	if test "x$PROTOCC" = "x"; then
+    	  AC_MSG_WARN([Protobuf compiler missing, disabling protobuf support.])
+    	  HAVE_PROTOBUF=no
+    	else
+    	  AC_DEFINE([HAVE_LIBPROTOBUF], [1], [Define to 1 if libprotobuf-c is present])
+    	fi
+    fi
 
-if test "$HAVE_PROTOBUF" = "yes"; then
-	AC_PATH_PROG(PROTOCC, protoc-c)
-	if test "x$PROTOCC" = "x"; then
-	  AC_MSG_WARN([Protobuf compiler missing, disabling protobuf support.])
-	  HAVE_PROTOBUF=no
-	else
-	  AC_DEFINE([HAVE_LIBPROTOBUF], 1, [Define to 1 if libprotobuf-c is present])
-	fi
+    AC_SUBST([PROTOBUF_CPPFLAGS])
+    AC_SUBST([PROTOBUF_LDFLAGS])
+    AC_SUBST([HAVE_PROTOBUF])
 fi
 
-AC_SUBST([PROTOBUF_CPPFLAGS])
-AC_SUBST([PROTOBUF_LDFLAGS])
-AC_SUBST([HAVE_PROTOBUF])
 
-fi dnl }
-
-
-
 dnl ===========================================================================
 dnl Detect GTK+2.0 for GUI
 dnl ===========================================================================
@@ -1019,25 +1033,21 @@
 
 
 dnl ===========================================================================
-dnl Allow the user to enable debugging with --enable-debug
+dnl Allow the developer to turn on expensive checks and debugging flags
+dnl with --enable-debug
 dnl
-dnl Currently we default to debug level 4. See DEBUG for more information.
-dnl
 
-AC_ARG_ENABLE([debug], AC_HELP_STRING([--enable-debug], [Enable verbose debugging messages]),
-	[POSTGIS_DEBUG_LEVEL=4], [POSTGIS_DEBUG_LEVEL=0])
+AC_ARG_ENABLE([debug], AC_HELP_STRING([--enable-debug], [Enable debugging code and flags]),
+	[ENABLE_DEBUG=1], [ENABLE_DEBUG=0])
 
-AC_DEFINE_UNQUOTED([POSTGIS_DEBUG_LEVEL], [$POSTGIS_DEBUG_LEVEL], [PostGIS library debug level (0=disabled)])
+if test $ENABLE_DEBUG -eq 1; then
+    AC_DEFINE_UNQUOTED([PARANOIA_LEVEL], [10], [Enable use of memory checks])
+    CFLAGS="$CFLAGS -g"
+else
+    AC_DEFINE_UNQUOTED([PARANOIA_LEVEL], [0], [Disable use of memory checks])
+fi
 
-dnl ===========================================================================
-dnl Allow the user to enable GEOS profiling with --enable-profile
-dnl
 
-AC_ARG_ENABLE([profile], AC_HELP_STRING([--enable-profile], [Enable GEOS profiling messages]),
-	[POSTGIS_PROFILE=1], [POSTGIS_PROFILE=0])
-
-AC_DEFINE_UNQUOTED([POSTGIS_PROFILE], [$POSTGIS_PROFILE], [Enable GEOS profiling (0=disabled)])
-
 dnl ===========================================================================
 dnl Define version macros
 dnl

Modified: trunk/liblwgeom/lwgeom.c
===================================================================
--- trunk/liblwgeom/lwgeom.c	2017-09-08 13:04:38 UTC (rev 15661)
+++ trunk/liblwgeom/lwgeom.c	2017-09-08 19:20:46 UTC (rev 15662)
@@ -1516,11 +1516,6 @@
 	LWPOLY *poly;
 	int i;
 
-#if PARANOIA_LEVEL > 0
-  assert(o1 < 4);
-  assert(o2 < 4);
-#endif
-
 	if ( (!in) || lwgeom_is_empty(in) ) return;
 
   /* TODO: check for lwgeom NOT having the specified dimension ? */

Modified: trunk/liblwgeom/lwgeom_api.c
===================================================================
--- trunk/liblwgeom/lwgeom_api.c	2017-09-08 13:04:38 UTC (rev 15661)
+++ trunk/liblwgeom/lwgeom_api.c	2017-09-08 19:20:46 UTC (rev 15662)
@@ -32,11 +32,6 @@
 #include <assert.h>
 #include "../postgis_svn_revision.h"
 
-/*
- * Lower this to reduce integrity checks
- */
-#define PARANOIA_LEVEL 1
-
 const char *
 lwgeom_version()
 {

Modified: trunk/liblwgeom/lwgeom_geos.c
===================================================================
--- trunk/liblwgeom/lwgeom_geos.c	2017-09-08 13:04:38 UTC (rev 15661)
+++ trunk/liblwgeom/lwgeom_geos.c	2017-09-08 19:20:46 UTC (rev 15662)
@@ -1247,7 +1247,7 @@
    * We should now have a collection
    */
 #if PARANOIA_LEVEL > 0
-  if ( GEOSGeometryTypeId(geos_result) != COLLECTIONTYPE )
+  if ( GEOSGeomTypeId(geos_result) != COLLECTIONTYPE )
   {
     GEOSGeom_destroy(geos_result);
     lwerror("Unexpected return from GEOSpolygonize");

Modified: trunk/liblwgeom/lwgeom_geos_split.c
===================================================================
--- trunk/liblwgeom/lwgeom_geos_split.c	2017-09-08 13:04:38 UTC (rev 15661)
+++ trunk/liblwgeom/lwgeom_geos_split.c	2017-09-08 19:20:46 UTC (rev 15662)
@@ -419,7 +419,7 @@
 	}
 
 #if PARANOIA_LEVEL > 0
-	if ( GEOSGeometryTypeId(polygons) != COLLECTIONTYPE )
+	if ( GEOSGeomTypeId(polygons) != COLLECTIONTYPE )
 	{
 		GEOSGeom_destroy(g1);
 		GEOSGeom_destroy(g2);

Modified: trunk/liblwgeom/ptarray.c
===================================================================
--- trunk/liblwgeom/ptarray.c	2017-09-08 13:04:38 UTC (rev 15661)
+++ trunk/liblwgeom/ptarray.c	2017-09-08 19:20:46 UTC (rev 15662)
@@ -391,11 +391,6 @@
 	double d, *dp1, *dp2;
 	POINT4D p;
 
-#if PARANOIA_LEVEL > 0
-  assert(o1 < 4);
-  assert(o2 < 4);
-#endif
-
   dp1 = ((double*)&p)+(unsigned)o1;
   dp2 = ((double*)&p)+(unsigned)o2;
 	for (i=0 ; i < pa->npoints ; i++)

Modified: trunk/libpgcommon/lwgeom_pg.c
===================================================================
--- trunk/libpgcommon/lwgeom_pg.c	2017-09-08 13:04:38 UTC (rev 15661)
+++ trunk/libpgcommon/lwgeom_pg.c	2017-09-08 19:20:46 UTC (rev 15662)
@@ -29,8 +29,6 @@
 #include <stdlib.h>
 #include <stdarg.h>
 
-#define PARANOIA_LEVEL 1
-
 #define PGC_ERRMSG_MAXLEN 256
 
 /**

Modified: trunk/postgis_config.h.in
===================================================================
--- trunk/postgis_config.h.in	2017-09-08 13:04:38 UTC (rev 15661)
+++ trunk/postgis_config.h.in	2017-09-08 19:20:46 UTC (rev 15662)
@@ -3,6 +3,13 @@
 
 #include "postgis_svn_revision.h"
 
+/* Manually manipulate the POSTGIS_DEBUG_LEVEL, it is not affected by the  
+   configure process */
+#define POSTGIS_DEBUG_LEVEL 0
+
+/* Define to 1 to enable memory checks in pointarray management. */
+#undef PARANOIA_LEVEL
+
 /* Define to 1 if translation of program messages to the user's native
    language is requested. */
 #undef ENABLE_NLS
@@ -121,9 +128,6 @@
 /* PostGIS build date */
 #undef POSTGIS_BUILD_DATE
 
-/* PostGIS library debug level (0=disabled) */
-#undef POSTGIS_DEBUG_LEVEL
-
 /* SFCGAL library version at buil time */
 #undef POSTGIS_SFCGAL_VERSION
 
@@ -151,9 +155,6 @@
 /* PostgreSQL server version */
 #undef POSTGIS_PGSQL_VERSION
 
-/* Enable GEOS profiling (0=disabled) */
-#undef POSTGIS_PROFILE
-
 /* PROJ library version */
 #undef POSTGIS_PROJ_VERSION
 



More information about the postgis-tickets mailing list