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/pylifecycle.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index d349aaf6de..160f30ce6d 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -530,7 +530,7 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p, /* bpo-34008: For backward compatibility reasons, calling Py_Main() after Py_Initialize() ignores the new configuration. */ if (_PyRuntime.core_initialized) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (!tstate) { return _Py_INIT_ERR("failed to read thread state"); } @@ -1009,7 +1009,7 @@ Py_FinalizeEx(void) wait_for_thread_shutdown(); /* Get current thread state and interpreter pointer */ - tstate = PyThreadState_GET(); + tstate = _PyThreadState_GET(); interp = tstate->interp; /* The interpreter is still entirely intact at this point, and the @@ -1406,7 +1406,7 @@ Py_EndInterpreter(PyThreadState *tstate) { PyInterpreterState *interp = tstate->interp; - if (tstate != PyThreadState_GET()) + if (tstate != _PyThreadState_GET()) Py_FatalError("Py_EndInterpreter: thread is not current"); if (tstate->frame != NULL) Py_FatalError("Py_EndInterpreter: thread still has a frame"); @@ -1928,7 +1928,7 @@ fatal_error(const char *prefix, const char *msg, int status) and holds the GIL */ PyThreadState *tss_tstate = PyGILState_GetThisThreadState(); if (tss_tstate != NULL) { - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = _PyThreadState_GET(); if (tss_tstate != tstate) { /* The Python thread does not hold the GIL */ tss_tstate = NULL; -- cgit v1.2.1