Author: Armin Rigo <[email protected]>
Branch:
Changeset: r97027:c89821342184
Date: 2019-07-25 17:20 +0200
http://bitbucket.org/pypy/pypy/changeset/c89821342184/
Log: cpyext: add a workaround that should make one case work (typically
seen only with C++ code)
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
@@ -1004,6 +1004,12 @@
deadlock_error(pname)
rgil.acquire()
assert cpyext_glob_tid_ptr[0] == 0
+ if gil_auto_workaround:
+ # while we're in workaround-land, detect when a regular PyXxx()
+ # function is invoked at .so load-time, e.g. by a C++ global
+ # variable with an initializer, and in this case make sure we
+ # initialize things.
+ space.fromcache(State).make_sure_cpyext_is_imported()
elif pygilstate_ensure:
if cpyext_glob_tid_ptr[0] == tid:
cpyext_glob_tid_ptr[0] = 0
@@ -1719,8 +1725,8 @@
def load_cpyext_module(space, name, path, dll, initptr):
from rpython.rlib import rdynload
- space.getbuiltinmodule("cpyext") # mandatory to init cpyext
state = space.fromcache(State)
+ state.make_sure_cpyext_is_imported()
w_mod = state.find_extension(name, path)
if w_mod is not None:
rdynload.dlclose(dll)
diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py
--- a/pypy/module/cpyext/state.py
+++ b/pypy/module/cpyext/state.py
@@ -45,6 +45,13 @@
# XXX will leak if _PyDateTime_Import already called
self.datetimeAPI = []
+ self.cpyext_is_imported = False
+
+ def make_sure_cpyext_is_imported(self):
+ if not self.cpyext_is_imported:
+ self.space.getbuiltinmodule("cpyext") # mandatory to init cpyext
+ self.cpyext_is_imported = True
+
def set_exception(self, operror):
self.clear_exception()
ec = self.space.getexecutioncontext()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit