A few months ago I sent a message to both the GEOS and Shapely mailing
lists pointing out an issue that I was running into where freeing
memory allocated by GEOSGeomToWKT and GEOSGeomToWKB_buf can cause a
crash on Windows if the memory is not freed by the GEOS DLL. This is
because the memory is created in this DLL, and as a result in certain
cases this can cause a crash if the memory is not freed in the same
DLL. I have made the changes locally, but as far as I can tell the
changes have not made it into Shapely. I would like to stop supporting
these local changes if at all possible. I have attached two of the old
patches for reference.
-Aron
http://trac.osgeo.org/geos/ticket/249
http://trac.osgeo.org/gdal/wiki/FAQMiscellaneous#FAQ-Miscellaneous
http://msdn.microsoft.com/en-us/library/ms235460.aspx
Index: shapely/geos.py
===================================================================
--- shapely/geos.py (revision 1424)
+++ shapely/geos.py (revision 1425)
@@ -134,6 +134,9 @@
if 'geos_handle' == name:
self.geos_handle = lgeos._lgeos.initGEOS_r(notice_h, error_h)
return self.geos_handle
+ if name == 'GEOSFree':
+ attr = getattr(self._lgeos, name)
+ return attr
old_func = getattr(self._lgeos, name)
if geos_c_version >= (1,5,0):
@@ -162,7 +165,7 @@
def errcheck_just_free(result, func, argtuple):
retval = result.value
- free(result)
+ lgeos.GEOSFree(result)
return retval
func = lgeos.GEOSGeomToWKT
Index: shapely/ctypes_declarations.py
===================================================================
--- shapely/ctypes_declarations.py (revision 1424)
+++ shapely/ctypes_declarations.py (revision 1425)
@@ -6,6 +6,9 @@
_lgeos.finishGEOS.restype = None
+_lgeos.GEOSFree.restype = None
+_lgeos.GEOSFree.argtypes = [ctypes.c_void_p]
+
_lgeos.GEOSversion.restype = ctypes.c_char_p
_lgeos.GEOSGeomFromWKT.restype = ctypes.c_void_p
Index: shapely/geos.py
===================================================================
--- shapely/geos.py
+++ shapely/geos.py
@@ -159,7 +159,7 @@
size_ref = argtuple[2]
size = size_ref._obj
retval = ctypes.string_at(result, size.value)[:]
- free(result)
+ lgeos.GEOSFree(result)
return retval
func.func.errcheck = errcheck_wkb
Index: shapely/ctypes_declarations.py
===================================================================
--- shapely/ctypes_declarations.py
+++ shapely/ctypes_declarations.py
@@ -17,6 +17,9 @@
_lgeos.GEOSGeomToWKT.restype = allocated_c_char_p
_lgeos.GEOSGeomToWKT.argtypes = [ctypes.c_void_p]
+_lgeos.GEOSGeomToWKB_buf.restype = allocated_c_char_p
+_lgeos.GEOSGeomToWKB_buf.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
+
_lgeos.GEOS_setWKBOutputDims.restype = ctypes.c_int
_lgeos.GEOS_setWKBOutputDims.argtypes = [ctypes.c_int]
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community