Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12438 -- now use `GEOSFree` to free string pointers allocated …

…within GEOS when available; now parse out subminor version, and added a `GEOS_VERSION` tuple.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11979 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 474fb8c3ae9edd2c26ce5dd3e6c57db7c61976ed 1 parent 7d0c196
Justin Bronn authored December 24, 2009
8  django/contrib/gis/geos/libgeos.py
@@ -104,7 +104,7 @@ def get_pointer_arr(n):
104 104
 
105 105
 # Regular expression should be able to parse version strings such as
106 106
 # '3.0.0rc4-CAPI-1.3.3', or '3.0.0-CAPI-1.4.1'
107  
-version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.\d+)(rc(?P<release_candidate>\d+))?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)$')
  107
+version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))(rc(?P<release_candidate>\d+))?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)$')
108 108
 def geos_version_info():
109 109
     """
110 110
     Returns a dictionary containing the various version metadata parsed from
@@ -115,14 +115,16 @@ def geos_version_info():
115 115
     ver = geos_version()
116 116
     m = version_regex.match(ver)
117 117
     if not m: raise GEOSException('Could not parse version info string "%s"' % ver)
118  
-    return dict((key, m.group(key)) for key in ('version', 'release_candidate', 'capi_version', 'major', 'minor'))
  118
+    return dict((key, m.group(key)) for key in ('version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor'))
119 119
 
120 120
 # Version numbers and whether or not prepared geometry support is available.
121 121
 _verinfo = geos_version_info()
122 122
 GEOS_MAJOR_VERSION = int(_verinfo['major'])
123 123
 GEOS_MINOR_VERSION = int(_verinfo['minor'])
  124
+GEOS_SUBMINOR_VERSION = int(_verinfo['subminor'])
124 125
 del _verinfo
125  
-GEOS_PREPARE = GEOS_MAJOR_VERSION > 3 or GEOS_MAJOR_VERSION == 3 and GEOS_MINOR_VERSION >= 1
  126
+GEOS_VERSION = (GEOS_MAJOR_VERSION, GEOS_MINOR_VERSION, GEOS_SUBMINOR_VERSION)
  127
+GEOS_PREPARE = GEOS_VERSION >= (3, 1, 0)
126 128
 
127 129
 # Calling the finishGEOS() upon exit of the interpreter.
128 130
 atexit.register(lgeos.finishGEOS)
29  django/contrib/gis/geos/prototypes/errcheck.py
... ...
@@ -1,22 +1,27 @@
1 1
 """
2 2
  Error checking functions for GEOS ctypes prototype functions.
3 3
 """
4  
-import os
5  
-from ctypes import string_at, CDLL
6  
-from ctypes.util import find_library
  4
+from ctypes import c_void_p, string_at, CDLL
7 5
 from django.contrib.gis.geos.error import GEOSException
  6
+from django.contrib.gis.geos.libgeos import lgeos, GEOS_VERSION
8 7
 
9  
-# Getting the C library, needed to free the string pointers
10  
-# returned from GEOS.
11  
-if os.name == 'nt':
12  
-    libc_name = 'msvcrt'
  8
+# Getting the `free` routine used to free the memory allocated for
  9
+# string pointers returned by GEOS.
  10
+if GEOS_VERSION >= (3, 1, 0):
  11
+    # In versions 3.1 and above, `GEOSFree` was added to the C API
  12
+    # because `free` isn't always available on all platforms.
  13
+    free = lgeos.GEOSFree
  14
+    free.argtypes = [c_void_p]
  15
+    free.restype = None
13 16
 else:
14  
-    libc_name = 'libc'
15  
-libc = CDLL(find_library(libc_name))
  17
+    # Getting the `free` routine from the C library of the platform.
  18
+    # The C library is obtained by passing None into `CDLL`.
  19
+    libc = CDLL(None)
  20
+    free = libc.free
16 21
 
17 22
 ### ctypes error checking routines ###
18 23
 def last_arg_byref(args):
19  
-    "Returns the last C argument's by reference value."
  24
+    "Returns the last C argument's value by reference."
20 25
     return args[-1]._obj.value
21 26
 
22 27
 def check_dbl(result, func, cargs):
@@ -60,7 +65,7 @@ def check_sized_string(result, func, cargs):
60 65
     # correct size.
61 66
     s = string_at(result, last_arg_byref(cargs))
62 67
     # Freeing the memory allocated within GEOS
63  
-    libc.free(result)
  68
+    free(result)
64 69
     return s
65 70
 
66 71
 def check_string(result, func, cargs):
@@ -73,7 +78,7 @@ def check_string(result, func, cargs):
73 78
     # Getting the string value at the pointer address.
74 79
     s = string_at(result)
75 80
     # Freeing the memory allocated within GEOS
76  
-    libc.free(result)
  81
+    free(result)
77 82
     return s
78 83
 
79 84
 def check_zero(result, func, cargs):

0 notes on commit 474fb8c

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