Author: Armin Rigo <[email protected]>
Branch:
Changeset: r84098:22204fd13f81
Date: 2016-05-01 15:35 +0200
http://bitbucket.org/pypy/pypy/changeset/22204fd13f81/
Log: hg merge cpyext-auto-gil
When some PyXxx() function is called without the GIL, we already
detect this case. Previously we would complain loudly. With this
change, we instead silently acquire/release the GIL. This seems to
make numpy happy: it contains calls to some "simple" PyXxx()
functions without the GIL, hoping that their implementation is kept
simple enough, and expect no problem from that.
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -790,6 +790,8 @@
from rpython.rlib import rgil
argtypes_enum_ui = unrolling_iterable(enumerate(argtypesw))
fatal_value = restype._defl()
+ gil_auto_workaround = (gil is None) # automatically detect when we don't
+ # have the GIL, and acquire/release it
gil_acquire = (gil == "acquire" or gil == "around")
gil_release = (gil == "release" or gil == "around")
pygilstate_ensure = (gil == "pygilstate_ensure")
@@ -825,7 +827,8 @@
# see "Handling of the GIL" above (careful, we don't have the GIL here)
tid = rthread.get_or_make_ident()
- if gil_acquire:
+ _gil_auto = (gil_auto_workaround and cpyext_glob_tid_ptr[0] != tid)
+ if gil_acquire or _gil_auto:
if cpyext_glob_tid_ptr[0] == tid:
deadlock_error(nameof(callable))
rgil.acquire()
@@ -919,7 +922,7 @@
arg = rffi.cast(lltype.Signed, args[-1])
unlock = (arg == pystate.PyGILState_UNLOCKED)
else:
- unlock = gil_release
+ unlock = gil_release or _gil_auto
if unlock:
rgil.release()
else:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit