Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r90240:f9cd9cb3c6b5 Date: 2017-02-21 08:04 +0000 http://bitbucket.org/pypy/pypy/changeset/f9cd9cb3c6b5/
Log: hg merge default diff --git a/lib-python/2.7/sysconfig.py b/lib-python/2.7/sysconfig.py --- a/lib-python/2.7/sysconfig.py +++ b/lib-python/2.7/sysconfig.py @@ -529,7 +529,9 @@ for suffix, mode, type_ in imp.get_suffixes(): if type_ == imp.C_EXTENSION: _CONFIG_VARS['SOABI'] = suffix.split('.')[1] - break + break + _CONFIG_VARS['INCLUDEPY'] = os.path.join(_CONFIG_VARS['prefix'], + 'include') if args: vals = [] diff --git a/pypy/module/cpyext/pystate.py b/pypy/module/cpyext/pystate.py --- a/pypy/module/cpyext/pystate.py +++ b/pypy/module/cpyext/pystate.py @@ -1,6 +1,6 @@ from pypy.module.cpyext.api import ( - cpython_api, generic_cpy_call, CANNOT_FAIL, CConfig, cpython_struct) -from pypy.module.cpyext.pyobject import PyObject, Py_DecRef, make_ref, from_ref + cpython_api, CANNOT_FAIL, cpython_struct) +from pypy.module.cpyext.pyobject import PyObject, Py_DecRef, make_ref from pypy.interpreter.error import OperationError from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rlib import rthread @@ -29,8 +29,9 @@ the current thread must have acquired it. (This function is available even when thread support is disabled at compile time.)""" state = space.fromcache(InterpreterState) - tstate = state.swap_thread_state( - space, lltype.nullptr(PyThreadState.TO)) + ec = space.getexecutioncontext() + tstate = state._get_thread_state(space, ec).memory + ec.cpyext_threadstate_is_current = False return tstate @cpython_api([PyThreadState], lltype.Void, gil="acquire") @@ -40,8 +41,7 @@ NULL. If the lock has been created, the current thread must not have acquired it, otherwise deadlock ensues. (This function is available even when thread support is disabled at compile time.)""" - state = space.fromcache(InterpreterState) - state.swap_thread_state(space, tstate) + PyThreadState_Swap(space, tstate) @cpython_api([], lltype.Void) def PyEval_InitThreads(space): @@ -91,9 +91,11 @@ # released, so a check against that can't be used to determine the need for # initialization). ExecutionContext.cpyext_initialized_threadstate = False +ExecutionContext.cpyext_threadstate_is_current = True def cleanup_cpyext_state(self): self.cpyext_threadstate = None + self.cpyext_threadstate_is_current = True self.cpyext_initialized_threadstate = False ExecutionContext.cleanup_cpyext_state = cleanup_cpyext_state @@ -162,6 +164,7 @@ if not ec.cpyext_initialized_threadstate: ec.cpyext_threadstate = self.new_thread_state(space) ec.cpyext_initialized_threadstate = True + ec.cpyext_threadstate_is_current = True return ec.cpyext_threadstate @cpython_api([], PyThreadState, error=CANNOT_FAIL) @@ -185,7 +188,7 @@ meant that an exception was raised.""" state = space.fromcache(InterpreterState) ts = state.get_thread_state(space) - if not ts: + if not space.getexecutioncontext().cpyext_threadstate_is_current: return lltype.nullptr(PyObject.TO) return ts.c_dict @@ -193,8 +196,21 @@ def PyThreadState_Swap(space, tstate): """Swap the current thread state with the thread state given by the argument tstate, which may be NULL. The global interpreter lock must be held.""" + ec = space.getexecutioncontext() state = space.fromcache(InterpreterState) - return state.swap_thread_state(space, tstate) + old_tstate = state.get_thread_state(space) + if not ec.cpyext_threadstate_is_current: + old_tstate = lltype.nullptr(PyThreadState.TO) + if tstate: + if tstate != state.get_thread_state(space): + print "Error in cpyext, CPython compatibility layer:" + print "PyThreadState_Swap() cannot be used to switch to another" + print "different PyThreadState right now" + raise AssertionError + ec.cpyext_threadstate_is_current = True + else: + ec.cpyext_threadstate_is_current = False + return old_tstate @cpython_api([PyThreadState], lltype.Void, gil="acquire") def PyEval_AcquireThread(space, tstate): @@ -258,6 +274,7 @@ if not we_are_translated(): _workaround_cpython_untranslated(space) # + ec.cpyext_threadstate_is_current = True return rffi.cast(PyGILState_STATE, previous_state) @cpython_api([PyGILState_STATE], lltype.Void, gil="pygilstate_release") @@ -269,6 +286,7 @@ else: assert ec.cpyext_gilstate_counter_noleave == 0 assert oldstate == PyGILState_UNLOCKED + ec.cpyext_threadstate_is_current = False space.threadlocals.leave_thread(space) @cpython_api([], PyInterpreterState, error=CANNOT_FAIL) diff --git a/pypy/module/cpyext/test/test_api.py b/pypy/module/cpyext/test/test_api.py --- a/pypy/module/cpyext/test/test_api.py +++ b/pypy/module/cpyext/test/test_api.py @@ -66,7 +66,7 @@ raise try: - self.space.getexecutioncontext().cleanup_cpyext_threadstate() + self.space.getexecutioncontext().cleanup_cpyext_state() except AttributeError: pass diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py --- a/pypy/module/cpyext/test/test_cpyext.py +++ b/pypy/module/cpyext/test/test_cpyext.py @@ -105,7 +105,6 @@ del obj import gc; gc.collect() - space.getexecutioncontext().cleanup_cpyext_state() for w_obj in state.non_heaptypes_w: Py_DecRef(space, w_obj) @@ -182,6 +181,7 @@ def teardown_method(self, meth): if self.runappdirect: return + self.space.getexecutioncontext().cleanup_cpyext_state() self.cleanup_references(self.space) # XXX: like AppTestCpythonExtensionBase.teardown_method: # find out how to disable check_and_print_leaks() if the @@ -372,6 +372,7 @@ return for name in self.imported_module_names: self.unimport_module(name) + self.space.getexecutioncontext().cleanup_cpyext_state() self.cleanup_references(self.space) # XXX: find out how to disable check_and_print_leaks() if the # test failed... diff --git a/pypy/module/cpyext/test/test_pystate.py b/pypy/module/cpyext/test/test_pystate.py --- a/pypy/module/cpyext/test/test_pystate.py +++ b/pypy/module/cpyext/test/test_pystate.py @@ -79,8 +79,8 @@ return PyLong_FromLong(0); } - new_tstate = PyThreadState_Get(); /* fails on cpython */ - if (new_tstate != NULL) { + PyObject* d = PyThreadState_GetDict(); /* fails on cpython */ + if (d != NULL) { return PyLong_FromLong(1); } @@ -171,6 +171,26 @@ res = module.bounce() assert res == 4 + def test_nested_pygilstate_ensure(self): + module = self.import_extension('foo', [ + ("bounce", "METH_NOARGS", + """ + PyGILState_STATE gilstate; + PyThreadState *tstate; + PyObject *dict; + + if (PyEval_ThreadsInitialized() == 0) + PyEval_InitThreads(); + dict = PyThreadState_GetDict(); + gilstate = PyGILState_Ensure(); + PyGILState_Release(gilstate); + if (PyThreadState_GetDict() != dict) + return PyLong_FromLong(-2); + return PyLong_FromLong(4); + """)]) + res = module.bounce() + assert res == 4 + def test_threadsinitialized(self): module = self.import_extension('foo', [ ("test", "METH_NOARGS", diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -135,10 +135,7 @@ assert typedef is not None return self.fromcache(TypeCache).getorbuild(typedef) - # BACKCOMPAT: this function is still accepted for backward - # compatibility, but its usage should be progressively removed - # everywhere apart from tests. - #@not_rpython # only for tests + @not_rpython # only for tests @specialize.argtype(1) def wrap(self, x): """ Wraps the Python value 'x' into one of the wrapper classes. This diff --git a/rpython/translator/platform/darwin.py b/rpython/translator/platform/darwin.py --- a/rpython/translator/platform/darwin.py +++ b/rpython/translator/platform/darwin.py @@ -31,8 +31,12 @@ return self.rpath_flags def _args_for_shared(self, args): + if hasattr(self, '_exe_name'): + target = os.path.basename(self._exe_name) + else: + target = '$(TARGET)' # inside a Makefile return (list(self.shared_only) - + ['-dynamiclib', '-install_name', '@rpath/$(TARGET)', '-undefined', 'dynamic_lookup', '-flat_namespace'] + + ['-dynamiclib', '-install_name', '@rpath/' + target, '-undefined', 'dynamic_lookup', '-flat_namespace'] + args) def _include_dirs_for_libffi(self): diff --git a/rpython/translator/platform/posix.py b/rpython/translator/platform/posix.py --- a/rpython/translator/platform/posix.py +++ b/rpython/translator/platform/posix.py @@ -51,6 +51,7 @@ return ["-Wl,--export-dynamic"] def _link(self, cc, ofiles, link_args, standalone, exe_name): + self._exe_name = str(exe_name) args = [str(ofile) for ofile in ofiles] + link_args args += ['-o', str(exe_name)] if not standalone: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit