Author: jbronn
Date: 2009-07-08 21:00:40 -0500 (Wed, 08 Jul 2009)
New Revision: 11205
Modified:
django/trunk/django/contrib/gis/gdal/prototypes/generation.py
django/trunk/django/contrib/gis/geos/prototypes/topology.py
Log:
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.
Modified: django/trunk/django/contrib/gis/gdal/prototypes/generation.py
===================================================================
--- django/trunk/django/contrib/gis/gdal/prototypes/generation.py
2009-07-08 00:52:25 UTC (rev 11204)
+++ django/trunk/django/contrib/gis/gdal/prototypes/generation.py
2009-07-09 02:00:40 UTC (rev 11205)
@@ -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 @@
"""
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
Modified: django/trunk/django/contrib/gis/geos/prototypes/topology.py
===================================================================
--- django/trunk/django/contrib/gis/geos/prototypes/topology.py 2009-07-08
00:52:25 UTC (rev 11204)
+++ django/trunk/django/contrib/gis/geos/prototypes/topology.py 2009-07-09
02:00:40 UTC (rev 11205)
@@ -10,6 +10,7 @@
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.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."
@@ -38,6 +39,7 @@
# 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
# Routines only in GEOS 3.1+
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---