From 9eabe722f4f97d4ff8077efce48c3b6a729b6af6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ra=C3=BAl=20Mar=C3=ADn=20Rodr=C3=ADguez?= Date: Wed, 24 Apr 2019 10:04:42 +0000 Subject: [PATCH] Style changes from the previous commits Also addresses some warnings in debug logs Note: SPI_processed was 32b until PG9.5 (still supported) git-svn-id: http://svn.osgeo.org/postgis/trunk@17409 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/liblwgeom_topo.h | 133 ++--- liblwgeom/liblwgeom_topo_internal.h | 26 +- liblwgeom/lwgeom_topo.c | 745 ++++++++++++++-------------- raster/rt_pg/rtpg_gdal.c | 4 +- raster/rt_pg/rtpg_geometry.c | 15 +- topology/postgis_topology.c | 249 +++++----- 6 files changed, 573 insertions(+), 599 deletions(-) diff --git a/liblwgeom/liblwgeom_topo.h b/liblwgeom/liblwgeom_topo.h index 0e193131e..c7c27e17e 100644 --- a/liblwgeom/liblwgeom_topo.h +++ b/liblwgeom/liblwgeom_topo.h @@ -198,10 +198,7 @@ typedef struct LWT_BE_CALLBACKS_T { * (@see lastErrorMessage) * */ - LWT_ISO_NODE* (*getNodeById) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields - ); + LWT_ISO_NODE *(*getNodeById)(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields); /** * Get nodes within distance by point @@ -223,11 +220,12 @@ typedef struct LWT_BE_CALLBACKS_T { * - error ("numelems" is set to -1) * */ - LWT_ISO_NODE* (*getNodeWithinDistance2D) ( - const LWT_BE_TOPOLOGY* topo, - const LWPOINT* pt, double dist, uint64_t* numelems, - int fields, int limit - ); + LWT_ISO_NODE *(*getNodeWithinDistance2D)(const LWT_BE_TOPOLOGY *topo, + const LWPOINT *pt, + double dist, + uint64_t *numelems, + int fields, + int limit); /** * Insert nodes @@ -242,11 +240,7 @@ typedef struct LWT_BE_CALLBACKS_T { * * @return 1 on success, 0 on error (@see lastErrorMessage) */ - int (*insertNodes) ( - const LWT_BE_TOPOLOGY* topo, - LWT_ISO_NODE* nodes, - uint64_t numelems - ); + int (*insertNodes)(const LWT_BE_TOPOLOGY *topo, LWT_ISO_NODE *nodes, uint64_t numelems); /** * Get edge by id @@ -264,10 +258,7 @@ typedef struct LWT_BE_CALLBACKS_T { * - none found ("numelems" is set to 0) * - error ("numelems" is set to -1) */ - LWT_ISO_EDGE* (*getEdgeById) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields - ); + LWT_ISO_EDGE *(*getEdgeById)(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields); /** * Get edges within distance by point @@ -289,11 +280,12 @@ typedef struct LWT_BE_CALLBACKS_T { * - error ("numelems" is set to -1) * */ - LWT_ISO_EDGE* (*getEdgeWithinDistance2D) ( - const LWT_BE_TOPOLOGY* topo, - const LWPOINT* pt, double dist, uint64_t* numelems, - int fields, int limit - ); + LWT_ISO_EDGE *(*getEdgeWithinDistance2D)(const LWT_BE_TOPOLOGY *topo, + const LWPOINT *pt, + double dist, + uint64_t *numelems, + int fields, + int limit); /** * Get next available edge identifier @@ -322,11 +314,7 @@ typedef struct LWT_BE_CALLBACKS_T { * * @return number of inserted edges, or -1 (@see lastErrorMessage) */ - int (*insertEdges) ( - const LWT_BE_TOPOLOGY* topo, - LWT_ISO_EDGE* edges, - uint64_t numelems - ); + int (*insertEdges)(const LWT_BE_TOPOLOGY *topo, LWT_ISO_EDGE *edges, uint64_t numelems); /** * Update edges selected by fields match/mismatch @@ -369,10 +357,7 @@ typedef struct LWT_BE_CALLBACKS_T { * - none found ("numelems" is set to 0) * - error ("numelems" is set to -1) */ - LWT_ISO_FACE* (*getFaceById) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields - ); + LWT_ISO_FACE *(*getFaceById)(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields); /** * Get face containing point @@ -447,11 +432,8 @@ typedef struct LWT_BE_CALLBACKS_T { * - error ("numelems" is set to -1) * */ - LWT_ISO_NODE* (*getNodeWithinBox2D) ( - const LWT_BE_TOPOLOGY* topo, - const GBOX* box, - uint64_t* numelems, int fields, int limit - ); + LWT_ISO_NODE *( + *getNodeWithinBox2D)(const LWT_BE_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, int limit); /** * Get edges whose bounding box overlaps a given 2D bounding box @@ -472,11 +454,8 @@ typedef struct LWT_BE_CALLBACKS_T { * - error ("numelems" is set to -1) * */ - LWT_ISO_EDGE* (*getEdgeWithinBox2D) ( - const LWT_BE_TOPOLOGY* topo, - const GBOX* box, - uint64_t* numelems, int fields, int limit - ); + LWT_ISO_EDGE *( + *getEdgeWithinBox2D)(const LWT_BE_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, int limit); /** * Get edges that start or end on any of the given node identifiers @@ -496,10 +475,7 @@ typedef struct LWT_BE_CALLBACKS_T { * - error ("numelems" is set to -1) * (@see lastErrorMessage) */ - LWT_ISO_EDGE* (*getEdgeByNode) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields - ); + LWT_ISO_EDGE *(*getEdgeByNode)(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields); /** * Update nodes selected by fields match/mismatch @@ -559,11 +535,7 @@ typedef struct LWT_BE_CALLBACKS_T { * * @return number of inserted faces, or -1 (@see lastErrorMessage) */ - int (*insertFaces) ( - const LWT_BE_TOPOLOGY* topo, - LWT_ISO_FACE* faces, - uint64_t numelems - ); + int (*insertFaces)(const LWT_BE_TOPOLOGY *topo, LWT_ISO_FACE *faces, uint64_t numelems); /** * Update faces by id @@ -609,10 +581,7 @@ typedef struct LWT_BE_CALLBACKS_T { * walked in their direction, negative ones in opposite) or * NULL on error (@see lastErrorMessage) */ - LWT_ELEMID* (*getRingEdges) ( - const LWT_BE_TOPOLOGY* topo, - LWT_ELEMID edge, uint64_t *numedges, uint64_t limit - ); + LWT_ELEMID *(*getRingEdges)(const LWT_BE_TOPOLOGY *topo, LWT_ELEMID edge, uint64_t *numedges, int limit); /** * Update edges by id @@ -628,11 +597,7 @@ typedef struct LWT_BE_CALLBACKS_T { * @return number of edges being updated or -1 on error * (@see lastErrorMessage) */ - int (*updateEdgesById) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_EDGE* edges, uint64_t numedges, - int upd_fields - ); + int (*updateEdgesById)(const LWT_BE_TOPOLOGY *topo, const LWT_ISO_EDGE *edges, uint64_t numedges, int upd_fields); /** * \brief @@ -654,11 +619,11 @@ typedef struct LWT_BE_CALLBACKS_T { * - no edge found ("numelems" is set to 0) * - error ("numelems" is set to -1) */ - LWT_ISO_EDGE* (*getEdgeByFace) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields, - const GBOX *box - ); + LWT_ISO_EDGE *(*getEdgeByFace)(const LWT_BE_TOPOLOGY *topo, + const LWT_ELEMID *ids, + uint64_t *numelems, + int fields, + const GBOX *box); /** * Get isolated nodes contained in any of the given faces @@ -679,11 +644,11 @@ typedef struct LWT_BE_CALLBACKS_T { * - no nod found ("numelems" is set to 0) * - error ("numelems" is set to -1, @see lastErrorMessage) */ - LWT_ISO_NODE* (*getNodeByFace) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* faces, uint64_t* numelems, int fields, - const GBOX *box - ); + LWT_ISO_NODE *(*getNodeByFace)(const LWT_BE_TOPOLOGY *topo, + const LWT_ELEMID *faces, + uint64_t *numelems, + int fields, + const GBOX *box); /** * Update nodes by id @@ -698,11 +663,7 @@ typedef struct LWT_BE_CALLBACKS_T { * @return number of nodes being updated or -1 on error * (@see lastErrorMessage) */ - int (*updateNodesById) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_NODE* nodes, uint64_t numnodes, - int upd_fields - ); + int (*updateNodesById)(const LWT_BE_TOPOLOGY *topo, const LWT_ISO_NODE *nodes, uint64_t numnodes, int upd_fields); /** * Delete faces by id @@ -714,11 +675,7 @@ typedef struct LWT_BE_CALLBACKS_T { * @return number of faces being deleted or -1 on error * (@see lastErrorMessage) */ - int (*deleteFacesById) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, - uint64_t numelems - ); + int (*deleteFacesById)(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t numelems); /** * Get topology SRID @@ -753,11 +710,7 @@ typedef struct LWT_BE_CALLBACKS_T { * @return number of nodes being deleted or -1 on error * (@see lastErrorMessage) */ - int (*deleteNodesById) ( - const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, - uint64_t numelems - ); + int (*deleteNodesById)(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t numelems); /** * Check TopoGeometry objects before an edge removal event @@ -863,11 +816,11 @@ typedef struct LWT_BE_CALLBACKS_T { * - error ("numelems" is set to -1) * */ - LWT_ISO_FACE* (*getFaceWithinBox2D) ( - const LWT_BE_TOPOLOGY* topo, - const GBOX* box, - uint64_t* numelems, int fields, uint64_t limit - ); + LWT_ISO_FACE *(*getFaceWithinBox2D)(const LWT_BE_TOPOLOGY *topo, + const GBOX *box, + uint64_t *numelems, + int fields, + int limit); } LWT_BE_CALLBACKS; diff --git a/liblwgeom/liblwgeom_topo_internal.h b/liblwgeom/liblwgeom_topo_internal.h index 90c34a274..4f110d4a0 100644 --- a/liblwgeom/liblwgeom_topo_internal.h +++ b/liblwgeom/liblwgeom_topo_internal.h @@ -49,23 +49,29 @@ LWT_BE_TOPOLOGY * lwt_be_loadTopologyByName(LWT_BE_IFACE *be, const char *name); int lwt_be_freeTopology(LWT_TOPOLOGY *topo); -LWT_ISO_NODE* lwt_be_getNodeWithinDistance2D(LWT_TOPOLOGY* topo, LWPOINT* pt, double dist, uint64_t* numelems, int fields, uint64_t limit); +LWT_ISO_NODE *lwt_be_getNodeWithinDistance2D(LWT_TOPOLOGY *topo, + LWPOINT *pt, + double dist, + uint64_t *numelems, + int fields, + uint64_t limit); -LWT_ISO_NODE* lwt_be_getNodeById(LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, uint64_t* numelems, int fields); +LWT_ISO_NODE *lwt_be_getNodeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields); int lwt_be_ExistsCoincidentNode(LWT_TOPOLOGY* topo, LWPOINT* pt); -int lwt_be_insertNodes(LWT_TOPOLOGY* topo, LWT_ISO_NODE* node, uint64_t numelems); +int lwt_be_insertNodes(LWT_TOPOLOGY *topo, LWT_ISO_NODE *node, uint64_t numelems); int lwt_be_ExistsEdgeIntersectingPoint(LWT_TOPOLOGY* topo, LWPOINT* pt); LWT_ELEMID lwt_be_getNextEdgeId(LWT_TOPOLOGY* topo); -LWT_ISO_EDGE* lwt_be_getEdgeById(LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, - uint64_t* numelems, int fields); -LWT_ISO_EDGE* lwt_be_getEdgeWithinDistance2D(LWT_TOPOLOGY* topo, LWPOINT* pt, - double dist, uint64_t* numelems, int fields, - uint64_t limit); -int -lwt_be_insertEdges(LWT_TOPOLOGY* topo, LWT_ISO_EDGE* edge, uint64_t numelems); +LWT_ISO_EDGE *lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields); +LWT_ISO_EDGE *lwt_be_getEdgeWithinDistance2D(LWT_TOPOLOGY *topo, + LWPOINT *pt, + double dist, + uint64_t *numelems, + int fields, + uint64_t limit); +int lwt_be_insertEdges(LWT_TOPOLOGY *topo, LWT_ISO_EDGE *edge, uint64_t numelems); int lwt_be_updateEdges(LWT_TOPOLOGY* topo, const LWT_ISO_EDGE* sel_edge, int sel_fields, const LWT_ISO_EDGE* upd_edge, int upd_fields, const LWT_ISO_EDGE* exc_edge, int exc_fields); int diff --git a/liblwgeom/lwgeom_topo.c b/liblwgeom/lwgeom_topo.c index 838a895b6..6f01a349b 100644 --- a/liblwgeom/lwgeom_topo.c +++ b/liblwgeom/lwgeom_topo.c @@ -151,65 +151,61 @@ lwt_be_freeTopology(LWT_TOPOLOGY *topo) CBT0(topo, freeTopology); } -LWT_ISO_NODE* -lwt_be_getNodeById(LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, - uint64_t* numelems, int fields) +LWT_ISO_NODE * +lwt_be_getNodeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields) { CBT3(topo, getNodeById, ids, numelems, fields); } -LWT_ISO_NODE* -lwt_be_getNodeWithinDistance2D(LWT_TOPOLOGY* topo, LWPOINT* pt, - double dist, uint64_t* numelems, int fields, - uint64_t limit) +LWT_ISO_NODE * +lwt_be_getNodeWithinDistance2D(LWT_TOPOLOGY *topo, + LWPOINT *pt, + double dist, + uint64_t *numelems, + int fields, + uint64_t limit) { CBT5(topo, getNodeWithinDistance2D, pt, dist, numelems, fields, limit); } -static LWT_ISO_NODE* -lwt_be_getNodeWithinBox2D( const LWT_TOPOLOGY* topo, - const GBOX* box, uint64_t* numelems, int fields, - uint64_t limit ) +static LWT_ISO_NODE * +lwt_be_getNodeWithinBox2D(const LWT_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, uint64_t limit) { CBT4(topo, getNodeWithinBox2D, box, numelems, fields, limit); } -static LWT_ISO_EDGE* -lwt_be_getEdgeWithinBox2D( const LWT_TOPOLOGY* topo, - const GBOX* box, uint64_t* numelems, int fields, - uint64_t limit ) +static LWT_ISO_EDGE * +lwt_be_getEdgeWithinBox2D(const LWT_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, uint64_t limit) { CBT4(topo, getEdgeWithinBox2D, box, numelems, fields, limit); } -static LWT_ISO_FACE* -lwt_be_getFaceWithinBox2D( const LWT_TOPOLOGY* topo, - const GBOX* box, uint64_t* numelems, int fields, - uint64_t limit ) +static LWT_ISO_FACE * +lwt_be_getFaceWithinBox2D(const LWT_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, uint64_t limit) { CBT4(topo, getFaceWithinBox2D, box, numelems, fields, limit); } int -lwt_be_insertNodes(LWT_TOPOLOGY* topo, LWT_ISO_NODE* node, uint64_t numelems) +lwt_be_insertNodes(LWT_TOPOLOGY *topo, LWT_ISO_NODE *node, uint64_t numelems) { CBT2(topo, insertNodes, node, numelems); } static int -lwt_be_insertFaces(LWT_TOPOLOGY* topo, LWT_ISO_FACE* face, uint64_t numelems) +lwt_be_insertFaces(LWT_TOPOLOGY *topo, LWT_ISO_FACE *face, uint64_t numelems) { CBT2(topo, insertFaces, face, numelems); } static int -lwt_be_deleteFacesById(const LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, uint64_t numelems) +lwt_be_deleteFacesById(const LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t numelems) { CBT2(topo, deleteFacesById, ids, numelems); } static int -lwt_be_deleteNodesById(const LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, uint64_t numelems) +lwt_be_deleteNodesById(const LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t numelems) { CBT2(topo, deleteNodesById, ids, numelems); } @@ -220,51 +216,49 @@ lwt_be_getNextEdgeId(LWT_TOPOLOGY* topo) CBT0(topo, getNextEdgeId); } -LWT_ISO_EDGE* -lwt_be_getEdgeById(LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, - uint64_t* numelems, int fields) +LWT_ISO_EDGE * +lwt_be_getEdgeById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields) { CBT3(topo, getEdgeById, ids, numelems, fields); } -static LWT_ISO_FACE* -lwt_be_getFaceById(LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, - uint64_t* numelems, int fields) +static LWT_ISO_FACE * +lwt_be_getFaceById(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields) { CBT3(topo, getFaceById, ids, numelems, fields); } -static LWT_ISO_EDGE* -lwt_be_getEdgeByNode(LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, - uint64_t* numelems, int fields) +static LWT_ISO_EDGE * +lwt_be_getEdgeByNode(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields) { CBT3(topo, getEdgeByNode, ids, numelems, fields); } -static LWT_ISO_EDGE* -lwt_be_getEdgeByFace(LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, - uint64_t* numelems, int fields, const GBOX *box) +static LWT_ISO_EDGE * +lwt_be_getEdgeByFace(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields, const GBOX *box) { CBT4(topo, getEdgeByFace, ids, numelems, fields, box); } -static LWT_ISO_NODE* -lwt_be_getNodeByFace(LWT_TOPOLOGY* topo, const LWT_ELEMID* ids, - uint64_t* numelems, int fields, const GBOX *box) +static LWT_ISO_NODE * +lwt_be_getNodeByFace(LWT_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields, const GBOX *box) { CBT4(topo, getNodeByFace, ids, numelems, fields, box); } -LWT_ISO_EDGE* -lwt_be_getEdgeWithinDistance2D(LWT_TOPOLOGY* topo, LWPOINT* pt, - double dist, uint64_t* numelems, int fields, - uint64_t limit) +LWT_ISO_EDGE * +lwt_be_getEdgeWithinDistance2D(LWT_TOPOLOGY *topo, + LWPOINT *pt, + double dist, + uint64_t *numelems, + int fields, + uint64_t limit) { CBT5(topo, getEdgeWithinDistance2D, pt, dist, numelems, fields, limit); } int -lwt_be_insertEdges(LWT_TOPOLOGY* topo, LWT_ISO_EDGE* edge, uint64_t numelems) +lwt_be_insertEdges(LWT_TOPOLOGY *topo, LWT_ISO_EDGE *edge, uint64_t numelems) { CBT2(topo, insertEdges, edge, numelems); } @@ -375,9 +369,8 @@ lwt_be_updateTopoGeomEdgeHeal(LWT_TOPOLOGY* topo, CBT3(topo, updateTopoGeomEdgeHeal, edge1, edge2, newedge); } -static LWT_ELEMID* -lwt_be_getRingEdges( LWT_TOPOLOGY* topo, - LWT_ELEMID edge, uint64_t *numedges, uint64_t limit ) +static LWT_ELEMID * +lwt_be_getRingEdges(LWT_TOPOLOGY *topo, LWT_ELEMID edge, uint64_t *numedges, uint64_t limit) { CBT3(topo, getRingEdges, edge, numedges, limit); } @@ -388,24 +381,26 @@ lwt_be_getRingEdges( LWT_TOPOLOGY* topo, int lwt_be_ExistsCoincidentNode(LWT_TOPOLOGY* topo, LWPOINT* pt) { - uint64_t exists = 0; - lwt_be_getNodeWithinDistance2D(topo, pt, 0, &exists, 0, -1); - if ( exists == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return 0; - } + uint64_t exists = 0; + lwt_be_getNodeWithinDistance2D(topo, pt, 0, &exists, 0, -1); + if (exists == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return 0; + } return exists; } int lwt_be_ExistsEdgeIntersectingPoint(LWT_TOPOLOGY* topo, LWPOINT* pt) { - uint64_t exists = 0; - lwt_be_getEdgeWithinDistance2D(topo, pt, 0, &exists, 0, -1); - if ( exists == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return 0; - } + uint64_t exists = 0; + lwt_be_getEdgeWithinDistance2D(topo, pt, 0, &exists, 0, -1); + if (exists == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return 0; + } return exists; } @@ -601,28 +596,30 @@ _lwt_CheckEdgeCrossing( LWT_TOPOLOGY* topo, LWT_ELEMID start_node, LWT_ELEMID end_node, const LWLINE *geom, LWT_ELEMID myself ) { - uint64_t i, num_nodes, num_edges; - LWT_ISO_EDGE *edges; - LWT_ISO_NODE *nodes; - const GBOX *edgebox; - GEOSGeometry *edgegg; + uint64_t i, num_nodes, num_edges; + LWT_ISO_EDGE *edges; + LWT_ISO_NODE *nodes; + const GBOX *edgebox; + GEOSGeometry *edgegg; - initGEOS(lwnotice, lwgeom_geos_error); + initGEOS(lwnotice, lwgeom_geos_error); - edgegg = LWGEOM2GEOS( lwline_as_lwgeom(geom), 0); - if ( ! edgegg ) { - lwerror("Could not convert edge geometry to GEOS: %s", lwgeom_geos_errmsg); - return -1; - } + edgegg = LWGEOM2GEOS(lwline_as_lwgeom(geom), 0); + if (!edgegg) + { + lwerror("Could not convert edge geometry to GEOS: %s", lwgeom_geos_errmsg); + return -1; + } edgebox = lwgeom_get_bbox( lwline_as_lwgeom(geom) ); /* loop over each node within the edge's gbox */ nodes = lwt_be_getNodeWithinBox2D( topo, edgebox, &num_nodes, LWT_COL_NODE_ALL, 0 ); LWDEBUGF(1, "lwt_be_getNodeWithinBox2D returned %d nodes", num_nodes); - if ( num_nodes == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; + if (num_nodes == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } for ( i=0; ibe_iface)); - return -1; + if (num_edges == UINT64_MAX) + { + GEOSGeom_destroy(edgegg); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } for ( i=0; ibe_iface)); return -1; @@ -945,7 +943,7 @@ _lwt_EdgeSplit( LWT_TOPOLOGY* topo, LWT_ELEMID edge, LWPOINT* pt, int skipISOChe if ( ! *oldedge ) { LWDEBUGF(1, "lwt_be_getEdgeById returned NULL and set i=%d", i); - if ( i == UINT64_MAX ) + if (i == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return NULL; @@ -1516,9 +1514,10 @@ _lwt_FindAdjacentEdges( LWT_TOPOLOGY* topo, LWT_ELEMID node, edgeend *data, /* Get incident edges */ edges = lwt_be_getEdgeByNode( topo, &node, &numedges, LWT_COL_EDGE_ALL ); - if ( numedges == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return 0; + if (numedges == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return 0; } LWDEBUGF(1, "getEdgeByNode returned %d edges, minaz=%g, maxaz=%g", @@ -1764,7 +1763,7 @@ _lwt_MakeRingShell(LWT_TOPOLOGY *topo, LWT_ELEMID *signed_edge_ids, uint64_t num ring_edges = lwt_be_getEdgeById(topo, edge_ids, &i, LWT_COL_EDGE_EDGE_ID|LWT_COL_EDGE_GEOM); lwfree( edge_ids ); - if ( i == UINT64_MAX ) + if (i == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return NULL; @@ -1856,23 +1855,24 @@ _lwt_AddFaceSplit( LWT_TOPOLOGY* topo, LWT_ELEMID sedge, LWT_ELEMID face, int mbr_only ) { - uint64_t numfaceedges, i, j; - int newface_outside; - uint64_t num_signed_edge_ids; - LWT_ELEMID *signed_edge_ids; - LWT_ISO_EDGE *edges; - LWT_ISO_EDGE *forward_edges = NULL; - int forward_edges_count = 0; - LWT_ISO_EDGE *backward_edges = NULL; - int backward_edges_count = 0; - - 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 %" LWTFMT_ELEMID "): %s", - sedge, lwt_be_lastErrorMessage(topo->be_iface)); - return -2; - } + uint64_t numfaceedges, i, j; + int newface_outside; + uint64_t num_signed_edge_ids; + LWT_ELEMID *signed_edge_ids; + LWT_ISO_EDGE *edges; + LWT_ISO_EDGE *forward_edges = NULL; + int forward_edges_count = 0; + LWT_ISO_EDGE *backward_edges = NULL; + int backward_edges_count = 0; + + 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 %" LWTFMT_ELEMID "): %s", + sedge, + lwt_be_lastErrorMessage(topo->be_iface)); + return -2; + } LWDEBUGF(1, "getRingEdges returned %d edges", num_signed_edge_ids); /* You can't get to the other side of an edge forming a ring */ @@ -1956,7 +1956,7 @@ _lwt_AddFaceSplit( LWT_TOPOLOGY* topo, /* Face created an hole in an outer face */ uint64_t nfaces = 1; oldface = lwt_be_getFaceById(topo, &face, &nfaces, LWT_COL_FACE_ALL); - if ( nfaces == UINT64_MAX ) + if (nfaces == UINT64_MAX) { lwfree( signed_edge_ids ); lwpoly_free(shell); /* NOTE: owns shellbox */ @@ -2021,10 +2021,11 @@ _lwt_AddFaceSplit( LWT_TOPOLOGY* topo, ; numfaceedges = 1; edges = lwt_be_getEdgeByFace( topo, &face, &numfaceedges, fields, newface.mbr ); - if ( numfaceedges == UINT64_MAX ) { - lwfree( signed_edge_ids ); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -2; + if (numfaceedges == UINT64_MAX) + { + lwfree(signed_edge_ids); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -2; } LWDEBUGF(1, "lwt_be_getEdgeByFace returned %d edges", numfaceedges); @@ -2183,10 +2184,11 @@ _lwt_AddFaceSplit( LWT_TOPOLOGY* topo, fields = LWT_COL_NODE_NODE_ID | LWT_COL_NODE_GEOM; LWT_ISO_NODE *nodes = lwt_be_getNodeByFace(topo, &face, &numisonodes, fields, newface.mbr); - if ( numisonodes == UINT64_MAX ) { - lwfree( signed_edge_ids ); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -2; + if (numisonodes == UINT64_MAX) + { + lwfree(signed_edge_ids); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -2; } if ( numisonodes ) { LWT_ISO_NODE *updated_nodes = lwalloc(sizeof(LWT_ISO_NODE)*numisonodes); @@ -2349,9 +2351,10 @@ _lwt_AddEdge( LWT_TOPOLOGY* topo, } endpoints = lwt_be_getNodeById( topo, node_ids, &num_nodes, LWT_COL_NODE_ALL ); - if ( num_nodes == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; + if (num_nodes == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } for ( i=0; ibe_iface)); - return NULL; + if (numfaceedges == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return NULL; } if ( numfaceedges == 0 ) { i = 1; face = lwt_be_getFaceById(topo, &faceid, &i, LWT_COL_FACE_FACE_ID); - if ( i == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return NULL; + if (i == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return NULL; } if ( i == 0 ) { lwerror("SQL/MM Spatial exception - non-existent face."); @@ -3023,9 +3028,10 @@ lwt_GetFaceEdges(LWT_TOPOLOGY* topo, LWT_ELEMID face_id, LWT_ELEMID **out ) LWT_COL_EDGE_FACE_RIGHT ; edges = lwt_be_getEdgeByFace( topo, &face_id, &numfaceedges, fields, NULL ); - if ( numfaceedges == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; + if (numfaceedges == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } if ( ! numfaceedges ) return 0; /* no edges in output */ @@ -3188,7 +3194,7 @@ lwt_ChangeEdgeGeom(LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, LWLINE *geom) { LWDEBUGF(1, "lwt_ChangeEdgeGeom: " "lwt_be_getEdgeById returned NULL and set i=%d", i); - if ( i == UINT64_MAX ) + if (i == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -3305,10 +3311,11 @@ lwt_ChangeEdgeGeom(LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, LWLINE *geom) nodes = lwt_be_getNodeWithinBox2D(topo, &mbox, &numnodes, LWT_COL_NODE_ALL, 0); LWDEBUGF(1, "lwt_be_getNodeWithinBox2D returned %d nodes", numnodes); - if ( numnodes == UINT64_MAX ) { - _lwt_release_edges(oldedge, 1); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; + if (numnodes == UINT64_MAX) + { + _lwt_release_edges(oldedge, 1); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } // 3. if any node beside endnodes are found: if ( numnodes > ( 1 + isclosed ? 0 : 1 ) ) @@ -3344,9 +3351,9 @@ lwt_ChangeEdgeGeom(LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, LWLINE *geom) edgeend span_pre, epan_pre; /* initialize span_pre.myaz and epan_pre.myaz with existing edge */ - int res = _lwt_InitEdgeEndByLine(&span_pre, &epan_pre, - oldedge->geom, &p1, &p2); - if ( res ) return -1; /* lwerror should have been raised */ + int res = _lwt_InitEdgeEndByLine(&span_pre, &epan_pre, oldedge->geom, &p1, &p2); + if (res) + return -1; /* lwerror should have been raised */ _lwt_FindAdjacentEdges( topo, oldedge->start_node, &span_pre, isclosed ? &epan_pre : NULL, edge_id ); _lwt_FindAdjacentEdges( topo, oldedge->end_node, &epan_pre, @@ -3362,13 +3369,13 @@ lwt_ChangeEdgeGeom(LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, LWLINE *geom) newedge.edge_id = edge_id; newedge.geom = geom; res = lwt_be_updateEdgesById(topo, &newedge, 1, LWT_COL_EDGE_GEOM); - if ( res == -1 ) + if (res == -1) { _lwt_release_edges(oldedge, 1); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; } - if ( ! res ) + if (!res) { _lwt_release_edges(oldedge, 1); lwerror("Unexpected error: %d edges updated when expecting 1", i); @@ -3380,11 +3387,12 @@ lwt_ChangeEdgeGeom(LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, LWLINE *geom) */ edgeend span_post, epan_post; res = _lwt_InitEdgeEndByLine(&span_post, &epan_post, geom, &p1, &p2); - if ( res ) return -1; /* lwerror should have been raised */ + if (res) + return -1; /* lwerror should have been raised */ /* initialize epan_post.myaz and epan_post.myaz */ - res = _lwt_InitEdgeEndByLine(&span_post, &epan_post, - geom, &p1, &p2); - if ( res ) return -1; /* lwerror should have been raised */ + res = _lwt_InitEdgeEndByLine(&span_post, &epan_post, geom, &p1, &p2); + if (res) + return -1; /* lwerror should have been raised */ _lwt_FindAdjacentEdges( topo, oldedge->start_node, &span_post, isclosed ? &epan_post : NULL, edge_id ); _lwt_FindAdjacentEdges( topo, oldedge->end_node, &epan_post, @@ -3485,18 +3493,20 @@ lwt_ChangeEdgeGeom(LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, LWLINE *geom) LWDEBUGF(1, "%d faces to update", facestoupdate); if ( facestoupdate ) { - res = lwt_be_updateFacesById( topo, &(faces[0]), facestoupdate ); - if ( res != facestoupdate ) - { - if ( nface1 ) lwgeom_free(nface1); - if ( nface2 ) lwgeom_free(nface2); - _lwt_release_edges(oldedge, 1); - if ( res == -1 ) - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - else - lwerror("Unexpected error: %d faces found when expecting 1", i); - return -1; - } + res = lwt_be_updateFacesById(topo, &(faces[0]), facestoupdate); + if (res != facestoupdate) + { + if (nface1) + lwgeom_free(nface1); + if (nface2) + lwgeom_free(nface2); + _lwt_release_edges(oldedge, 1); + if (res == -1) + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + else + lwerror("Unexpected error: %d faces found when expecting 1", i); + return -1; + } } if ( nface1 ) lwgeom_free(nface1); if ( nface2 ) lwgeom_free(nface2); @@ -3518,9 +3528,10 @@ _lwt_GetIsoNode(LWT_TOPOLOGY* topo, LWT_ELEMID nid) uint64_t n = 1; node = lwt_be_getNodeById( topo, &nid, &n, LWT_COL_NODE_CONTAINING_FACE ); - if ( n == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return 0; + if (n == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return 0; } if ( n < 1 ) { lwerror("SQL/MM Spatial exception - non-existent node"); @@ -3673,7 +3684,7 @@ lwt_RemIsoEdge(LWT_TOPOLOGY* topo, LWT_ELEMID id) deledge.edge_id = id; n = lwt_be_deleteEdges( topo, &deledge, LWT_COL_EDGE_EDGE_ID ); - if ( n == UINT64_MAX ) + if (n == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -3694,7 +3705,7 @@ lwt_RemIsoEdge(LWT_TOPOLOGY* topo, LWT_ELEMID id) } n = lwt_be_updateNodesById(topo, upd_node, n, LWT_COL_NODE_CONTAINING_FACE); - if ( n == UINT64_MAX ) + if (n == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -3774,50 +3785,51 @@ _lwt_UpdateNodeFaceRef( LWT_TOPOLOGY *topo, LWT_ELEMID of, LWT_ELEMID nf) static LWT_ELEMID _lwt_RemEdge( LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, int modFace ) { - uint64_t i, nedges, nfaces, fields; - LWT_ISO_EDGE *edge = NULL; - LWT_ISO_EDGE *upd_edge = NULL; - LWT_ISO_EDGE upd_edge_left[2]; - int nedge_left = 0; - LWT_ISO_EDGE upd_edge_right[2]; - int nedge_right = 0; - LWT_ISO_NODE upd_node[2]; - int nnode = 0; - LWT_ISO_FACE *faces = NULL; - LWT_ISO_FACE newface; - LWT_ELEMID node_ids[2]; - LWT_ELEMID face_ids[2]; - int fnode_edges = 0; /* number of edges on the first node (excluded - * the one being removed ) */ - int lnode_edges = 0; /* number of edges on the last node (excluded - * the one being removed ) */ - - newface.face_id = 0; - - i = 1; - edge = lwt_be_getEdgeById(topo, &edge_id, &i, LWT_COL_EDGE_ALL); - if ( ! edge ) - { - LWDEBUGF(1, "lwt_be_getEdgeById returned NULL and set i=%d", i); - if ( i == UINT64_MAX ) - { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; - } - else if ( i == 0 ) - { - lwerror("SQL/MM Spatial exception - non-existent edge %" - LWTFMT_ELEMID, edge_id); - return -1; - } - else - { - lwerror("Backend coding error: getEdgeById callback returned NULL " - "but numelements output parameter has value %d " - "(expected 0 or 1)", i); - return -1; - } - } + uint64_t i, nedges, nfaces, fields; + LWT_ISO_EDGE *edge = NULL; + LWT_ISO_EDGE *upd_edge = NULL; + LWT_ISO_EDGE upd_edge_left[2]; + int nedge_left = 0; + LWT_ISO_EDGE upd_edge_right[2]; + int nedge_right = 0; + LWT_ISO_NODE upd_node[2]; + int nnode = 0; + LWT_ISO_FACE *faces = NULL; + LWT_ISO_FACE newface; + LWT_ELEMID node_ids[2]; + LWT_ELEMID face_ids[2]; + int fnode_edges = 0; /* number of edges on the first node (excluded + * the one being removed ) */ + int lnode_edges = 0; /* number of edges on the last node (excluded + * the one being removed ) */ + + newface.face_id = 0; + + i = 1; + edge = lwt_be_getEdgeById(topo, &edge_id, &i, LWT_COL_EDGE_ALL); + if (!edge) + { + LWDEBUGF(1, "lwt_be_getEdgeById returned NULL and set i=%d", i); + if (i == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; + } + else if (i == 0) + { + lwerror("SQL/MM Spatial exception - non-existent edge %" LWTFMT_ELEMID, edge_id); + return -1; + } + else + { + lwerror( + "Backend coding error: getEdgeById callback returned NULL " + "but numelements output parameter has value %d " + "(expected 0 or 1)", + i); + return -1; + } + } if ( ! lwt_be_checkTopoGeomRemEdge(topo, edge_id, edge->face_left, edge->face_right) ) @@ -3840,9 +3852,10 @@ _lwt_RemEdge( LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, int modFace ) LWT_COL_EDGE_END_NODE | LWT_COL_EDGE_NEXT_LEFT | LWT_COL_EDGE_NEXT_RIGHT; upd_edge = lwt_be_getEdgeByNode( topo, &(node_ids[0]), &nedges, fields ); - if ( nedges == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; + if (nedges == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } nedge_left = nedge_right = 0; for ( i=0; ibe_iface)); - return -1; + if (nfaces == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } GBOX *box1=NULL; GBOX *box2=NULL; @@ -4011,38 +4023,38 @@ _lwt_RemEdge( LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, int modFace ) if ( modFace ) { newface.face_id = floodface; - int result = lwt_be_updateFacesById( topo, &newface, 1 ); - _lwt_release_faces(faces, 2); - if ( result == -1 ) - { - _lwt_release_edges(edge, 1); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; - } - if ( result != 1 ) - { - _lwt_release_edges(edge, 1); - lwerror("Unexpected error: %d faces updated when expecting 1", i); - return -1; - } + int result = lwt_be_updateFacesById(topo, &newface, 1); + _lwt_release_faces(faces, 2); + if (result == -1) + { + _lwt_release_edges(edge, 1); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; + } + if (result != 1) + { + _lwt_release_edges(edge, 1); + lwerror("Unexpected error: %d faces updated when expecting 1", i); + return -1; + } } else { /* New face replaces the old two faces */ newface.face_id = -1; - int result = lwt_be_insertFaces( topo, &newface, 1 ); - _lwt_release_faces(faces, 2); - if ( result == -1 ) - { - _lwt_release_edges(edge, 1); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; - } - if ( i != 1 ) - { + int result = lwt_be_insertFaces(topo, &newface, 1); + _lwt_release_faces(faces, 2); + if (result == -1) + { + _lwt_release_edges(edge, 1); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; + } + if (result != 1) + { _lwt_release_edges(edge, 1); - lwerror("Unexpected error: %d faces inserted when expecting 1", i); - return -1; + lwerror("Unexpected error: %d faces inserted when expecting 1", result); + return -1; } floodface = newface.face_id; } @@ -4096,10 +4108,11 @@ _lwt_RemEdge( LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, int modFace ) /* Delete the edge */ int result = lwt_be_deleteEdges(topo, edge, LWT_COL_EDGE_EDGE_ID); - if ( result == -1 ) { - _lwt_release_edges(edge, 1); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; + if (result == -1) + { + _lwt_release_edges(edge, 1); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } /* If any of the edge nodes remained isolated, set @@ -4119,13 +4132,13 @@ _lwt_RemEdge( LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, int modFace ) } if ( nnode ) { - int result = lwt_be_updateNodesById(topo, upd_node, nnode, - LWT_COL_NODE_CONTAINING_FACE); - if ( result == -1 ) { - _lwt_release_edges(edge, 1); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; - } + int result = lwt_be_updateNodesById(topo, upd_node, nnode, LWT_COL_NODE_CONTAINING_FACE); + if (result == -1) + { + _lwt_release_edges(edge, 1); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; + } } if ( edge->face_left != edge->face_right ) @@ -4138,10 +4151,11 @@ _lwt_RemEdge( LWT_TOPOLOGY* topo, LWT_ELEMID edge_id, int modFace ) if ( edge->face_left != floodface ) ids[nids++] = edge->face_left; int result = lwt_be_deleteFacesById(topo, ids, nids); - if ( result == -1 ) { - _lwt_release_edges(edge, 1); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; + if (result == -1) + { + _lwt_release_edges(edge, 1); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } } @@ -4272,10 +4286,11 @@ _lwt_HealEdges( LWT_TOPOLOGY* topo, LWT_ELEMID eid1, LWT_ELEMID eid2, num_node_edges = 1; node_edges = lwt_be_getEdgeByNode( topo, &commonnode, &num_node_edges, LWT_COL_EDGE_EDGE_ID ); - if ( num_node_edges == UINT64_MAX ) { - _lwt_release_edges(edges, nedges); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; + if (num_node_edges == UINT64_MAX) + { + _lwt_release_edges(edges, nedges); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } for (i=0; ibe_iface)); - return -1; + if (num_node_edges == UINT64_MAX) + { + _lwt_release_edges(edges, nedges); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } for (i=0; ibe_iface)); return -1; } - else if ( result != 1 ) + else if (result != 1) { lwline_free(newedge.geom); if ( edges ) _lwt_release_edges(edges, nedges); @@ -4481,16 +4496,19 @@ _lwt_HealEdges( LWT_TOPOLOGY* topo, LWT_ELEMID eid1, LWT_ELEMID eid2, newedge.face_left = e1->face_left; newedge.face_right = e1->face_right; int result = lwt_be_insertEdges(topo, &newedge, 1); - if ( result == -1 ) { - lwline_free(newedge.geom); - _lwt_release_edges(edges, nedges); - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; - } else if ( result == 0 ) { - lwline_free(newedge.geom); - _lwt_release_edges(edges, nedges); - lwerror("Insertion of split edge failed (no reason)"); - return -1; + if (result == -1) + { + lwline_free(newedge.geom); + _lwt_release_edges(edges, nedges); + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; + } + else if (result == 0) + { + lwline_free(newedge.geom); + _lwt_release_edges(edges, nedges); + lwerror("Insertion of split edge failed (no reason)"); + return -1; } } lwline_free(newedge.geom); @@ -4512,10 +4530,8 @@ _lwt_HealEdges( LWT_TOPOLOGY* topo, LWT_ELEMID eid1, LWT_ELEMID eid2, /* update edges connected to e2's boundary from their end node */ seledge.next_left = e2freenode * eid2; updedge.next_left = e2freenode * newedge.edge_id * e2sign; - int result = lwt_be_updateEdges(topo, &seledge, LWT_COL_EDGE_NEXT_LEFT, - &updedge, LWT_COL_EDGE_NEXT_LEFT, - NULL, 0); - if ( result == -1 ) + int result = lwt_be_updateEdges(topo, &seledge, LWT_COL_EDGE_NEXT_LEFT, &updedge, LWT_COL_EDGE_NEXT_LEFT, NULL, 0); + if (result == -1) { _lwt_release_edges(edges, nedges); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); @@ -4525,10 +4541,8 @@ _lwt_HealEdges( LWT_TOPOLOGY* topo, LWT_ELEMID eid1, LWT_ELEMID eid2, /* update edges connected to e2's boundary from their start node */ seledge.next_right = e2freenode * eid2; updedge.next_right = e2freenode * newedge.edge_id * e2sign; - result = lwt_be_updateEdges(topo, &seledge, LWT_COL_EDGE_NEXT_RIGHT, - &updedge, LWT_COL_EDGE_NEXT_RIGHT, - NULL, 0); - if ( result == -1 ) + result = lwt_be_updateEdges(topo, &seledge, LWT_COL_EDGE_NEXT_RIGHT, &updedge, LWT_COL_EDGE_NEXT_RIGHT, NULL, 0); + if (result == -1) { _lwt_release_edges(edges, nedges); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); @@ -4540,10 +4554,8 @@ _lwt_HealEdges( LWT_TOPOLOGY* topo, LWT_ELEMID eid1, LWT_ELEMID eid2, /* update edges connected to e1's boundary from their end node */ seledge.next_left = e1freenode * eid1; updedge.next_left = e1freenode * newedge.edge_id; - result = lwt_be_updateEdges(topo, &seledge, LWT_COL_EDGE_NEXT_LEFT, - &updedge, LWT_COL_EDGE_NEXT_LEFT, - NULL, 0); - if ( result == -1 ) + result = lwt_be_updateEdges(topo, &seledge, LWT_COL_EDGE_NEXT_LEFT, &updedge, LWT_COL_EDGE_NEXT_LEFT, NULL, 0); + if (result == -1) { _lwt_release_edges(edges, nedges); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); @@ -4553,10 +4565,8 @@ _lwt_HealEdges( LWT_TOPOLOGY* topo, LWT_ELEMID eid1, LWT_ELEMID eid2, /* update edges connected to e1's boundary from their start node */ seledge.next_right = e1freenode * eid1; updedge.next_right = e1freenode * newedge.edge_id; - result = lwt_be_updateEdges(topo, &seledge, LWT_COL_EDGE_NEXT_RIGHT, - &updedge, LWT_COL_EDGE_NEXT_RIGHT, - NULL, 0); - if ( result == -1 ) + result = lwt_be_updateEdges(topo, &seledge, LWT_COL_EDGE_NEXT_RIGHT, &updedge, LWT_COL_EDGE_NEXT_RIGHT, NULL, 0); + if (result == -1) { _lwt_release_edges(edges, nedges); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); @@ -4566,7 +4576,7 @@ _lwt_HealEdges( LWT_TOPOLOGY* topo, LWT_ELEMID eid1, LWT_ELEMID eid2, /* delete the edges (only second on modEdge or both) */ result = lwt_be_deleteEdges(topo, e2, LWT_COL_EDGE_EDGE_ID); - if ( result == -1 ) + if (result == -1) { _lwt_release_edges(edges, nedges); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); @@ -4574,7 +4584,7 @@ _lwt_HealEdges( LWT_TOPOLOGY* topo, LWT_ELEMID eid1, LWT_ELEMID eid2, } if ( ! modEdge ) { i = lwt_be_deleteEdges(topo, e1, LWT_COL_EDGE_EDGE_ID); - if ( result == -1 ) + if (result == -1) { _lwt_release_edges(edges, nedges); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); @@ -4586,7 +4596,7 @@ _lwt_HealEdges( LWT_TOPOLOGY* topo, LWT_ELEMID eid1, LWT_ELEMID eid2, /* delete the common node */ i = lwt_be_deleteNodesById( topo, &commonnode, 1 ); - if ( result == -1 ) + if (result == -1) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -4637,7 +4647,7 @@ lwt_GetNodeByPoint(LWT_TOPOLOGY *topo, LWPOINT *pt, double tol) return -1; } elem = lwt_be_getNodeWithinDistance2D(topo, pt, tol, &num, flds, 0); - if ( num == UINT64_MAX ) + if (num == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -4672,7 +4682,7 @@ lwt_GetEdgeByPoint(LWT_TOPOLOGY *topo, LWPOINT *pt, double tol) return -1; } elem = lwt_be_getEdgeWithinDistance2D(topo, pt, tol, &num, flds, 0); - if ( num == UINT64_MAX ) + if (num == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -4745,7 +4755,7 @@ lwt_GetFaceByPoint(LWT_TOPOLOGY *topo, LWPOINT *pt, double tol) /* NOTE: we never pass a tolerance of 0 to avoid ever using * ST_Within, which doesn't include endpoints matches */ elem = lwt_be_getEdgeWithinDistance2D(topo, pt, tol?tol:1e-5, &num, flds, 0); - if ( num == UINT64_MAX ) + if (num == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -4885,32 +4895,33 @@ static LWT_ELEMID _lwt_AddPoint(LWT_TOPOLOGY* topo, LWPOINT* point, double tol, int findFace, int *moved) { - uint64_t num, i; - double mindist = FLT_MAX; - LWT_ISO_NODE *nodes, *nodes2; - LWT_ISO_EDGE *edges, *edges2; - LWGEOM *pt = lwpoint_as_lwgeom(point); - int flds; - LWT_ELEMID id = 0; - scored_pointer *sorted; - - /* Get tolerance, if 0 was given */ - if ( ! tol ) tol = _LWT_MINTOLERANCE( topo, pt ); - - LWDEBUGG(1, pt, "Adding point"); - - /* - -- 1. Check if any existing node is closer than the given precision - -- and if so pick the closest - TODO: use WithinBox2D - */ - flds = LWT_COL_NODE_NODE_ID|LWT_COL_NODE_GEOM; - nodes = lwt_be_getNodeWithinDistance2D(topo, point, tol, &num, flds, 0); - if ( num == UINT64_MAX ) - { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; - } + uint64_t num, i; + double mindist = FLT_MAX; + LWT_ISO_NODE *nodes, *nodes2; + LWT_ISO_EDGE *edges, *edges2; + LWGEOM *pt = lwpoint_as_lwgeom(point); + int flds; + LWT_ELEMID id = 0; + scored_pointer *sorted; + + /* Get tolerance, if 0 was given */ + if (!tol) + tol = _LWT_MINTOLERANCE(topo, pt); + + LWDEBUGG(1, pt, "Adding point"); + + /* + -- 1. Check if any existing node is closer than the given precision + -- and if so pick the closest + TODO: use WithinBox2D + */ + flds = LWT_COL_NODE_NODE_ID | LWT_COL_NODE_GEOM; + nodes = lwt_be_getNodeWithinDistance2D(topo, point, tol, &num, flds, 0); + if (num == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; + } if ( num ) { LWDEBUGF(1, "New point is within %.15g units of %d nodes", tol, num); @@ -4968,7 +4979,7 @@ _lwt_AddPoint(LWT_TOPOLOGY* topo, LWPOINT* point, double tol, int */ flds = LWT_COL_EDGE_EDGE_ID|LWT_COL_EDGE_GEOM; edges = lwt_be_getEdgeWithinDistance2D(topo, point, tol, &num, flds, 0); - if ( num == UINT64_MAX ) + if (num == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -5215,7 +5226,7 @@ _lwt_GetEqualEdge( LWT_TOPOLOGY *topo, LWLINE *edge ) const int flds = LWT_COL_EDGE_EDGE_ID|LWT_COL_EDGE_GEOM; edges = lwt_be_getEdgeWithinBox2D( topo, qbox, &num, flds, 0 ); - if ( num == UINT64_MAX ) + if (num == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -5333,7 +5344,7 @@ _lwt_AddLineEdge( LWT_TOPOLOGY* topo, LWLINE* edge, double tol, nn = nid[0] == nid[1] ? 1 : 2; node = lwt_be_getNodeById( topo, nid, &nn, LWT_COL_NODE_NODE_ID|LWT_COL_NODE_GEOM ); - if ( nn == UINT64_MAX ) + if (nn == UINT64_MAX) { lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); return -1; @@ -5496,7 +5507,7 @@ _lwt_AddLine(LWT_TOPOLOGY* topo, LWLINE* line, double tol, int* nedges, LWT_ELEMID *ids; LWT_ISO_EDGE *edges; LWT_ISO_NODE *nodes; - uint64_t num, numedges=0, numnodes=0; + uint64_t num, numedges = 0, numnodes = 0; uint64_t i; GBOX qbox; @@ -5534,7 +5545,7 @@ _lwt_AddLine(LWT_TOPOLOGY* topo, LWLINE* line, double tol, int* nedges, /* 2. Node to edges falling within tol distance */ edges = lwt_be_getEdgeWithinBox2D( topo, &qbox, &numedges, LWT_COL_EDGE_ALL, 0 ); - if ( numedges == UINT64_MAX ) + if (numedges == UINT64_MAX) { lwgeom_free(noded); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); @@ -5610,7 +5621,7 @@ _lwt_AddLine(LWT_TOPOLOGY* topo, LWLINE* line, double tol, int* nedges, /* 2.1. Node with existing nodes within tol * TODO: check if we should be only considering _isolated_ nodes! */ nodes = lwt_be_getNodeWithinBox2D( topo, &qbox, &numnodes, LWT_COL_NODE_ALL, 0 ); - if ( numnodes == UINT64_MAX ) + if (numnodes == UINT64_MAX) { lwgeom_free(noded); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); @@ -5821,7 +5832,7 @@ lwt_AddPolygon(LWT_TOPOLOGY* topo, LWPOLY* poly, double tol, int* nfaces) gbox_expand(&qbox, tol); faces = lwt_be_getFaceWithinBox2D( topo, &qbox, &nfacesinbox, LWT_COL_FACE_ALL, 0 ); - if ( nfacesinbox == UINT64_MAX ) + if (nfacesinbox == UINT64_MAX) { lwfree(ids); lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); @@ -6117,9 +6128,10 @@ _lwt_FetchAllEdges(LWT_TOPOLOGY *topo, int *numedges) edge = lwt_be_getEdgeWithinBox2D( topo, NULL, &nelems, fields, 0); *numedges = nelems; - if ( nelems == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return NULL; + if (nelems == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return NULL; } return edge; } @@ -6661,9 +6673,10 @@ _lwt_CheckFacesExist(LWT_TOPOLOGY *topo) qbox.xmin = qbox.ymin = -DBL_MAX; qbox.xmax = qbox.ymax = DBL_MAX; faces = lwt_be_getFaceWithinBox2D( topo, &qbox, &nelems, fields, 1); - if ( nelems == UINT64_MAX ) { - lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); - return -1; + if (nelems == UINT64_MAX) + { + lwerror("Backend error: %s", lwt_be_lastErrorMessage(topo->be_iface)); + return -1; } if ( faces ) _lwt_release_faces(faces, nelems); return nelems; diff --git a/raster/rt_pg/rtpg_gdal.c b/raster/rt_pg/rtpg_gdal.c index 31263a5e7..c4581af9e 100644 --- a/raster/rt_pg/rtpg_gdal.c +++ b/raster/rt_pg/rtpg_gdal.c @@ -417,8 +417,8 @@ Datum RASTER_getGDALDrivers(PG_FUNCTION_ARGS) POSTGIS_RT_DEBUGF(4, "Result %d, Index %d", call_cntr, drv_set2[call_cntr].idx); POSTGIS_RT_DEBUGF(4, "Result %d, Short Name %s", call_cntr, drv_set2[call_cntr].short_name); POSTGIS_RT_DEBUGF(4, "Result %d, Full Name %s", call_cntr, drv_set2[call_cntr].long_name); - POSTGIS_RT_DEBUGF(4, "Result %d, Can Read %s", call_cntr, drv_set2[call_cntr].can_read); - POSTGIS_RT_DEBUGF(4, "Result %d, Can Write %s", call_cntr, drv_set2[call_cntr].can_write); + POSTGIS_RT_DEBUGF(4, "Result %d, Can Read %u", call_cntr, drv_set2[call_cntr].can_read); + POSTGIS_RT_DEBUGF(4, "Result %d, Can Write %u", call_cntr, drv_set2[call_cntr].can_write); POSTGIS_RT_DEBUGF(5, "Result %d, Create Options %s", call_cntr, drv_set2[call_cntr].create_options); /* build a tuple */ diff --git a/raster/rt_pg/rtpg_geometry.c b/raster/rt_pg/rtpg_geometry.c index eafa80c9d..97acc5017 100644 --- a/raster/rt_pg/rtpg_geometry.c +++ b/raster/rt_pg/rtpg_geometry.c @@ -926,8 +926,8 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS) } } #if POSTGIS_DEBUG_LEVEL > 0 - for (i = 0; i < pixtypes_len; i++) - POSTGIS_RT_DEBUGF(3, "RASTER_asRaster: pixtypes[%d] = %d", i, (int) pixtypes[i]); + for (uint32_t u = 0; u < pixtypes_len; u++) + POSTGIS_RT_DEBUGF(3, "RASTER_asRaster: pixtypes[%u] = %u", i, pixtypes[i]); #endif /* value */ @@ -989,8 +989,8 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS) } } #if POSTGIS_DEBUG_LEVEL > 0 - for (i = 0; i < values_len; i++) - POSTGIS_RT_DEBUGF(3, "RASTER_asRaster: values[%d] = %f", i, values[i]); + for (uint32_t u = 0; u < values_len; u++) + POSTGIS_RT_DEBUGF(3, "RASTER_asRaster: values[%u] = %f", i, values[i]); #endif /* nodataval */ @@ -1061,9 +1061,10 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS) } } #if POSTGIS_DEBUG_LEVEL > 0 - for (i = 0; i < nodatavals_len; i++) { - POSTGIS_RT_DEBUGF(3, "RASTER_asRaster: hasnodatas[%d] = %d", i, hasnodatas[i]); - POSTGIS_RT_DEBUGF(3, "RASTER_asRaster: nodatavals[%d] = %f", i, nodatavals[i]); + for (uint32_t u = 0; u < nodatavals_len; u++) + { + POSTGIS_RT_DEBUGF(3, "RASTER_asRaster: hasnodatas[%u] = %d", u, hasnodatas[u]); + POSTGIS_RT_DEBUGF(3, "RASTER_asRaster: nodatavals[%u] = %f", u, nodatavals[u]); } #endif diff --git a/topology/postgis_topology.c b/topology/postgis_topology.c index 37b1e016c..13c9c83d3 100644 --- a/topology/postgis_topology.c +++ b/topology/postgis_topology.c @@ -917,9 +917,8 @@ getNotNullInt32( HeapTuple row, TupleDesc desc, int col, int32 *val ) /* ----------------- Callbacks start here ------------------------ */ -static LWT_ISO_EDGE* -cb_getEdgeById(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields) +static LWT_ISO_EDGE * +cb_getEdgeById(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields) { LWT_ISO_EDGE *edges; int spi_result; @@ -952,7 +951,7 @@ cb_getEdgeById(const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getEdgeById: edge query returned %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_getEdgeById: edge query returned " UINT64_FORMAT " rows", SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -971,9 +970,8 @@ cb_getEdgeById(const LWT_BE_TOPOLOGY* topo, return edges; } -static LWT_ISO_EDGE* -cb_getEdgeByNode(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields) +static LWT_ISO_EDGE * +cb_getEdgeByNode(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields) { LWT_ISO_EDGE *edges; int spi_result; @@ -1015,7 +1013,7 @@ cb_getEdgeByNode(const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getEdgeByNode: edge query returned %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_getEdgeByNode: edge query returned " UINT64_FORMAT " rows", SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -1034,10 +1032,8 @@ cb_getEdgeByNode(const LWT_BE_TOPOLOGY* topo, return edges; } -static LWT_ISO_EDGE* -cb_getEdgeByFace(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields, - const GBOX *box) +static LWT_ISO_EDGE * +cb_getEdgeByFace(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields, const GBOX *box) { LWT_ISO_EDGE *edges; int spi_result; @@ -1096,7 +1092,7 @@ cb_getEdgeByFace(const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getEdgeByFace: edge query returned %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_getEdgeByFace: edge query returned " UINT64_FORMAT " rows", SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -1115,9 +1111,8 @@ cb_getEdgeByFace(const LWT_BE_TOPOLOGY* topo, return edges; } -static LWT_ISO_FACE* -cb_getFacesById(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields) +static LWT_ISO_FACE * +cb_getFacesById(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields) { LWT_ISO_FACE *faces; int spi_result; @@ -1152,7 +1147,7 @@ cb_getFacesById(const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getFaceById: face query returned %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_getFaceById: face query returned " UINT64_FORMAT " rows", SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -1171,9 +1166,8 @@ cb_getFacesById(const LWT_BE_TOPOLOGY* topo, return faces; } -static LWT_ELEMID* -cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, - LWT_ELEMID edge, uint64_t* numelems, uint64_t limit) +static LWT_ELEMID * +cb_getRingEdges(const LWT_BE_TOPOLOGY *topo, LWT_ELEMID edge, uint64_t *numelems, int limit) { LWT_ELEMID *edges; int spi_result; @@ -1199,10 +1193,10 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, if ( limit ) { ++limit; /* so we know if we hit it */ - appendStringInfo(sql, " LIMIT " UINT64_FORMAT, limit); + appendStringInfo(sql, " LIMIT %d", limit); } - POSTGIS_DEBUGF(1, "cb_getRingEdges query (limit " UINT64_FORMAT "): %s", limit, sql->data); + POSTGIS_DEBUGF(1, "cb_getRingEdges query (limit %d): %s", limit, sql->data); spi_result = SPI_execute(sql->data, !topo->be_data->data_changed, limit); MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != SPI_OK_SELECT ) @@ -1220,11 +1214,11 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, { return NULL; } - if ( limit && *numelems == limit ) + if (limit && *numelems == (uint64_t)limit) { - cberror(topo->be_data, "Max traversing limit hit: "UINT64_FORMAT, limit-1); - *numelems = UINT64_MAX; - return NULL; + cberror(topo->be_data, "Max traversing limit hit: %d", limit - 1); + *numelems = UINT64_MAX; + return NULL; } edges = palloc( sizeof(LWT_ELEMID) * *numelems ); @@ -1245,8 +1239,7 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, } val = DatumGetInt32(dat); edges[i] = val; - POSTGIS_DEBUGF(1, "Component %d in ring of edge %" LWTFMT_ELEMID - " is edge %d", i, edge, val); + POSTGIS_DEBUGF(1, "Component " UINT64_FORMAT " in ring of edge %" LWTFMT_ELEMID " is edge %d", i, edge, val); } SPI_freetuptable(SPI_tuptable); @@ -1254,9 +1247,8 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo, return edges; } -static LWT_ISO_NODE* -cb_getNodeById(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields) +static LWT_ISO_NODE * +cb_getNodeById(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields) { LWT_ISO_NODE *nodes; int spi_result; @@ -1289,7 +1281,7 @@ cb_getNodeById(const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getNodeById: edge query returned %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_getNodeById: edge query returned " UINT64_FORMAT " rows", SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -1308,10 +1300,8 @@ cb_getNodeById(const LWT_BE_TOPOLOGY* topo, return nodes; } -static LWT_ISO_NODE* -cb_getNodeByFace(const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t* numelems, int fields, - const GBOX *box) +static LWT_ISO_NODE * +cb_getNodeByFace(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t *numelems, int fields, const GBOX *box) { LWT_ISO_NODE *nodes; int spi_result; @@ -1351,7 +1341,7 @@ cb_getNodeByFace(const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getNodeByFace: edge query returned %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_getNodeByFace: edge query returned " UINT64_FORMAT " rows", SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -1370,10 +1360,13 @@ cb_getNodeByFace(const LWT_BE_TOPOLOGY* topo, return nodes; } -static LWT_ISO_EDGE* -cb_getEdgeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, - const LWPOINT* pt, double dist, uint64_t* numelems, - int fields, int limit) +static LWT_ISO_EDGE * +cb_getEdgeWithinDistance2D(const LWT_BE_TOPOLOGY *topo, + const LWPOINT *pt, + double dist, + uint64_t *numelems, + int fields, + int limit) { LWT_ISO_EDGE *edges; int spi_result; @@ -1427,9 +1420,11 @@ cb_getEdgeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getEdgeWithinDistance2D: edge query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); + POSTGIS_DEBUGF(1, + "cb_getEdgeWithinDistance2D: edge query " + "(limited by %d) returned " UINT64_FORMAT " rows", + elems_requested, + SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -1445,7 +1440,7 @@ cb_getEdgeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, dat = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull); exists = DatumGetBool(dat); *numelems = exists ? 1 : 0; - POSTGIS_DEBUGF(1, "cb_getEdgeWithinDistance2D: exists ? %d", *numelems); + POSTGIS_DEBUGF(1, "cb_getEdgeWithinDistance2D: exists ? " UINT64_FORMAT, *numelems); } SPI_freetuptable(SPI_tuptable); @@ -1465,10 +1460,13 @@ cb_getEdgeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, return edges; } -static LWT_ISO_NODE* -cb_getNodeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, - const LWPOINT* pt, double dist, uint64_t* numelems, - int fields, int limit) +static LWT_ISO_NODE * +cb_getNodeWithinDistance2D(const LWT_BE_TOPOLOGY *topo, + const LWPOINT *pt, + double dist, + uint64_t *numelems, + int fields, + int limit) { MemoryContext oldcontext = CurrentMemoryContext; LWT_ISO_NODE *nodes; @@ -1530,9 +1528,11 @@ cb_getNodeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getNodeWithinDistance2D: node query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); + POSTGIS_DEBUGF(1, + "cb_getNodeWithinDistance2D: node query " + "(limited by %d) returned " UINT64_FORMAT " rows", + elems_requested, + SPI_processed); if ( ! SPI_processed ) { *numelems = 0; @@ -1571,8 +1571,7 @@ cb_getNodeWithinDistance2D(const LWT_BE_TOPOLOGY* topo, } static int -cb_insertNodes( const LWT_BE_TOPOLOGY* topo, - LWT_ISO_NODE* nodes, uint64_t numelems ) +cb_insertNodes(const LWT_BE_TOPOLOGY *topo, LWT_ISO_NODE *nodes, uint64_t numelems) { MemoryContext oldcontext = CurrentMemoryContext; int spi_result; @@ -1607,12 +1606,13 @@ cb_insertNodes( const LWT_BE_TOPOLOGY* topo, if ( SPI_processed ) topo->be_data->data_changed = true; - // TODO: Remove cast when numelems uses uint64 instead of int - if ( SPI_processed != (uint64) numelems ) + if (SPI_processed != numelems) { - cberror(topo->be_data, "processed " UINT64_FORMAT " rows, expected " UINT64_FORMAT, - SPI_processed, numelems); - return 0; + cberror(topo->be_data, + "processed " UINT64_FORMAT " rows, expected " UINT64_FORMAT, + (uint64_t)SPI_processed, + numelems); + return 0; } /* Set node_id (could skip this if none had it set to -1) */ @@ -1630,8 +1630,7 @@ cb_insertNodes( const LWT_BE_TOPOLOGY* topo, } static int -cb_insertEdges( const LWT_BE_TOPOLOGY* topo, - LWT_ISO_EDGE* edges, uint64_t numelems ) +cb_insertEdges(const LWT_BE_TOPOLOGY *topo, LWT_ISO_EDGE *edges, uint64_t numelems) { MemoryContext oldcontext = CurrentMemoryContext; int spi_result; @@ -1654,7 +1653,7 @@ cb_insertEdges( const LWT_BE_TOPOLOGY* topo, } if ( needsEdgeIdReturn ) appendStringInfoString(sql, " RETURNING edge_id"); - POSTGIS_DEBUGF(1, "cb_insertEdges query (%d elems): %s", numelems, sql->data); + POSTGIS_DEBUGF(1, "cb_insertEdges query (" UINT64_FORMAT " elems): %s", numelems, sql->data); spi_result = SPI_execute(sql->data, false, numelems); MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != ( needsEdgeIdReturn ? SPI_OK_INSERT_RETURNING : SPI_OK_INSERT ) ) @@ -1666,18 +1665,20 @@ cb_insertEdges( const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); if ( SPI_processed ) topo->be_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_insertEdges query processed %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_insertEdges query processed " UINT64_FORMAT " rows", SPI_processed); if ( SPI_processed != (uint64) numelems ) { - cberror(topo->be_data, "processed " UINT64_FORMAT " rows, expected " UINT64_FORMAT, - SPI_processed, numelems); - return -1; + cberror(topo->be_data, + "processed " UINT64_FORMAT " rows, expected " UINT64_FORMAT, + (uint64_t)SPI_processed, + numelems); + return -1; } if ( needsEdgeIdReturn ) { /* Set node_id for items that need it */ - for ( i=0; i< SPI_processed; ++i ) + for (i = 0; i < SPI_processed; ++i) { if ( edges[i].edge_id != -1 ) continue; fillEdgeFields(&edges[i], SPI_tuptable->vals[i], @@ -1691,8 +1692,7 @@ cb_insertEdges( const LWT_BE_TOPOLOGY* topo, } static int -cb_insertFaces( const LWT_BE_TOPOLOGY* topo, - LWT_ISO_FACE* faces, uint64_t numelems ) +cb_insertFaces(const LWT_BE_TOPOLOGY *topo, LWT_ISO_FACE *faces, uint64_t numelems) { MemoryContext oldcontext = CurrentMemoryContext; int spi_result; @@ -1714,7 +1714,7 @@ cb_insertFaces( const LWT_BE_TOPOLOGY* topo, } if ( needsFaceIdReturn ) appendStringInfoString(sql, " RETURNING face_id"); - POSTGIS_DEBUGF(1, "cb_insertFaces query (" UINT64_MAX " elems): %s", numelems, sql->data); + POSTGIS_DEBUGF(1, "cb_insertFaces query (" UINT64_FORMAT " elems): %s", numelems, sql->data); spi_result = SPI_execute(sql->data, false, numelems); MemoryContextSwitchTo( oldcontext ); /* switch back */ if ( spi_result != ( needsFaceIdReturn ? SPI_OK_INSERT_RETURNING : SPI_OK_INSERT ) ) @@ -1726,12 +1726,14 @@ cb_insertFaces( const LWT_BE_TOPOLOGY* topo, } pfree(sqldata.data); if ( SPI_processed ) topo->be_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_insertFaces query processed %d rows", SPI_processed); - if ( SPI_processed != numelems ) + POSTGIS_DEBUGF(1, "cb_insertFaces query processed " UINT64_FORMAT " rows", SPI_processed); + if (SPI_processed != numelems) { - cberror(topo->be_data, "processed " UINT64_FORMAT " rows, expected " UINT64_FORMAT, - SPI_processed, numelems); - return -1; + cberror(topo->be_data, + "processed " UINT64_FORMAT " rows, expected " UINT64_FORMAT, + (uint64_t)SPI_processed, + numelems); + return -1; } if ( needsFaceIdReturn ) @@ -1790,7 +1792,7 @@ cb_updateEdges( const LWT_BE_TOPOLOGY* topo, if ( SPI_processed ) topo->be_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_updateEdges: update query processed %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_updateEdges: update query processed " UINT64_FORMAT " rows", SPI_processed); return SPI_processed; } @@ -1835,14 +1837,13 @@ cb_updateNodes( const LWT_BE_TOPOLOGY* topo, if ( SPI_processed ) topo->be_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_updateNodes: update query processed %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_updateNodes: update query processed " UINT64_FORMAT " rows", SPI_processed); return SPI_processed; } static int -cb_updateNodesById( const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_NODE* nodes, uint64_t numnodes, int fields ) +cb_updateNodesById(const LWT_BE_TOPOLOGY *topo, const LWT_ISO_NODE *nodes, uint64_t numnodes, int fields) { MemoryContext oldcontext = CurrentMemoryContext; uint64_t i; @@ -1859,9 +1860,12 @@ cb_updateNodesById( const LWT_BE_TOPOLOGY* topo, return -1; } - POSTGIS_DEBUGF(1, "cb_updateNodesById got %d nodes to update" - " (fields:%d)", - numnodes, fields); + POSTGIS_DEBUGF(1, + "cb_updateNodesById got " UINT64_FORMAT + " nodes to update" + " (fields:%d)", + numnodes, + fields); initStringInfo(sql); appendStringInfoString(sql, "WITH newnodes(node_id,"); @@ -1908,7 +1912,7 @@ cb_updateNodesById( const LWT_BE_TOPOLOGY* topo, if ( SPI_processed ) topo->be_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_updateNodesById: update query processed %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_updateNodesById: update query processed " UINT64_FORMAT " rows", SPI_processed); return SPI_processed; } @@ -1956,14 +1960,13 @@ cb_updateFacesById( const LWT_BE_TOPOLOGY* topo, if ( SPI_processed ) topo->be_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_updateFacesById: update query processed %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_updateFacesById: update query processed " UINT64_FORMAT " rows", SPI_processed); return SPI_processed; } static int -cb_updateEdgesById( const LWT_BE_TOPOLOGY* topo, - const LWT_ISO_EDGE* edges, uint64_t numedges, int fields ) +cb_updateEdgesById(const LWT_BE_TOPOLOGY *topo, const LWT_ISO_EDGE *edges, uint64_t numedges, int fields) { MemoryContext oldcontext = CurrentMemoryContext; uint64_t i; @@ -2049,7 +2052,7 @@ cb_updateEdgesById( const LWT_BE_TOPOLOGY* topo, if ( SPI_processed ) topo->be_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_updateEdgesById: update query processed %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_updateEdgesById: update query processed " UINT64_FORMAT " rows", SPI_processed); return SPI_processed; } @@ -2082,7 +2085,7 @@ cb_deleteEdges( const LWT_BE_TOPOLOGY* topo, if ( SPI_processed ) topo->be_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_deleteEdges: delete query processed %d rows", SPI_processed); + POSTGIS_DEBUGF(1, "cb_deleteEdges: delete query processed " UINT64_FORMAT " rows", SPI_processed); return SPI_processed; } @@ -2116,9 +2119,8 @@ cb_getNextEdgeId( const LWT_BE_TOPOLOGY* topo ) if ( SPI_processed != 1 ) { - cberror(topo->be_data, "processed " UINT64_FORMAT " rows, expected 1", - (uint64)SPI_processed); - return -1; + cberror(topo->be_data, "processed " UINT64_FORMAT " rows, expected 1", (uint64_t)SPI_processed); + return -1; } dat = SPI_getbinval( SPI_tuptable->vals[0], @@ -2178,8 +2180,8 @@ cb_updateTopoGeomEdgeSplit ( const LWT_BE_TOPOLOGY* topo, if ( spi_result == SPI_OK_DELETE_RETURNING && SPI_processed ) { - POSTGIS_DEBUGF(1, "cb_updateTopoGeomEdgeSplit: deleted %d faces", SPI_processed); - topo->be_data->data_changed = true; + POSTGIS_DEBUGF(1, "cb_updateTopoGeomEdgeSplit: deleted " UINT64_FORMAT " faces", SPI_processed); + topo->be_data->data_changed = true; } ntopogeoms = SPI_processed; @@ -2816,8 +2818,7 @@ cb_getFaceContainingPoint( const LWT_BE_TOPOLOGY* topo, const LWPOINT* pt ) } static int -cb_deleteFacesById( const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t numelems ) +cb_deleteFacesById(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t numelems) { MemoryContext oldcontext = CurrentMemoryContext; int spi_result; @@ -2826,7 +2827,7 @@ cb_deleteFacesById( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); appendStringInfo(sql, "DELETE FROM \"%s\".face WHERE face_id IN (", topo->name); - for (uint64_t i=0; ibe_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_deleteFacesById: delete query processed %d rows", - SPI_processed); + POSTGIS_DEBUGF(1, "cb_deleteFacesById: delete query processed " UINT64_FORMAT " rows", SPI_processed); return SPI_processed; } static int -cb_deleteNodesById( const LWT_BE_TOPOLOGY* topo, - const LWT_ELEMID* ids, uint64_t numelems ) +cb_deleteNodesById(const LWT_BE_TOPOLOGY *topo, const LWT_ELEMID *ids, uint64_t numelems) { MemoryContext oldcontext = CurrentMemoryContext; int spi_result; @@ -2865,7 +2864,7 @@ cb_deleteNodesById( const LWT_BE_TOPOLOGY* topo, initStringInfo(sql); appendStringInfo(sql, "DELETE FROM \"%s\".node WHERE node_id IN (", topo->name); - for (uint64_t i=0; ibe_data->data_changed = true; - POSTGIS_DEBUGF(1, "cb_deleteNodesById: delete query processed %d rows", - SPI_processed); + POSTGIS_DEBUGF(1, "cb_deleteNodesById: delete query processed " UINT64_FORMAT " rows", SPI_processed); return SPI_processed; } -static LWT_ISO_NODE* -cb_getNodeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, - uint64_t* numelems, int fields, int limit ) +static LWT_ISO_NODE * +cb_getNodeWithinBox2D(const LWT_BE_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, int limit) { MemoryContext oldcontext = CurrentMemoryContext; int spi_result; @@ -2940,9 +2937,11 @@ cb_getNodeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getNodeWithinBox2D: edge query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); + POSTGIS_DEBUGF(1, + "cb_getNodeWithinBox2D: edge query " + "(limited by %d) returned " UINT64_FORMAT " rows", + elems_requested, + SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -2959,7 +2958,7 @@ cb_getNodeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, exists = DatumGetBool(dat); SPI_freetuptable(SPI_tuptable); *numelems = exists ? 1 : 0; - POSTGIS_DEBUGF(1, "cb_getNodeWithinBox2D: exists ? %d", *numelems); + POSTGIS_DEBUGF(1, "cb_getNodeWithinBox2D: exists ? " UINT64_FORMAT, *numelems); } return NULL; } @@ -2976,9 +2975,8 @@ cb_getNodeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, return nodes; } -static LWT_ISO_EDGE* -cb_getEdgeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, - uint64_t* numelems, int fields, int limit ) +static LWT_ISO_EDGE * +cb_getEdgeWithinBox2D(const LWT_BE_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, int limit) { MemoryContext oldcontext = CurrentMemoryContext; int spi_result; @@ -3029,9 +3027,11 @@ cb_getEdgeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getEdgeWithinBox2D: edge query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); + POSTGIS_DEBUGF(1, + "cb_getEdgeWithinBox2D: edge query " + "(limited by %d) returned " UINT64_FORMAT " rows", + elems_requested, + SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -3048,7 +3048,7 @@ cb_getEdgeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, exists = DatumGetBool(dat); *numelems = exists ? 1 : 0; SPI_freetuptable(SPI_tuptable); - POSTGIS_DEBUGF(1, "cb_getEdgeWithinBox2D: exists ? %d", *numelems); + POSTGIS_DEBUGF(1, "cb_getEdgeWithinBox2D: exists ? " UINT64_FORMAT, *numelems); } return NULL; } @@ -3065,9 +3065,8 @@ cb_getEdgeWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, return edges; } -static LWT_ISO_FACE* -cb_getFaceWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, - uint64_t* numelems, int fields, uint64_t limit ) +static LWT_ISO_FACE * +cb_getFaceWithinBox2D(const LWT_BE_TOPOLOGY *topo, const GBOX *box, uint64_t *numelems, int fields, int limit) { MemoryContext oldcontext = CurrentMemoryContext; int spi_result; @@ -3113,9 +3112,11 @@ cb_getFaceWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, } pfree(sqldata.data); - POSTGIS_DEBUGF(1, "cb_getFaceWithinBox2D: face query " - "(limited by %d) returned %d rows", - elems_requested, SPI_processed); + POSTGIS_DEBUGF(1, + "cb_getFaceWithinBox2D: face query " + "(limited by %d) returned " UINT64_FORMAT " rows", + elems_requested, + SPI_processed); *numelems = SPI_processed; if ( ! SPI_processed ) { @@ -3131,7 +3132,7 @@ cb_getFaceWithinBox2D ( const LWT_BE_TOPOLOGY* topo, const GBOX* box, dat = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull); exists = DatumGetBool(dat); *numelems = exists ? 1 : 0; - POSTGIS_DEBUGF(1, "cb_getFaceWithinBox2D: exists ? %d", *numelems); + POSTGIS_DEBUGF(1, "cb_getFaceWithinBox2D: exists ? " UINT64_FORMAT, *numelems); } SPI_freetuptable(SPI_tuptable); -- 2.40.0