Skip to content

Commit 67e0de6

Browse files
authored
bpo-36854: gcmodule.c gets its state from tstate (GH-17285)
* Add GCState type for readability * gcmodule.c now gets its gcstate from tstate * _PyGC_DumpShutdownStats() now expects tstate rather than runtime * Rename "state" to "gcstate" for readability: to avoid confusion between "state" and "tstate" for example. * collect() now only expects tstate: it gets gcstate from tstate. * Pass tstate to _PyErr_xxx() functions
1 parent 9da7430 commit 67e0de6

File tree

4 files changed

+192
-163
lines changed

4 files changed

+192
-163
lines changed

Include/internal/pycore_object.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content);
1818
* NB: While the object is tracked by the collector, it must be safe to call the
1919
* ob_traverse method.
2020
*
21-
* Internal note: _PyRuntime.gc.generation0->_gc_prev doesn't have any bit flags
21+
* Internal note: interp->gc.generation0->_gc_prev doesn't have any bit flags
2222
* because it's not object header. So we don't use _PyGCHead_PREV() and
2323
* _PyGCHead_SET_PREV() for it to avoid unnecessary bitwise operations.
2424
*
@@ -37,11 +37,13 @@ static inline void _PyObject_GC_TRACK_impl(const char *filename, int lineno,
3737
"object is in generation which is garbage collected",
3838
filename, lineno, "_PyObject_GC_TRACK");
3939

40-
PyGC_Head *last = (PyGC_Head*)(_PyRuntime.gc.generation0->_gc_prev);
40+
PyThreadState *tstate = _PyThreadState_GET();
41+
PyGC_Head *generation0 = tstate->interp->runtime->gc.generation0;
42+
PyGC_Head *last = (PyGC_Head*)(generation0->_gc_prev);
4143
_PyGCHead_SET_NEXT(last, gc);
4244
_PyGCHead_SET_PREV(gc, last);
43-
_PyGCHead_SET_NEXT(gc, _PyRuntime.gc.generation0);
44-
_PyRuntime.gc.generation0->_gc_prev = (uintptr_t)gc;
45+
_PyGCHead_SET_NEXT(gc, generation0);
46+
generation0->_gc_prev = (uintptr_t)gc;
4547
}
4648

4749
#define _PyObject_GC_TRACK(op) \

Include/internal/pycore_pylifecycle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extern void _PyWarnings_Fini(PyInterpreterState *interp);
8989
extern void _PyGILState_Init(PyThreadState *tstate);
9090
extern void _PyGILState_Fini(PyThreadState *tstate);
9191

92-
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(struct pyruntimestate *runtime);
92+
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(PyThreadState *tstate);
9393

9494
PyAPI_FUNC(PyStatus) _Py_PreInitializeFromPyArgv(
9595
const PyPreConfig *src_config,

0 commit comments

Comments
 (0)