Fixed #25961 -- Removed handling of non-thread safe GEOS functions.
This commit is contained in:
parent
63d2472b10
commit
8b5a29800c
|
@ -66,6 +66,8 @@ def load_geos():
|
||||||
# geos/prototypes/threadsafe.py.
|
# geos/prototypes/threadsafe.py.
|
||||||
_lgeos.initGEOS_r.restype = CONTEXT_PTR
|
_lgeos.initGEOS_r.restype = CONTEXT_PTR
|
||||||
_lgeos.finishGEOS_r.argtypes = [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
|
return _lgeos
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,9 +165,9 @@ class GEOSFuncFactory:
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
# Return the string version of the GEOS library. Have to set the restype
|
def geos_version():
|
||||||
# explicitly to c_char_p to ensure compatibility across 32 and 64-bit platforms.
|
"""Return the string version of the GEOS library."""
|
||||||
geos_version = GEOSFuncFactory('GEOSversion', restype=c_char_p)
|
return lgeos.GEOSversion()
|
||||||
|
|
||||||
|
|
||||||
def geos_version_tuple():
|
def geos_version_tuple():
|
||||||
|
|
|
@ -32,29 +32,20 @@ class GEOSFunc:
|
||||||
variants when available.
|
variants when available.
|
||||||
"""
|
"""
|
||||||
def __init__(self, func_name):
|
def __init__(self, func_name):
|
||||||
try:
|
# GEOS thread-safe function signatures end with '_r' and take an
|
||||||
# GEOS thread-safe function signatures end with '_r', and
|
# additional context handle parameter.
|
||||||
# take an additional context handle parameter.
|
|
||||||
self.cfunc = getattr(lgeos, func_name + '_r')
|
self.cfunc = getattr(lgeos, func_name + '_r')
|
||||||
self.threaded = True
|
# Create a reference to thread_context so it's not garbage-collected
|
||||||
# Create a reference here to thread_context so it's not
|
# before an attempt to call this object.
|
||||||
# garbage-collected before an attempt to call this object.
|
|
||||||
self.thread_context = thread_context
|
self.thread_context = thread_context
|
||||||
except AttributeError:
|
|
||||||
# Otherwise, use usual function.
|
|
||||||
self.cfunc = getattr(lgeos, func_name)
|
|
||||||
self.threaded = False
|
|
||||||
|
|
||||||
def __call__(self, *args):
|
def __call__(self, *args):
|
||||||
if self.threaded:
|
# Create a context handle if one doesn't exist for this thread.
|
||||||
# If a context handle does not exist for this thread, initialize one.
|
|
||||||
if not self.thread_context.handle:
|
if not self.thread_context.handle:
|
||||||
self.thread_context.handle = GEOSContextHandle()
|
self.thread_context.handle = GEOSContextHandle()
|
||||||
# Call the threaded GEOS routine with pointer of the context handle
|
# Call the threaded GEOS routine with the pointer of the context handle
|
||||||
# as the first argument.
|
# as the first argument.
|
||||||
return self.cfunc(self.thread_context.handle.ptr, *args)
|
return self.cfunc(self.thread_context.handle.ptr, *args)
|
||||||
else:
|
|
||||||
return self.cfunc(*args)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.cfunc.__name__
|
return self.cfunc.__name__
|
||||||
|
@ -64,12 +55,9 @@ class GEOSFunc:
|
||||||
return self.cfunc.argtypes
|
return self.cfunc.argtypes
|
||||||
|
|
||||||
def _set_argtypes(self, argtypes):
|
def _set_argtypes(self, argtypes):
|
||||||
if self.threaded:
|
|
||||||
new_argtypes = [CONTEXT_PTR]
|
new_argtypes = [CONTEXT_PTR]
|
||||||
new_argtypes.extend(argtypes)
|
new_argtypes.extend(argtypes)
|
||||||
self.cfunc.argtypes = new_argtypes
|
self.cfunc.argtypes = new_argtypes
|
||||||
else:
|
|
||||||
self.cfunc.argtypes = argtypes
|
|
||||||
|
|
||||||
argtypes = property(_get_argtypes, _set_argtypes)
|
argtypes = property(_get_argtypes, _set_argtypes)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue