bpo-43268: Pass interp rather than tstate to internal functions (GH-24580)
Pass the current interpreter (interp) rather than the current Python
thread state (tstate) to internal functions which only use the
interpreter.
Modified functions:
* _PyXXX_Fini() and _PyXXX_ClearFreeList() functions
* _PyEval_SignalAsyncExc(), make_pending_calls()
* _PySys_GetObject(), sys_set_object(), sys_set_object_id(), sys_set_object_str()
* should_audit(), set_flags_from_config(), make_flags()
* _PyAtExit_Call()
* init_stdio_encoding()
* etc.
diff --git a/Python/pystate.c b/Python/pystate.c
index f4fd039..1623bab 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -324,7 +324,7 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
/* Last garbage collection on this interpreter */
_PyGC_CollectNoFail(tstate);
- _PyGC_Fini(tstate);
+ _PyGC_Fini(interp);
/* We don't clear sysdict and builtins until the end of this function.
Because clearing other attributes can execute arbitrary Python code
@@ -1146,7 +1146,7 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
HEAD_UNLOCK(runtime);
Py_XDECREF(old_exc);
- _PyEval_SignalAsyncExc(tstate);
+ _PyEval_SignalAsyncExc(tstate->interp);
return 1;
}
HEAD_UNLOCK(runtime);
@@ -1357,9 +1357,9 @@ _PyGILState_GetInterpreterStateUnsafe(void)
}
void
-_PyGILState_Fini(PyThreadState *tstate)
+_PyGILState_Fini(PyInterpreterState *interp)
{
- struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
+ struct _gilstate_runtime_state *gilstate = &interp->runtime->gilstate;
PyThread_tss_delete(&gilstate->autoTSSkey);
gilstate->autoInterpreterState = NULL;
}