[3.14] gh-142975: During GC, mark frozen objects with a merged zero refcount for destruction (GH-143156) (GH-143175)

gh-142975: During GC, mark frozen objects with a merged zero refcount for destruction (GH-143156)
(cherry picked from commit 8611f74e08)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
Miss Islington (bot)
2025-12-25 18:00:42 +01:00
committed by GitHub
parent 02282e5479
commit 8a61b71eee
3 changed files with 39 additions and 1 deletions
+5 -1
View File
@@ -905,7 +905,11 @@ exit:
static void
queue_untracked_obj_decref(PyObject *op, struct collection_state *state)
{
if (!_PyObject_GC_IS_TRACKED(op)) {
assert(Py_REFCNT(op) == 0);
// gh-142975: We have to treat frozen objects as untracked in this function
// or else they might be picked up in a future collection, which breaks the
// assumption that all incoming objects have a non-zero reference count.
if (!_PyObject_GC_IS_TRACKED(op) || gc_is_frozen(op)) {
// GC objects with zero refcount are handled subsequently by the
// GC as if they were cyclic trash, but we have to handle dead
// non-GC objects here. Add one to the refcount so that we can