From aa0be5b7f0c72e58385ae29057ff471f9a231877 Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Thu, 9 Jul 2009 02:37:20 +0000 Subject: [PATCH] [1.0.X] ixed 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. Backport of r11205 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11206 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/gdal/prototypes/generation.py | 9 ++++++--- django/contrib/gis/geos/prototypes/topology.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/django/contrib/gis/gdal/prototypes/generation.py b/django/contrib/gis/gdal/prototypes/generation.py index bba715d67ce7b..1303532372ad2 100644 --- a/django/contrib/gis/gdal/prototypes/generation.py +++ b/django/contrib/gis/gdal/prototypes/generation.py @@ -8,6 +8,9 @@ check_arg_errcode, check_errcode, check_geom, check_geom_offset, \ 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): "Generates a ctypes function that returns a double value." func.argtypes = argtypes @@ -77,9 +80,9 @@ def string_output(func, argtypes, offset=-1, str_result=False): """ func.argtypes = argtypes if str_result: - # String is the result, don't explicitly define - # the argument type so we can get the pointer. - pass + # Use subclass of c_char_p so the error checking routine + # can free the memory at the pointer's address. + func.restype = gdal_char_p else: # Error code is returned func.restype = c_int diff --git a/django/contrib/gis/geos/prototypes/topology.py b/django/contrib/gis/geos/prototypes/topology.py index 70cf9000988c6..a28f5cafda407 100644 --- a/django/contrib/gis/geos/prototypes/topology.py +++ b/django/contrib/gis/geos/prototypes/topology.py @@ -5,6 +5,7 @@ from ctypes import c_char_p, c_double, c_int from django.contrib.gis.geos.libgeos import lgeos, GEOM_PTR 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): "For GEOS unary topology functions." @@ -32,4 +33,5 @@ def topology(func, *args): # GEOSRelate returns a string, not a geometry. geos_relate = lgeos.GEOSRelate geos_relate.argtypes = [GEOM_PTR, GEOM_PTR] +geos_relate.restype = geos_char_p geos_relate.errcheck = check_string