Fixed GEOS & GDAL C function prototypes to explicitly use a subclass of `c_char_p` as the return type on routines that return strings. This prevents crashes on some 64-bit platforms, like FreeBSD. Thanks to wilsaj for discovering the problem. Refs #9747.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11205 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2009-07-09 02:00:40 +00:00
parent 4532cf69de
commit 55968a6edd
2 changed files with 8 additions and 3 deletions

View File

@ -8,6 +8,9 @@ from django.contrib.gis.gdal.prototypes.errcheck import \
check_arg_errcode, check_errcode, check_geom, check_geom_offset, \ check_arg_errcode, check_errcode, check_geom, check_geom_offset, \
check_pointer, check_srs, check_str_arg, check_string, check_const_string check_pointer, check_srs, check_str_arg, check_string, check_const_string
class gdal_char_p(c_char_p):
pass
def double_output(func, argtypes, errcheck=False, strarg=False): def double_output(func, argtypes, errcheck=False, strarg=False):
"Generates a ctypes function that returns a double value." "Generates a ctypes function that returns a double value."
func.argtypes = argtypes func.argtypes = argtypes
@ -77,9 +80,9 @@ def string_output(func, argtypes, offset=-1, str_result=False):
""" """
func.argtypes = argtypes func.argtypes = argtypes
if str_result: if str_result:
# String is the result, don't explicitly define # Use subclass of c_char_p so the error checking routine
# the argument type so we can get the pointer. # can free the memory at the pointer's address.
pass func.restype = gdal_char_p
else: else:
# Error code is returned # Error code is returned
func.restype = c_int func.restype = c_int

View File

@ -10,6 +10,7 @@ __all__ = ['geos_boundary', 'geos_buffer', 'geos_centroid', 'geos_convexhull',
from ctypes import c_char_p, c_double, c_int from ctypes import c_char_p, c_double, c_int
from django.contrib.gis.geos.libgeos import lgeos, GEOM_PTR, GEOS_PREPARE from django.contrib.gis.geos.libgeos import lgeos, GEOM_PTR, GEOS_PREPARE
from django.contrib.gis.geos.prototypes.errcheck import check_geom, check_string from django.contrib.gis.geos.prototypes.errcheck import check_geom, check_string
from django.contrib.gis.geos.prototypes.geom import geos_char_p
def topology(func, *args): def topology(func, *args):
"For GEOS unary topology functions." "For GEOS unary topology functions."
@ -38,6 +39,7 @@ geos_union = topology(lgeos.GEOSUnion, GEOM_PTR)
# GEOSRelate returns a string, not a geometry. # GEOSRelate returns a string, not a geometry.
geos_relate = lgeos.GEOSRelate geos_relate = lgeos.GEOSRelate
geos_relate.argtypes = [GEOM_PTR, GEOM_PTR] geos_relate.argtypes = [GEOM_PTR, GEOM_PTR]
geos_relate.restype = geos_char_p
geos_relate.errcheck = check_string geos_relate.errcheck = check_string
# Routines only in GEOS 3.1+ # Routines only in GEOS 3.1+