Ticket #9747: geos_explicit_char_restype.diff
File geos_explicit_char_restype.diff, 1.9 KB (added by , 16 years ago) |
---|
-
django/contrib/gis/geos/prototypes/geom.py
1 from ctypes import c_char_p, c_int, c_size_t, c_u int, POINTER1 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 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 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