]> granicus.if.org Git - postgis/commitdiff
Use standard int64_t type and PRId64 format for 64bit identifiers
authorSandro Santilli <strk@keybit.net>
Sat, 18 Jul 2015 16:17:59 +0000 (16:17 +0000)
committerSandro Santilli <strk@keybit.net>
Sat, 18 Jul 2015 16:17:59 +0000 (16:17 +0000)
Hopefully helps with #3206

git-svn-id: http://svn.osgeo.org/postgis/trunk@13810 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom_topo.h
liblwgeom/lwgeom_topo.c
topology/postgis_topology.c

index 6cade652987cb5d9750484052494b55aa4455baf..75843f28a4ed516805adf7f8d30563768ca75550 100644 (file)
 #include "liblwgeom.h"
 
 /* INT64 */
-#ifdef _WIN32
-typedef __int64 LWT_INT64;
-#else
-typedef long long int LWT_INT64;
-#endif
+typedef int64_t LWT_INT64;
 
 /** Identifier of topology element */
 typedef LWT_INT64 LWT_ELEMID;
index 1bf3d3b4bfb5b50dba45d0deb838c0d9e62f3a0a..361bc809a4c253a10c42c33f57d1d2a9fd01f225 100644 (file)
@@ -26,6 +26,7 @@
 #include "lwgeom_geos.h"
 
 #include <stdio.h>
+#include <inttypes.h> /* for PRId64 */
 #include <errno.h>
 
 /*********************************************************************
@@ -862,8 +863,8 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
     minaz = maxaz = -1;
   }
 
-  LWDEBUGF(1, "Looking for edges incident to node %lld "
-              "and adjacent to azimuth %g", node, data->myaz);
+  LWDEBUGF(1, "Looking for edges incident to node %" PRId64
+              " and adjacent to azimuth %g", node, data->myaz);
 
   /* Get incident edges */
   edges = lwt_be_getEdgeByNode( topo, &node, &numedges, LWT_COL_EDGE_ALL );
