diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-05-03 03:30:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 03:30:03 (GMT) |
commit | de64e7561680fdc5358001e9488091e75d4174a3 (patch) | |
tree | f89d99c8d18a03f9613056b4bd76486ebb68ec6b /Modules/gcmodule.c | |
parent | 872cbc613245db7a1fc5e6656ed0135d2e115f50 (diff) | |
download | cpython-de64e7561680fdc5358001e9488091e75d4174a3.zip cpython-de64e7561680fdc5358001e9488091e75d4174a3.tar.gz cpython-de64e7561680fdc5358001e9488091e75d4174a3.tar.bz2 |
gh-94673: More Per-Interpreter Fields for Builtin Static Types (gh-103912)
his involves moving tp_dict, tp_bases, and tp_mro to PyInterpreterState, in the same way we did for tp_subclasses. Those three fields are effectively const for builtin static types (unlike tp_subclasses). In theory we only need to make their values immortal, along with their contents. However, that isn't such a simple proposition. (See gh-103823.) In the meantime the simplest solution is to move the fields into the interpreter.
One alternative is to statically allocate the values, but that's its own can of worms.
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r-- | Modules/gcmodule.c | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 8a4d1a4..f4d5186 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -2174,23 +2174,6 @@ _PyGC_DumpShutdownStats(PyInterpreterState *interp) } -static void -gc_fini_untrack(PyGC_Head *list) -{ - PyGC_Head *gc; - for (gc = GC_NEXT(list); gc != list; gc = GC_NEXT(list)) { - PyObject *op = FROM_GC(gc); - _PyObject_GC_UNTRACK(op); - // gh-92036: If a deallocator function expect the object to be tracked - // by the GC (ex: func_dealloc()), it can crash if called on an object - // which is no longer tracked by the GC. Leak one strong reference on - // purpose so the object is never deleted and its deallocator is not - // called. - Py_INCREF(op); - } -} - - void _PyGC_Fini(PyInterpreterState *interp) { @@ -2198,17 +2181,9 @@ _PyGC_Fini(PyInterpreterState *interp) Py_CLEAR(gcstate->garbage); Py_CLEAR(gcstate->callbacks); - if (!_Py_IsMainInterpreter(interp)) { - // bpo-46070: Explicitly untrack all objects currently tracked by the - // GC. Otherwise, if an object is used later by another interpreter, - // calling PyObject_GC_UnTrack() on the object crashs if the previous - // or the next object of the PyGC_Head structure became a dangling - // pointer. - for (int i = 0; i < NUM_GENERATIONS; i++) { - PyGC_Head *gen = GEN_HEAD(gcstate, i); - gc_fini_untrack(gen); - } - } + /* We expect that none of this interpreters objects are shared + with other interpreters. + See https://github.com/python/cpython/issues/90228. */ } /* for debugging */ |