Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3.6 Changeset: r97042:c1cbd6d85ee4 Date: 2019-08-01 16:43 +0100 http://bitbucket.org/pypy/pypy/changeset/c1cbd6d85ee4/
Log: hg merge default 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 @@ -1021,6 +1021,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 @@ -1749,8 +1755,8 @@ from rpython.rlib import rdynload from pypy.module.cpyext.pyobject import get_w_obj_and_decref - 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() diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py --- a/rpython/rlib/rfile.py +++ b/rpython/rlib/rfile.py @@ -312,6 +312,10 @@ if not self._ll_file: raise ValueError("I/O operation on closed file") + @property + def closed(self): + return not self._ll_file + def _fread(self, buf, n, stream): if not self._univ_newline: return c_fread(buf, 1, n, stream) diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py --- a/rpython/rlib/test/test_rfile.py +++ b/rpython/rlib/test/test_rfile.py @@ -411,7 +411,10 @@ def f(): with open(fname, "w") as f: f.write("dupa") + assert not f.closed + try: + assert f.closed f.write("dupb") except ValueError: pass _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit