summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-12-08 14:29:06 +0000
committerJustin Bronn <jbronn@gmail.com>2008-12-08 14:29:06 +0000
commit6590c0bcf5cc85c551706586fc8cab88965a986a (patch)
tree4ab9d9c4fe38ba8635ab64162e83229bdaf55ece
parent662e12b45ce1cafa3806d8e8dd45638996e91bd7 (diff)
Fixed #9747 -- now explicitly set response type on C functions that return WKB and WKT.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9605 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/gis/geos/prototypes/geom.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/django/contrib/gis/geos/prototypes/geom.py b/django/contrib/gis/geos/prototypes/geom.py
index e5942a5957..d42ceaa292 100644
--- a/django/contrib/gis/geos/prototypes/geom.py
+++ b/django/contrib/gis/geos/prototypes/geom.py
@@ -1,8 +1,21 @@
-from ctypes import c_char_p, c_int, c_size_t, c_uint, POINTER
+from ctypes import c_char_p, c_int, c_size_t, c_ubyte, c_uint, POINTER
from django.contrib.gis.geos.libgeos import lgeos, CS_PTR, GEOM_PTR
from django.contrib.gis.geos.prototypes.errcheck import \
check_geom, check_minus_one, check_sized_string, check_string, check_zero
+# This is the return type used by binary output (WKB, HEX) routines.
+c_uchar_p = POINTER(c_ubyte)
+
+# We create a simple subclass of c_char_p here because when the response
+# type is set to c_char_p, you get a _Python_ string and there's no way
+# to access the string's address inside the error checking function.
+# In other words, you can't free the memory allocated inside GEOS. Previously,
+# the return type would just be omitted and the integer address would be
+# used -- but this allows us to be specific in the function definition and
+# keeps the reference so it may be free'd.
+class geos_char_p(c_char_p):
+ pass
+
### ctypes generation functions ###
def bin_constructor(func):
"Generates a prototype for binary construction (HEX, WKB) GEOS routines."
@@ -16,6 +29,7 @@ def bin_output(func):
"Generates a prototype for the routines that return a a sized string."
func.argtypes = [GEOM_PTR, POINTER(c_size_t)]
func.errcheck = check_sized_string
+ func.restype = c_uchar_p
return func
def geom_output(func, argtypes):
@@ -44,6 +58,7 @@ def string_from_geom(func):
# We do _not_ specify an argument type because we want just an
# address returned from the function.
func.argtypes = [GEOM_PTR]
+ func.restype = geos_char_p
func.errcheck = check_string
return func