Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #9747 -- now explicitly set response type on C function…

…s that return WKB and WKT.

Backport of r9605 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9606 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 974135fc7e11c69badce74dc8108c9534a39c4c6 1 parent 4dcff3e
Justin Bronn authored December 08, 2008
17  django/contrib/gis/geos/prototypes/geom.py
... ...
@@ -1,8 +1,21 @@
1  
-from ctypes import c_char_p, c_int, c_size_t, c_uint, POINTER
  1
+from ctypes import c_char_p, c_int, c_size_t, c_ubyte, c_uint, POINTER
2 2
 from django.contrib.gis.geos.libgeos import lgeos, CS_PTR, GEOM_PTR
3 3
 from django.contrib.gis.geos.prototypes.errcheck import \
4 4
     check_geom, check_minus_one, check_sized_string, check_string, check_zero
5 5
 
  6
+# This is the return type used by binary output (WKB, HEX) routines.
  7
+c_uchar_p = POINTER(c_ubyte)
  8
+
  9
+# We create a simple subclass of c_char_p here because when the response
  10
+# type is set to c_char_p, you get a _Python_ string and there's no way
  11
+# to access the string's address inside the error checking function.
  12
+# In other words, you can't free the memory allocated inside GEOS.  Previously,
  13
+# the return type would just be omitted and the integer address would be
  14
+# used -- but this allows us to be specific in the function definition and
  15
+# keeps the reference so it may be free'd.
  16
+class geos_char_p(c_char_p):
  17
+    pass
  18
+
6 19
 ### ctypes generation functions ###
7 20
 def bin_constructor(func):
8 21
     "Generates a prototype for binary construction (HEX, WKB) GEOS routines."
@@ -16,6 +29,7 @@ def bin_output(func):
16 29
     "Generates a prototype for the routines that return a a sized string."
17 30
     func.argtypes = [GEOM_PTR, POINTER(c_size_t)]
18 31
     func.errcheck = check_sized_string
  32
+    func.restype = c_uchar_p
19 33
     return func
20 34
 
21 35
 def geom_output(func, argtypes):
@@ -44,6 +58,7 @@ def string_from_geom(func):
44 58
     # We do _not_ specify an argument type because we want just an
45 59
     # address returned from the function.
46 60
     func.argtypes = [GEOM_PTR]
  61
+    func.restype = geos_char_p
47 62
     func.errcheck = check_string
48 63
     return func
49 64
 

0 notes on commit 974135f

Please sign in to comment.
Something went wrong with that request. Please try again.