From 8b5a29800ce0bc7272917de99b46f6f6dcdb7d74 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Sat, 9 Sep 2017 13:34:14 +0500 Subject: [PATCH] Fixed #25961 -- Removed handling of non-thread safe GEOS functions. --- django/contrib/gis/geos/libgeos.py | 8 ++-- .../contrib/gis/geos/prototypes/threadsafe.py | 42 +++++++------------ 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/django/contrib/gis/geos/libgeos.py b/django/contrib/gis/geos/libgeos.py index b8dca115a0..40f3cae33a 100644 --- a/django/contrib/gis/geos/libgeos.py +++ b/django/contrib/gis/geos/libgeos.py @@ -66,6 +66,8 @@ def load_geos(): # geos/prototypes/threadsafe.py. _lgeos.initGEOS_r.restype = CONTEXT_PTR _lgeos.finishGEOS_r.argtypes = [CONTEXT_PTR] + # Set restype for compatibility across 32 and 64-bit platforms. + _lgeos.GEOSversion.restype = c_char_p return _lgeos @@ -163,9 +165,9 @@ class GEOSFuncFactory: return func -# Return the string version of the GEOS library. Have to set the restype -# explicitly to c_char_p to ensure compatibility across 32 and 64-bit platforms. -geos_version = GEOSFuncFactory('GEOSversion', restype=c_char_p) +def geos_version(): + """Return the string version of the GEOS library.""" + return lgeos.GEOSversion() def geos_version_tuple(): diff --git a/django/contrib/gis/geos/prototypes/threadsafe.py b/django/contrib/gis/geos/prototypes/threadsafe.py index c2f0fb8385..24f8f288c1 100644 --- a/django/contrib/gis/geos/prototypes/threadsafe.py +++ b/django/contrib/gis/geos/prototypes/threadsafe.py @@ -32,29 +32,20 @@ class GEOSFunc: variants when available. """ def __init__(self, func_name): - try: - # GEOS thread-safe function signatures end with '_r', and - # take an additional context handle parameter. - self.cfunc = getattr(lgeos, func_name + '_r') - self.threaded = True - # Create a reference here to thread_context so it's not - # garbage-collected before an attempt to call this object. - self.thread_context = thread_context - except AttributeError: - # Otherwise, use usual function. - self.cfunc = getattr(lgeos, func_name) - self.threaded = False + # GEOS thread-safe function signatures end with '_r' and take an + # additional context handle parameter. + self.cfunc = getattr(lgeos, func_name + '_r') + # Create a reference to thread_context so it's not garbage-collected + # before an attempt to call this object. + self.thread_context = thread_context def __call__(self, *args): - if self.threaded: - # If a context handle does not exist for this thread, initialize one. - if not self.thread_context.handle: - self.thread_context.handle = GEOSContextHandle() - # Call the threaded GEOS routine with pointer of the context handle - # as the first argument. - return self.cfunc(self.thread_context.handle.ptr, *args) - else: - return self.cfunc(*args) + # Create a context handle if one doesn't exist for this thread. + if not self.thread_context.handle: + self.thread_context.handle = GEOSContextHandle() + # Call the threaded GEOS routine with the pointer of the context handle + # as the first argument. + return self.cfunc(self.thread_context.handle.ptr, *args) def __str__(self): return self.cfunc.__name__ @@ -64,12 +55,9 @@ class GEOSFunc: return self.cfunc.argtypes def _set_argtypes(self, argtypes): - if self.threaded: - new_argtypes = [CONTEXT_PTR] - new_argtypes.extend(argtypes) - self.cfunc.argtypes = new_argtypes - else: - self.cfunc.argtypes = argtypes + new_argtypes = [CONTEXT_PTR] + new_argtypes.extend(argtypes) + self.cfunc.argtypes = new_argtypes argtypes = property(_get_argtypes, _set_argtypes)