[pypy-commit] pypy cpyext-auto-gil: When some PyXxx() function is called without the GIL, we already detect
arigo
pypy.commits at gmail.com
Sun May 1 06:09:55 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: cpyext-auto-gil
Changeset: r84094:bfd2cd24cee2
Date: 2016-05-01 12:09 +0200
http://bitbucket.org/pypy/pypy/changeset/bfd2cd24cee2/
Log: When some PyXxx() function is called without the GIL, we already
detect this case. On "default" we then complain loudly. Maybe we
should instead silently acquire/release the GIL. This would allow
this case to work: CPython C extension modules might call some
"simple" CPython PyXxx() functions without the GIL and hope that
their implementation is kept simple enough.
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:
More information about the pypy-commit
mailing list