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/Modules/gcmodule.c b/Modules/gcmodule.c
index f0d5699..21f6bd1 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -161,9 +161,9 @@ _PyGC_InitState(GCState *gcstate)
PyStatus
-_PyGC_Init(PyThreadState *tstate)
+_PyGC_Init(PyInterpreterState *interp)
{
- GCState *gcstate = &tstate->interp->gc;
+ GCState *gcstate = &interp->gc;
gcstate->garbage = PyList_New(0);
if (gcstate->garbage == NULL) {
@@ -1036,15 +1036,15 @@ delete_garbage(PyThreadState *tstate, GCState *gcstate,
* Clearing the free lists may give back memory to the OS earlier.
*/
static void
-clear_freelists(PyThreadState *tstate)
+clear_freelists(PyInterpreterState *interp)
{
- _PyFrame_ClearFreeList(tstate);
- _PyTuple_ClearFreeList(tstate);
- _PyFloat_ClearFreeList(tstate);
- _PyList_ClearFreeList(tstate);
- _PyDict_ClearFreeList(tstate);
- _PyAsyncGen_ClearFreeLists(tstate);
- _PyContext_ClearFreeList(tstate);
+ _PyFrame_ClearFreeList(interp);
+ _PyTuple_ClearFreeList(interp);
+ _PyFloat_ClearFreeList(interp);
+ _PyList_ClearFreeList(interp);
+ _PyDict_ClearFreeList(interp);
+ _PyAsyncGen_ClearFreeLists(interp);
+ _PyContext_ClearFreeList(interp);
}
// Show stats for objects in each generations
@@ -1323,7 +1323,7 @@ gc_collect_main(PyThreadState *tstate, int generation,
/* Clear free list only during the collection of the highest
* generation */
if (generation == NUM_GENERATIONS-1) {
- clear_freelists(tstate);
+ clear_freelists(tstate->interp);
}
if (_PyErr_Occurred(tstate)) {
@@ -2092,9 +2092,9 @@ _PyGC_CollectNoFail(PyThreadState *tstate)
}
void
-_PyGC_DumpShutdownStats(PyThreadState *tstate)
+_PyGC_DumpShutdownStats(PyInterpreterState *interp)
{
- GCState *gcstate = &tstate->interp->gc;
+ GCState *gcstate = &interp->gc;
if (!(gcstate->debug & DEBUG_SAVEALL)
&& gcstate->garbage != NULL && PyList_GET_SIZE(gcstate->garbage) > 0) {
const char *message;
@@ -2129,9 +2129,9 @@ _PyGC_DumpShutdownStats(PyThreadState *tstate)
}
void
-_PyGC_Fini(PyThreadState *tstate)
+_PyGC_Fini(PyInterpreterState *interp)
{
- GCState *gcstate = &tstate->interp->gc;
+ GCState *gcstate = &interp->gc;
Py_CLEAR(gcstate->garbage);
Py_CLEAR(gcstate->callbacks);
}