From 09532feeece39d5ba68a0d47115ce1967bfbd58e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 10 May 2019 23:39:09 +0200 Subject: bpo-36710: Add 'ceval' local variable to ceval.c (GH-12934) Add "struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;" local variables to function to better highlight the dependency on the global variable _PyRuntime and to point directly to _PyRuntime.ceval field rather than on the larger _PyRuntime. Changes: * Add _PyRuntimeState_GetThreadState(runtime) macro. * Add _PyEval_AddPendingCall(ceval, ...) and _PyThreadState_Swap(gilstate, ...) functions. * _PyThreadState_GET() macro now calls _PyRuntimeState_GetThreadState() using &_PyRuntime. * Add 'ceval' parameter to COMPUTE_EVAL_BREAKER(), SIGNAL_PENDING_SIGNALS(), _PyEval_SignalAsyncExc(), _PyEval_SignalReceived() and _PyEval_FiniThreads() macros and functions. * Add 'tstate' parameter to call_function(), do_call_core() and do_raise(). * Add 'runtime' parameter to _Py_CURRENTLY_FINALIZING(), _Py_FinishPendingCalls() and _PyThreadState_DeleteExcept() macros and functions. * Declare 'runtime', 'tstate', 'ceval' and 'eval_breaker' variables as constant. --- Python/pylifecycle.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 32902aa0d5..de8595ccb5 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -4,8 +4,9 @@ #include "Python-ast.h" #undef Yield /* undefine macro conflicting with */ -#include "pycore_coreconfig.h" +#include "pycore_ceval.h" #include "pycore_context.h" +#include "pycore_coreconfig.h" #include "pycore_fileutils.h" #include "pycore_hamt.h" #include "pycore_pathconfig.h" @@ -527,7 +528,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime, another running thread (see issue #9901). Instead we destroy the previously created GIL here, which ensures that we can call Py_Initialize / Py_FinalizeEx multiple times. */ - _PyEval_FiniThreads(); + _PyEval_FiniThreads(&runtime->ceval); /* Auto-thread-state API */ _PyGILState_Init(runtime, interp, tstate); @@ -1135,10 +1136,10 @@ Py_FinalizeEx(void) wait_for_thread_shutdown(); // Make any remaining pending calls. - _Py_FinishPendingCalls(); + _Py_FinishPendingCalls(runtime); /* Get current thread state and interpreter pointer */ - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime); PyInterpreterState *interp = tstate->interp; /* The interpreter is still entirely intact at this point, and the -- cgit v1.2.1