From 9d2218a7591a754f00ec87716d92062ec94d209d Mon Sep 17 00:00:00 2001 From: Ylannl Date: Tue, 22 Oct 2024 14:08:37 +0200 Subject: [PATCH] Use GEOS threadsafe functions (_r), add call to GEOSWKTReader_destroy_r --- src/Surface.cpp | 14 ++++++++------ thirdparty/{nlohmann-json => nlohmann}/json.hpp | 0 2 files changed, 8 insertions(+), 6 deletions(-) rename thirdparty/{nlohmann-json => nlohmann}/json.hpp (100%) diff --git a/src/Surface.cpp b/src/Surface.cpp index 76f03f9f..31cc4192 100644 --- a/src/Surface.cpp +++ b/src/Surface.cpp @@ -732,7 +732,8 @@ bool Surface::validate_projected_ring(Polygon &pgn, std::string id) bool Surface::validate_polygon(std::vector &lsRings, std::string polygonid) { - initGEOS(NULL, NULL); + // Use the _r geos functions to make it thread-safe + auto geos_ctx = GEOS_init_r(); //-- check the orientation of the rings: oring != irings //-- we don't care about CCW or CW at this point, just opposite is important //-- GEOS doesn't do its job, so we have to do it here. Shame on you GEOS. @@ -785,10 +786,10 @@ bool Surface::validate_polygon(std::vector &lsRings, std::string polygo } wkt << ")"; GEOSWKTReader* r; - r = GEOSWKTReader_create(); + r = GEOSWKTReader_create_r(geos_ctx); GEOSGeometry* mygeom; - mygeom = GEOSWKTReader_read(r, wkt.str().c_str()); - string reason = (string)GEOSisValidReason(mygeom); + mygeom = GEOSWKTReader_read_r(geos_ctx, r, wkt.str().c_str()); + string reason = (string)GEOSisValidReason_r(geos_ctx, mygeom); if (reason.find("Valid Geometry") == string::npos) { isvalid = false; @@ -805,8 +806,9 @@ bool Surface::validate_polygon(std::vector &lsRings, std::string polygo else this->add_error(999, polygonid, reason.c_str()); } - GEOSGeom_destroy( mygeom ); - finishGEOS(); + GEOSWKTReader_destroy_r(geos_ctx, r); + GEOSGeom_destroy_r(geos_ctx, mygeom ); + GEOS_finish_r(geos_ctx); return isvalid; } diff --git a/thirdparty/nlohmann-json/json.hpp b/thirdparty/nlohmann/json.hpp similarity index 100% rename from thirdparty/nlohmann-json/json.hpp rename to thirdparty/nlohmann/json.hpp