[geos-commits] [SCM] GEOS branch 3.9 updated. 56775452d0c802e2b2658940fee912cfb2d346e0

git at osgeo.org git at osgeo.org
Sat Dec 19 18:57:21 PST 2020


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, 3.9 has been updated
       via  56775452d0c802e2b2658940fee912cfb2d346e0 (commit)
      from  3caeaf132284ee0c5e0d5896ac105e47c1696937 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 56775452d0c802e2b2658940fee912cfb2d346e0
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Sat Dec 19 17:56:27 2020 -0800

    Clean up Win32 memory issue, references #1050

diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index a65e260..188d100 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -2408,22 +2408,31 @@ extern "C" {
         //assert(0 != holes);
 
         return execute(extHandle, [&]() {
-            auto vholes = geos::detail::make_unique<std::vector<LinearRing*>>(nholes);
 
+            std::vector<LinearRing*> tmpholes(nholes);
             for (size_t i = 0; i < nholes; i++) {
-                (*vholes)[i] = dynamic_cast<LinearRing*>(holes[i]);
-                if ((*vholes)[i] == nullptr) {
+                LinearRing* lr = dynamic_cast<LinearRing*>(holes[i]);
+                if (! lr) {
                     throw IllegalArgumentException("Hole is not a LinearRing");
                 }
+                tmpholes[i] = lr;
             }
-
             LinearRing* nshell = dynamic_cast<LinearRing*>(shell);
             if(! nshell) {
                 throw IllegalArgumentException("Shell is not a LinearRing");
             }
-            const GeometryFactory* gf = shell->getFactory();
+            GEOSContextHandleInternal_t* handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+            const GeometryFactory* gf = handle->geomFactory;
+
+            /* Create unique_ptr version for constructor */
+            std::vector<std::unique_ptr<LinearRing>> vholes;
+            vholes.reserve(nholes);
+            for (LinearRing* lr: tmpholes) {
+                vholes.emplace_back(lr);
+            }
+            std::unique_ptr<LinearRing> shell(nshell);
 
-            return gf->createPolygon(nshell, vholes.release());
+            return gf->createPolygon(std::move(shell), std::move(vholes)).release();
         });
     }
 
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 2bbd681..4aaffe2 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -78,6 +78,8 @@ geos_unit_SOURCES = \
 	capi/GEOSEqualsTest.cpp \
 	capi/GEOSFrechetDistanceTest.cpp \
 	capi/GEOSGeom_createCollectionTest.cpp \
+	capi/GEOSGeom_createPolygonTest.cpp \
+	capi/GEOSGeom_createLineStringTest.cpp \
 	capi/GEOSGeom_createTest.cpp \
 	capi/GEOSGeom_extentTest.cpp \
 	capi/GEOSGeom_extractUniquePointsTest.cpp \
diff --git a/tests/unit/capi/GEOSGeom_createPolygonTest.cpp b/tests/unit/capi/GEOSGeom_createPolygonTest.cpp
new file mode 100644
index 0000000..b560975
--- /dev/null
+++ b/tests/unit/capi/GEOSGeom_createPolygonTest.cpp
@@ -0,0 +1,54 @@
+#include <tut/tut.hpp>
+#include "capi_test_utils.h"
+
+namespace tut {
+//
+// Test Group
+//
+
+struct test_geosgeom_createpolygon_data : public capitest::utility {};
+
+typedef test_group<test_geosgeom_createpolygon_data> group;
+typedef group::object object;
+
+group test_geosgeom_createpolygon("capi::GEOSGeom_createPolygon");
+
+template<>
+template<>
+void object::test<1>
+()
+{
+    GEOSCoordSequence* shell_seq = GEOSCoordSeq_create(5, 2);
+    GEOSCoordSequence* hole_seq = GEOSCoordSeq_create(5, 2);
+
+    double shell_coords[] = {0,0, 0,10, 10,10, 10,0, 0,0};
+    double hole_coords[] = {5,5, 5,6, 6,6, 6,5, 5,5};
+    for (int i = 0; i < 5; i++) {
+        GEOSCoordSeq_setXY(shell_seq, i, shell_coords[2*i], shell_coords[2*i+1]);
+        GEOSCoordSeq_setXY(hole_seq, i, hole_coords[2*i], hole_coords[2*i+1]);
+    }
+
+    GEOSGeometry* shell = GEOSGeom_createLinearRing(shell_seq);
+    GEOSGeometry* hole = GEOSGeom_createLinearRing(hole_seq);
+    GEOSGeometry** holes = (GEOSGeometry**)malloc(sizeof(GEOSGeometry *));
+    holes[0] = hole;
+
+    GEOSGeometry* polygon = GEOSGeom_createPolygon(shell, holes, 1);
+    GEOSGeometry* expected = GEOSGeomFromWKT("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0),(5 5, 5 6, 6 6, 6 5, 5 5))");
+
+    // GEOSWKTWriter* w = GEOSWKTWriter_create();
+    // printf("%s\n", GEOSWKTWriter_write(w, polygon));
+    // printf("%s\n", GEOSWKTWriter_write(w, expected));
+
+    ensure_equals(GEOSEqualsExact(polygon, expected, 0), 1);
+
+    GEOSGeom_destroy(polygon);
+    GEOSGeom_destroy(expected);
+    // WARNING! The GEOSGeom_createPolygon takes ownership of the
+    // GEOSGeometry, but not the containing array!
+    // maybe this should be changed...
+    free(holes);
+}
+
+} // namespace tut
+

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

Summary of changes:
 capi/geos_ts_c.cpp                             | 21 +++++++---
 tests/unit/Makefile.am                         |  2 +
 tests/unit/capi/GEOSGeom_createPolygonTest.cpp | 54 ++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 6 deletions(-)
 create mode 100644 tests/unit/capi/GEOSGeom_createPolygonTest.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list