@@ -888,14 +889,17 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
 
     if ( pa->npoints < 2 ) {
       lwgeom_free(cleangeom);
-      lwerror("corrupted topology: edge %lld does not have two distinct points", edge->edge_id);
+      lwerror("corrupted topology: edge %" PRId64
+              " does not have two distinct points", edge->edge_id);
       return -1;
     }
 
     if ( edge->start_node == node ) {
       getPoint2d_p(pa, 0, &p1);
       getPoint2d_p(pa, 1, &p2);
-      LWDEBUGF(1, "edge %lld starts on node %lld, edgeend is %g,%g-%g,%g",
+      LWDEBUGF(1, "edge %" PRId64
+                  "starts on node %" PRId64
+                  ", edgeend is %g,%g-%g,%g",
                   edge->edge_id, node, p1.x, p1.y, p2.x, p2.y);
       if ( ! azimuth_pt_pt(&p1, &p2, &az) ) {
         lwgeom_free(cleangeom);
@@ -904,7 +908,8 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
         return -1;
       }
       azdif = az - data->myaz;
-      LWDEBUGF(1, "azimuth of edge %lld: %g (diff: %g)", edge->edge_id, az, azdif);
+      LWDEBUGF(1, "azimuth of edge %" PRId64
+                  ": %g (diff: %g)", edge->edge_id, az, azdif);
 
       if ( azdif < 0 ) azdif += 2 * M_PI;
       if ( minaz == -1 ) {
@@ -912,19 +917,19 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
         data->nextCW = data->nextCCW = edge->edge_id; /* outgoing */
         data->cwFace = edge->face_left;
         data->ccwFace = edge->face_right;
-        LWDEBUGF(1, "new nextCW and nextCCW edge is %lld, "
-                    "outgoing, "
-                    "with face_left %lld and face_right %lld "
-                    "(face_right is new ccwFace, face_left is new cwFace)",
+        LWDEBUGF(1, "new nextCW and nextCCW edge is %" PRId64
+                    "outgoing, "
+                    "with face_left %" PRId64 " and face_right %" PRId64
+                    " (face_right is new ccwFace, face_left is new cwFace)",
                     edge->edge_id, edge->face_left,
                     edge->face_right);
       } else {
         if ( azdif < minaz ) {
           data->nextCW = edge->edge_id; /* outgoing */
           data->cwFace = edge->face_left;
-          LWDEBUGF(1, "new nextCW edge is %lld, "
+          LWDEBUGF(1, "new nextCW edge is %" PRId64 ", "
                       "outgoing, "
-                      "with face_left %lld and face_right %lld "
+                      "with face_left %" PRId64 " and face_right %" PRId64 " "
                       "(previous had minaz=%g, face_left is new cwFace)",
                       edge->edge_id, edge->face_left,
                       edge->face_right, minaz);
@@ -933,9 +938,9 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
         else if ( azdif > maxaz ) {
           data->nextCCW = edge->edge_id; /* outgoing */
           data->ccwFace = edge->face_right;
-          LWDEBUGF(1, "new nextCCW edge is %lld, "
+          LWDEBUGF(1, "new nextCCW edge is %" PRId64 ", "
                       "outgoing, "
-                      "with face_left %lld and face_right %lld "
+                      "with face_left %" PRId64 " and face_right %" PRId64 " "
                       "(previous had maxaz=%g, face_right is new ccwFace)",
                       edge->edge_id, edge->face_left,
                       edge->face_right, maxaz);
@@ -947,7 +952,8 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
     if ( edge->end_node == node ) {
       getPoint2d_p(pa, pa->npoints-1, &p1);
       getPoint2d_p(pa, pa->npoints-2, &p2);
-      LWDEBUGF(1, "edge %lld ends on node %lld, edgeend is %g,%g-%g,%g",
+      LWDEBUGF(1, "edge %" PRId64 " ends on node %" PRId64
+                  ", edgeend is %g,%g-%g,%g",
                   edge->edge_id, node, p1.x, p1.y, p2.x, p2.y);
       if ( ! azimuth_pt_pt(&p1, &p2, &az) ) {
         lwgeom_free(cleangeom);
@@ -956,16 +962,17 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
         return -1;
       }
       azdif = az - data->myaz;
-      LWDEBUGF(1, "azimuth of edge %lld: %g (diff: %g)", edge->edge_id, az, azdif);
+      LWDEBUGF(1, "azimuth of edge %" PRId64
+                  ": %g (diff: %g)", edge->edge_id, az, azdif);
       if ( azdif < 0 ) azdif += 2 * M_PI;
       if ( minaz == -1 ) {
         minaz = maxaz = azdif;
         data->nextCW = data->nextCCW = -edge->edge_id; /* incoming */
         data->cwFace = edge->face_right;
         data->ccwFace = edge->face_left;
-        LWDEBUGF(1, "new nextCW and nextCCW edge is %lld, "
+        LWDEBUGF(1, "new nextCW and nextCCW edge is %" PRId64 ", "
                     "incoming, "
-                    "with face_left %lld and face_right %lld "
+                    "with face_left %" PRId64 " and face_right %" PRId64 " "
                     "(face_right is new cwFace, face_left is new ccwFace)",
                     edge->edge_id, edge->face_left,
                     edge->face_right);
@@ -973,10 +980,10 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
         if ( azdif < minaz ) {
           data->nextCW = -edge->edge_id; /* incoming */
           data->cwFace = edge->face_right;
-          LWDEBUGF(1, "new nextCW edge is %lld, "
+          LWDEBUGF(1, "new nextCW edge is %" PRId64 ", "
                       "incoming, "
-                      "with face_left %lld and face_right %lld "
-                      "(previous had minaz=%g, face_right is new cwFace)",
+                      "with face_left %" PRId64 " and face_right %" PRId64
+                      " (previous had minaz=%g, face_right is new cwFace)",
                       edge->edge_id, edge->face_left,
                       edge->face_right, minaz);
           minaz = azdif;
@@ -984,10 +991,10 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
         else if ( azdif > maxaz ) {
           data->nextCCW = -edge->edge_id; /* incoming */
           data->ccwFace = edge->face_left;
-          LWDEBUGF(1, "new nextCCW edge is %lld, "
+          LWDEBUGF(1, "new nextCCW edge is %" PRId64 ", "
                       "outgoing from start point, "
-                      "with face_left %lld and face_right %lld "
-                      "(previous had maxaz=%g, face_left is new ccwFace)",
+                      "with face_left %" PRId64 " and face_right %" PRId64
+                      " (previous had maxaz=%g, face_left is new ccwFace)",
                       edge->edge_id, edge->face_left,
                       edge->face_right, maxaz);
           maxaz = azdif;
@@ -1000,16 +1007,17 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data,
   }
   if ( edges ) lwfree(edges); /* there might be none */
 
-  LWDEBUGF(1, "edges adjacent to azimuth %g (incident to node %lld): "
-           "CW:%lld(%g) CCW:%lld(%g)",
-           data->myaz, node, data->nextCW, minaz,
-           data->nextCCW, maxaz);
+  LWDEBUGF(1, "edges adjacent to azimuth %g"
+              " (incident to node %" PRId64 ")"
+              ": CW:%" PRId64 "(%g) CCW:%" PRId64 "(%g)",
+              data->myaz, node, data->nextCW, minaz,
+              data->nextCCW, maxaz);
 
   if ( numedges && data->cwFace != data->ccwFace )
   {
     if ( data->cwFace != -1 && data->ccwFace != -1 ) {
-      lwerror("Corrupted topology: adjacent edges %lld and %lld "
-              "bind different face (%lld and %lld)",
+      lwerror("Corrupted topology: adjacent edges %" PRId64 " and %" PRId64
+              " bind different face (%" PRId64 " and %" PRId64 ")",
               numedges, data->nextCW, data->nextCCW,
               data->cwFace, data->ccwFace);
       return -1;
@@ -1096,7 +1104,7 @@ _lwt_AddFaceSplit( LWT_TOPOLOGY* topo,
   signed_edge_ids = lwt_be_getRingEdges(topo, sedge,
                                         &num_signed_edge_ids, 0);
   if ( ! signed_edge_ids ) {
-    lwerror("Backend error (no ring edges for edge %lld): %s",
+    lwerror("Backend error (no ring edges for edge %" PRId64 "): %s",
             sedge, lwt_be_lastErrorMessage(topo->be_iface));
     return -2;
   }
@@ -1112,7 +1120,7 @@ _lwt_AddFaceSplit( LWT_TOPOLOGY* topo,
     }
   }
 
-  LWDEBUGF(1, "Edge %lld splitted face %lld (mbr_only:%d)",
+  LWDEBUGF(1, "Edge %" PRId64 " splitted face %" PRId64 " (mbr_only:%d)",
            sedge, face, mbr_only);
 
   /* Construct a polygon using edges of the ring */
@@ -1155,7 +1163,8 @@ _lwt_AddFaceSplit( LWT_TOPOLOGY* topo,
   for ( i=0; i<num_signed_edge_ids; ++i )
   {
     LWT_ELEMID eid = signed_edge_ids[i];
-    LWDEBUGF(1, "Edge %d in ring of edge %lld is edge %lld", i, sedge, eid);
+    LWDEBUGF(1, "Edge %d in ring of edge %" PRId64 " is edge %" PRId64,
+                i, sedge, eid);
     LWT_ISO_EDGE *edge = NULL;
     POINTARRAY *epa;
     for ( j=0; j<numedges; ++j )
@@ -1186,7 +1195,8 @@ _lwt_AddFaceSplit( LWT_TOPOLOGY* topo,
   LWPOLY* shell = lwpoly_construct(0, 0, 1, points);
 
   int isccw = ptarray_isccw(pa);
-  LWDEBUGF(1, "Ring of edge %lld is %sclockwise", sedge, isccw ? "counter" : "");
+  LWDEBUGF(1, "Ring of edge %" PRId64 " is %sclockwise",
+              sedge, isccw ? "counter" : "");
   const GBOX* shellbox = lwgeom_get_bbox(lwpoly_as_lwgeom(shell));
 
   if ( face == 0 )
@@ -1696,12 +1706,13 @@ lwt_AddEdgeModFace( LWT_TOPOLOGY* topo,
       else if ( newedge.face_left != node->containing_face )
       {
         lwerror("SQL/MM Spatial exception - geometry crosses an edge"
-                " (endnodes in faces %lld and %lld)",
+                " (endnodes in faces %" PRId64 " and %" PRId64 ")",
                 newedge.face_left, node->containing_face);
       }
     }
 
-    lwnotice("Node %d, with geom %p (looking for %d and %d)", node->node_id, node->geom, start_node, end_node);
+    lwnotice("Node %d, with geom %p (looking for %d and %d)",
+             node->node_id, node->geom, start_node, end_node);
     if ( node->node_id == start_node ) {
       start_node_geom = node->geom;
     } 
@@ -1874,7 +1885,7 @@ lwt_AddEdgeModFace( LWT_TOPOLOGY* topo,
         if ( match == 2 ) {
           lwerror("GEOSRelatePatternMatch error: %s", lwgeom_geos_errmsg);
         } else {
-          lwerror("SQL/MM Spatial exception - coincident edge %lld",
+          lwerror("SQL/MM Spatial exception - coincident edge %" PRId64,
                   edge->edge_id);
         }
         return -1;
@@ -1889,7 +1900,7 @@ lwt_AddEdgeModFace( LWT_TOPOLOGY* topo,
         if ( match == 2 ) {
           lwerror("GEOSRelatePatternMatch error: %s", lwgeom_geos_errmsg);
         } else {
-          lwerror("Spatial exception - geometry intersects edge %lld",
+          lwerror("Spatial exception - geometry intersects edge %" PRId64,
                   edge->edge_id);
         }
         return -1;
@@ -1904,8 +1915,8 @@ lwt_AddEdgeModFace( LWT_TOPOLOGY* topo,
         if ( match == 2 ) {
           lwerror("GEOSRelatePatternMatch error: %s", lwgeom_geos_errmsg);
         } else {
-          lwerror("SQL/MM Spatial exception - geometry crosses edge %lld",
-                  edge->edge_id);
+          lwerror("SQL/MM Spatial exception - geometry crosses edge %"
+                  PRId64, edge->edge_id);
         }
         return -1;
       }
@@ -1990,13 +2001,15 @@ lwt_AddEdgeModFace( LWT_TOPOLOGY* topo,
    */
   if ( newedge.face_left != newedge.face_right )
   {
-    lwerror("Left(%lld)/right(%lld) faces mismatch: invalid topology ?",
-      newedge.face_left, newedge.face_right);
+    lwerror("Left(%" PRId64 ")/right(%" PRId64 ")"
+            "faces mismatch: invalid topology ?",
+            newedge.face_left, newedge.face_right);
     return -1;
   }
   else if ( newedge.face_left == -1 )
   {
-    lwerror("Could not derive edge face from linked primitives: invalid topology ?");
+    lwerror("Could not derive edge face from linked primitives:"
+            " invalid topology ?");
     return -1;
   }
 
index 382bf2d39da60c4471f76a166cfd82adf4a0c7fa..90e640c6669f6626b4a5becaf92a517a77898130 100644 (file)
@@ -17,6 +17,7 @@
 #include "lib/stringinfo.h"
 //#include "funcapi.h"
 #include "executor/spi.h" /* this is what you need to work with SPI */
+#include "inttypes.h" /* for PRId64 */
 
 #include "../postgis_config.h"
 
@@ -34,6 +35,8 @@
 # define GNU_PRINTF23
 #endif
 
+#define ABS(x) (x<0?-x:x)
+
 /*
  * This is required for builds against pgsql
  */
@@ -213,34 +216,34 @@ addEdgeValues(StringInfo str, const LWT_ISO_EDGE *edge, int fields, int fullEdge
 
   appendStringInfoChar(str, '(');
   if ( fields & LWT_COL_EDGE_EDGE_ID ) {
-    if ( edge->edge_id != -1 ) appendStringInfo(str, "%lld", edge->edge_id);
+    if ( edge->edge_id != -1 ) appendStringInfo(str, "%" PRId64, edge->edge_id);
     else appendStringInfoString(str, "DEFAULT");
     sep = ",";
   }
   if ( fields & LWT_COL_EDGE_START_NODE ) {
-    appendStringInfo(str, "%s%lld", sep, edge->start_node);
+    appendStringInfo(str, "%s%" PRId64, sep, edge->start_node);
     sep = ",";
   }
   if ( fields & LWT_COL_EDGE_END_NODE ) {
-    appendStringInfo(str, "%s%lld", sep, edge->end_node);
+    appendStringInfo(str, "%s%" PRId64, sep, edge->end_node);
     sep = ",";
   }
   if ( fields & LWT_COL_EDGE_FACE_LEFT ) {
-    appendStringInfo(str, "%s%lld", sep, edge->face_left);
+    appendStringInfo(str, "%s%" PRId64, sep, edge->face_left);
     sep = ",";
   }
   if ( fields & LWT_COL_EDGE_FACE_RIGHT ) {
-    appendStringInfo(str, "%s%lld", sep, edge->face_right);
+    appendStringInfo(str, "%s%" PRId64, sep, edge->face_right);
     sep = ",";
   }
   if ( fields & LWT_COL_EDGE_NEXT_LEFT ) {
-    appendStringInfo(str, "%s%lld", sep, edge->next_left);
-    if ( fullEdgeData ) appendStringInfo(str, ",%lld", llabs(edge->next_left));
+    appendStringInfo(str, "%s%" PRId64, sep, edge->next_left);
+    if ( fullEdgeData ) appendStringInfo(str, ",%" PRId64, ABS(edge->next_left));
     sep = ",";
   }
   if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) {
-    appendStringInfo(str, "%s%lld", sep, edge->next_right);
-    if ( fullEdgeData ) appendStringInfo(str, ",%lld", llabs(edge->next_right));
+    appendStringInfo(str, "%s%" PRId64, sep, edge->next_right);
+    if ( fullEdgeData ) appendStringInfo(str, ",%" PRId64, ABS(edge->next_right));
     sep = ",";
   }
   if ( fields & LWT_COL_EDGE_GEOM )
@@ -292,45 +295,45 @@ addEdgeUpdate(StringInfo str, const LWT_ISO_EDGE* edge, int fields,
 
   if ( fields & LWT_COL_EDGE_EDGE_ID ) {
     appendStringInfoString(str, "edge_id ");
-    appendStringInfo(str, "%s %lld", op, edge->edge_id);
+    appendStringInfo(str, "%s %" PRId64, op, edge->edge_id);
     sep = sep1;
   }
   if ( fields & LWT_COL_EDGE_START_NODE ) {
     appendStringInfo(str, "%sstart_node ", sep);
-    appendStringInfo(str, "%s %lld", op, edge->start_node);
+    appendStringInfo(str, "%s %" PRId64, op, edge->start_node);
     sep = sep1;
   }
   if ( fields & LWT_COL_EDGE_END_NODE ) {
     appendStringInfo(str, "%send_node", sep);
-    appendStringInfo(str, "%s %lld", op, edge->end_node);
+    appendStringInfo(str, "%s %" PRId64, op, edge->end_node);
     sep = sep1;
   }
   if ( fields & LWT_COL_EDGE_FACE_LEFT ) {
     appendStringInfo(str, "%sleft_face", sep);
-    appendStringInfo(str, "%s %lld", op, edge->face_left);
+    appendStringInfo(str, "%s %" PRId64, op, edge->face_left);
     sep = sep1;
   }
   if ( fields & LWT_COL_EDGE_FACE_RIGHT ) {
     appendStringInfo(str, "%sright_face", sep);
-    appendStringInfo(str, "%s %lld", op, edge->face_right);
+    appendStringInfo(str, "%s %" PRId64, op, edge->face_right);
     sep = sep1;
   }
   if ( fields & LWT_COL_EDGE_NEXT_LEFT ) {
     appendStringInfo(str, "%snext_left_edge", sep);
-    appendStringInfo(str, "%s %lld", op, edge->next_left);
+    appendStringInfo(str, "%s %" PRId64, op, edge->next_left);
     sep = sep1;
     if ( fullEdgeData ) {
       appendStringInfo(str, "%s abs_next_left_edge", sep);
-      appendStringInfo(str, "%s %lld", op, llabs(edge->next_left));
+      appendStringInfo(str, "%s %" PRId64, op, ABS(edge->next_left));
     }
   }
   if ( fields & LWT_COL_EDGE_NEXT_RIGHT ) {
     appendStringInfo(str, "%snext_right_edge", sep);
-    appendStringInfo(str, "%s %lld", op, edge->next_right);
+    appendStringInfo(str, "%s %" PRId64, op, edge->next_right);
     sep = sep1;
     if ( fullEdgeData ) {
       appendStringInfo(str, "%s abs_next_right_edge", sep);
-      appendStringInfo(str, "%s %lld", op, llabs(edge->next_right));
+      appendStringInfo(str, "%s %" PRId64, op, ABS(edge->next_right));
     }
   }
   if ( fields & LWT_COL_EDGE_GEOM ) {
@@ -371,13 +374,13 @@ addNodeUpdate(StringInfo str, const LWT_ISO_NODE* node, int fields,
 
   if ( fields & LWT_COL_NODE_NODE_ID ) {
     appendStringInfoString(str, "node_id ");
-    appendStringInfo(str, "%s %lld", op, node->node_id);
+    appendStringInfo(str, "%s %" PRId64, op, node->node_id);
     sep = sep1;
   }
   if ( fields & LWT_COL_NODE_CONTAINING_FACE ) {
     appendStringInfo(str, "%scontaining_face %s", sep, op);
     if ( node->containing_face != -1 ) {
-      appendStringInfo(str, "%lld", node->containing_face);
+      appendStringInfo(str, "%" PRId64, node->containing_face);
     } else {
       appendStringInfoString(str, "NULL");
     }
@@ -436,14 +439,14 @@ addNodeValues(StringInfo str, const LWT_ISO_NODE *node, int fields)
   appendStringInfoChar(str, '(');
 
   if ( fields & LWT_COL_NODE_NODE_ID ) {
-    if ( node->node_id != -1 ) appendStringInfo(str, "%lld", node->node_id);
+    if ( node->node_id != -1 ) appendStringInfo(str, "%" PRId64, node->node_id);
     else appendStringInfoString(str, "DEFAULT");
     sep = ",";
   }
 
   if ( fields & LWT_COL_NODE_CONTAINING_FACE ) {
     if ( node->containing_face != -1 )
-      appendStringInfo(str, "%s%lld", sep, node->containing_face);
+      appendStringInfo(str, "%s%" PRId64, sep, node->containing_face);
     else appendStringInfo(str, "%snull", sep);
   }
 
@@ -465,7 +468,7 @@ addNodeValues(StringInfo str, const LWT_ISO_NODE *node, int fields)
 static void
 addFaceValues(StringInfo str, LWT_ISO_FACE *face, int srid)
 {
-  if ( face->face_id != -1 ) appendStringInfo(str, "(%lld", face->face_id);
+  if ( face->face_id != -1 ) appendStringInfo(str, "(%" PRId64, face->face_id);
   else appendStringInfoString(str, "(DEFAULT");
 
   if ( face->mbr ) {
@@ -700,7 +703,7 @@ cb_getEdgeById(const LWT_BE_TOPOLOGY* topo,
   appendStringInfoString(sql, " WHERE edge_id IN (");
   // add all identifiers here
   for (i=0; i<*numelems; ++i) {
-    appendStringInfo(sql, "%s%lld", (i?",":""), ids[i]);
+    appendStringInfo(sql, "%s%" PRId64, (i?",":""), ids[i]);
   }
   appendStringInfoString(sql, ")");
   POSTGIS_DEBUGF(1, "cb_getEdgeById query: %s", sql->data);
@@ -746,12 +749,12 @@ cb_getEdgeByNode(const LWT_BE_TOPOLOGY* topo,
   appendStringInfoString(sql, " WHERE start_node IN (");
   // add all identifiers here
   for (i=0; i<*numelems; ++i) {
-    appendStringInfo(sql, "%s%lld", (i?",":""), ids[i]);
+    appendStringInfo(sql, "%s%" PRId64, (i?",":""), ids[i]);
   }
   appendStringInfoString(sql, ") OR end_node IN (");
   // add all identifiers here
   for (i=0; i<*numelems; ++i) {
-    appendStringInfo(sql, "%s%lld", (i?",":""), ids[i]);
+    appendStringInfo(sql, "%s%" PRId64, (i?",":""), ids[i]);
   }
   appendStringInfoString(sql, ")");
 
@@ -799,12 +802,12 @@ cb_getEdgeByFace(const LWT_BE_TOPOLOGY* topo,
   appendStringInfoString(sql, " WHERE left_face IN (");
   // add all identifiers here
   for (i=0; i<*numelems; ++i) {
-    appendStringInfo(sql, "%s%lld", (i?",":""), ids[i]);
+    appendStringInfo(sql, "%s%" PRId64, (i?",":""), ids[i]);
   }
   appendStringInfoString(sql, ") OR right_face IN (");
   // add all identifiers here
   for (i=0; i<*numelems; ++i) {
-    appendStringInfo(sql, "%s%lld", (i?",":""), ids[i]);
+    appendStringInfo(sql, "%s%" PRId64, (i?",":""), ids[i]);
   }
   appendStringInfoString(sql, ")");
 
@@ -852,7 +855,7 @@ cb_getFacesById(const LWT_BE_TOPOLOGY* topo,
   appendStringInfoString(sql, " WHERE face_id IN (");
   // add all identifiers here
   for (i=0; i<*numelems; ++i) {
-    appendStringInfo(sql, "%s%lld", (i?",":""), ids[i]);
+    appendStringInfo(sql, "%s%" PRId64, (i?",":""), ids[i]);
   }
   appendStringInfoString(sql, ")");
 
@@ -895,8 +898,9 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo,
 
   initStringInfo(sql);
   appendStringInfo(sql, "WITH RECURSIVE edgering AS ( "
-    "SELECT %lld as signed_edge_id, edge_id, next_left_edge, next_right_edge "
-    "FROM \"%s\".edge_data WHERE edge_id = %lld UNION "
+    "SELECT %" PRId64
+    " as signed_edge_id, edge_id, next_left_edge, next_right_edge "
+    "FROM \"%s\".edge_data WHERE edge_id = %" PRId64 " UNION "
     "SELECT CASE WHEN "
     "p.signed_edge_id < 0 THEN p.next_right_edge ELSE p.next_left_edge END, "
     "e.edge_id, e.next_left_edge, e.next_right_edge "
@@ -904,7 +908,7 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo,
     "e.edge_id = CASE WHEN p.signed_edge_id < 0 THEN "
     "abs(p.next_right_edge) ELSE abs(p.next_left_edge) END ) "
     "SELECT * FROM edgering",
-    edge, topo->name, llabs(edge), topo->name);
+    edge, topo->name, ABS(edge), topo->name);
   if ( limit ) {
     ++limit; /* so we know if we hit it */
     appendStringInfo(sql, " LIMIT %d", limit);
@@ -945,7 +949,7 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo,
     }
     val = DatumGetInt32(dat);
     edges[i] = val;
-    POSTGIS_DEBUGF(1, "Component %d in ring of edge %lld is edge %d",
+    POSTGIS_DEBUGF(1, "Component %d in ring of edge %" PRId64 " is edge %d",
                    i, edge, val);
   }
 
@@ -970,7 +974,7 @@ cb_getNodeById(const LWT_BE_TOPOLOGY* topo,
   appendStringInfoString(sql, " WHERE node_id IN (");
   // add all identifiers here
   for (i=0; i<*numelems; ++i) {
-    appendStringInfo(sql, "%s%lld", (i?",":""), ids[i]);
+    appendStringInfo(sql, "%s%" PRId64, (i?",":""), ids[i]);
   }
   appendStringInfoString(sql, ")");
   POSTGIS_DEBUGF(1, "cb_getNodeById query: %s", sql->data);
@@ -1015,7 +1019,7 @@ cb_getNodeByFace(const LWT_BE_TOPOLOGY* topo,
   appendStringInfoString(sql, " WHERE containing_face IN (");
   // add all identifiers here
   for (i=0; i<*numelems; ++i) {
-    appendStringInfo(sql, "%s%lld", (i?",":""), ids[i]);
+    appendStringInfo(sql, "%s%" PRId64, (i?",":""), ids[i]);
   }
   appendStringInfoString(sql, ")");
   POSTGIS_DEBUGF(1, "cb_getNodeByFace query: %s", sql->data);
@@ -1517,7 +1521,7 @@ cb_updateFacesById( const LWT_BE_TOPOLOGY* topo,
   for (i=0; i<numfaces; ++i) {
     const LWT_ISO_FACE* face = &(faces[i]);
     appendStringInfo(sql,
-      "%lld id, ST_SetSRID(ST_MakeEnvelope(%g,%g,%g,%g),%d) mbr",
+      "%" PRId64 " id, ST_SetSRID(ST_MakeEnvelope(%g,%g,%g,%g),%d) mbr",
       face->face_id, face->mbr->xmin, face->mbr->ymin,
       face->mbr->xmax, face->mbr->ymax, topo->srid);
   }
@@ -1710,7 +1714,7 @@ cb_updateTopoGeomEdgeSplit ( const LWT_BE_TOPOLOGY* topo,
   }
   appendStringInfo( sql, " FROM \"%s\".relation r %s topology.layer l WHERE "
     "l.topology_id = %d AND l.level = 0 AND l.layer_id = r.layer_id "
-    "AND abs(r.element_id) = %lld AND r.element_type = 2",
+    "AND abs(r.element_id) = %" PRId64 " AND r.element_type = 2",
     topo->name, (new_edge2 == -1 ? "," : "USING" ), topo->id, split_edge );
   if ( new_edge2 != -1 ) {
     appendStringInfo(sql, " RETURNING %s", proj);
@@ -1771,7 +1775,7 @@ cb_updateTopoGeomEdgeSplit ( const LWT_BE_TOPOLOGY* topo,
     resetStringInfo(sql);
     appendStringInfo(sql,
       "INSERT INTO \"%s\".relation VALUES ("
-      "%d,%d,%lld,%d)", topo->name,
+      "%d,%d,%" PRId64 ",%d)", topo->name,
       topogeo_id, layer_id, negate ? -new_edge1 : new_edge1, element_type);
     spi_result = SPI_execute(sql->data, false, 0);
     if ( spi_result != SPI_OK_INSERT ) {
@@ -1784,7 +1788,7 @@ cb_updateTopoGeomEdgeSplit ( const LWT_BE_TOPOLOGY* topo,
       resetStringInfo(sql);
       appendStringInfo(sql,
         "INSERT INTO FROM \"%s\".relation VALUES ("
-        "%d,%d,%lld,%d", topo->name,
+        "%d,%d,%" PRId64 ",%d", topo->name,
         topogeo_id, layer_id, negate ? -new_edge2 : new_edge2, element_type);
       spi_result = SPI_execute(sql->data, false, 0);
       if ( spi_result != SPI_OK_INSERT ) {
@@ -1812,7 +1816,8 @@ cb_updateTopoGeomFaceSplit ( const LWT_BE_TOPOLOGY* topo,
   const char *proj = "r.element_id, r.topogeo_id, r.layer_id, r.element_type";
 
   POSTGIS_DEBUGF(1, "cb_updateTopoGeomFaceSplit signalled "
-                    "split of face %lld into %lld and %lld",
+                    "split of face %" PRId64 " into %" PRId64
+                    " and %" PRId64,
                     split_face, new_face1, new_face2);
 
   initStringInfo(sql);
@@ -1823,7 +1828,7 @@ cb_updateTopoGeomFaceSplit ( const LWT_BE_TOPOLOGY* topo,
   }
   appendStringInfo( sql, " FROM \"%s\".relation r %s topology.layer l WHERE "
     "l.topology_id = %d AND l.level = 0 AND l.layer_id = r.layer_id "
-    "AND abs(r.element_id) = %lld AND r.element_type = 3",
+    "AND abs(r.element_id) = %" PRId64 " AND r.element_type = 3",
     topo->name, (new_face2 == -1 ? "," : "USING" ), topo->id, split_face );
   if ( new_face2 != -1 ) {
     appendStringInfo(sql, " RETURNING %s", proj);
@@ -1886,7 +1891,7 @@ cb_updateTopoGeomFaceSplit ( const LWT_BE_TOPOLOGY* topo,
     resetStringInfo(sql);
     appendStringInfo(sql,
       "INSERT INTO \"%s\".relation VALUES ("
-      "%d,%d,%lld,%d)", topo->name,
+      "%d,%d,%" PRId64 ",%d)", topo->name,
       topogeo_id, layer_id, negate ? -new_face1 : new_face1, element_type);
 
     POSTGIS_DEBUGF(1, "cb_updateTopoGeomFaceSplit query: %s", sql->data);
@@ -1902,7 +1907,7 @@ cb_updateTopoGeomFaceSplit ( const LWT_BE_TOPOLOGY* topo,
       resetStringInfo(sql);
       appendStringInfo(sql,
         "INSERT INTO \"%s\".relation VALUES ("
-        "%d,%d,%lld,%d)", topo->name,
+        "%d,%d,%" PRId64 ",%d)", topo->name,
         topogeo_id, layer_id, negate ? -new_face2 : new_face2, element_type);
 
       POSTGIS_DEBUGF(1, "cb_updateTopoGeomFaceSplit query: %s", sql->data);