From 50b48572d9a90c5bb36e2bef6179548ea927a35a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 1 Nov 2018 01:51:40 +0100 Subject: bpo-35081: Add _PyThreadState_GET() internal macro (GH-10266) If Py_BUILD_CORE is defined, the PyThreadState_GET() macro access _PyRuntime which comes from the internal pycore_state.h header. Public headers must not require internal headers. Move PyThreadState_GET() and _PyInterpreterState_GET_UNSAFE() from Include/pystate.h to Include/internal/pycore_state.h, and rename PyThreadState_GET() to _PyThreadState_GET() there. The PyThreadState_GET() macro of pystate.h is now redefined when pycore_state.h is included, to use the fast _PyThreadState_GET(). Changes: * Add _PyThreadState_GET() macro * Replace "PyThreadState_GET()->interp" with _PyInterpreterState_GET_UNSAFE() * Replace PyThreadState_GET() with _PyThreadState_GET() in internal C files (compiled with Py_BUILD_CORE defined), but keep PyThreadState_GET() in the public header files. * _testcapimodule.c: replace PyThreadState_GET() with PyThreadState_Get(); the module is not compiled with Py_BUILD_CORE defined. * pycore_state.h now requires Py_BUILD_CORE to be defined. --- Python/pystate.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index c77902a7f9..c193a10c8c 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -307,7 +307,7 @@ _PyInterpreterState_DeleteExceptMain() PyInterpreterState * _PyInterpreterState_Get(void) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (tstate == NULL) { Py_FatalError("_PyInterpreterState_Get(): no current thread state"); } @@ -689,7 +689,7 @@ tstate_delete_common(PyThreadState *tstate) void PyThreadState_Delete(PyThreadState *tstate) { - if (tstate == PyThreadState_GET()) + if (tstate == _PyThreadState_GET()) Py_FatalError("PyThreadState_Delete: tstate is still current"); if (_PyRuntime.gilstate.autoInterpreterState && PyThread_tss_get(&_PyRuntime.gilstate.autoTSSkey) == tstate) @@ -703,7 +703,7 @@ PyThreadState_Delete(PyThreadState *tstate) void PyThreadState_DeleteCurrent() { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (tstate == NULL) Py_FatalError( "PyThreadState_DeleteCurrent: no current tstate"); @@ -758,14 +758,14 @@ _PyThreadState_DeleteExcept(PyThreadState *tstate) PyThreadState * _PyThreadState_UncheckedGet(void) { - return PyThreadState_GET(); + return _PyThreadState_GET(); } PyThreadState * PyThreadState_Get(void) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (tstate == NULL) Py_FatalError("PyThreadState_Get: no current thread"); @@ -776,7 +776,7 @@ PyThreadState_Get(void) PyThreadState * PyThreadState_Swap(PyThreadState *newts) { - PyThreadState *oldts = PyThreadState_GET(); + PyThreadState *oldts = _PyThreadState_GET(); _PyThreadState_SET(newts); /* It should not be possible for more than one thread state @@ -807,7 +807,7 @@ PyThreadState_Swap(PyThreadState *newts) PyObject * PyThreadState_GetDict(void) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (tstate == NULL) return NULL; @@ -958,7 +958,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate) { /* Must be the tstate for this thread */ assert(PyGILState_GetThisThreadState()==tstate); - return tstate == PyThreadState_GET(); + return tstate == _PyThreadState_GET(); } /* Internal initialization/finalization functions called by @@ -1085,7 +1085,7 @@ PyGILState_Check(void) return 1; } - tstate = PyThreadState_GET(); + tstate = _PyThreadState_GET(); if (tstate == NULL) return 0; -- cgit v1.2.1