From 80eeee9f941acc3754f4602db42981d31f369cf0 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Wed, 10 Sep 2025 23:49:26 +0500 Subject: [PATCH 1/3] Remove trash_delete_later and trash_delete_nesting from _gc_runtime_state --- Include/internal/pycore_interp_structs.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Include/internal/pycore_interp_structs.h b/Include/internal/pycore_interp_structs.h index fa9568ab4d0e85..e3a66ea5f53b62 100644 --- a/Include/internal/pycore_interp_structs.h +++ b/Include/internal/pycore_interp_structs.h @@ -202,12 +202,6 @@ enum _GCPhase { #define NUM_GENERATIONS 3 struct _gc_runtime_state { - /* List of objects that still need to be cleaned up, singly linked - * via their gc headers' gc_prev pointers. */ - PyObject *trash_delete_later; - /* Current call-stack depth of tp_dealloc calls. */ - int trash_delete_nesting; - /* Is automatic collection enabled? */ int enabled; int debug; From dff746fad6f0eaaf1d2ca33e36eebe46ede8f9b2 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Wed, 10 Sep 2025 23:50:36 +0500 Subject: [PATCH 2/3] Add comments for delete_later from _ts --- Include/cpython/pystate.h | 2 ++ Objects/object.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 555641943423b4..224096b9a240a6 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -157,6 +157,8 @@ struct _ts { */ unsigned long native_thread_id; + /* List of objects that still need to be cleaned up, singly linked + * via their gc headers' gc_next pointers. */ PyObject *delete_later; /* Tagged pointer to top-most critical section, or zero if there is no diff --git a/Objects/object.c b/Objects/object.c index bd3ba02f8eb255..f0b62b971d81b9 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -3050,7 +3050,7 @@ Py_ReprLeave(PyObject *obj) /* Trashcan support. */ -/* Add op to the gcstate->trash_delete_later list. Called when the current +/* Add op to the tstate->delete_later list. Called when the current * call-stack depth gets large. op must be a gc'ed object, with refcount 0. * Py_DECREF must already have been called on it. */ @@ -3076,7 +3076,7 @@ _PyTrash_thread_deposit_object(PyThreadState *tstate, PyObject *op) tstate->delete_later = op; } -/* Deallocate all the objects in the gcstate->trash_delete_later list. +/* Deallocate all the objects in the tstate->delete_later list. * Called when the call-stack unwinds again. */ void _PyTrash_thread_destroy_chain(PyThreadState *tstate) From 78af3bd9b5e6ca74aeacf4fc35e46c51c5d43a98 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Wed, 17 Sep 2025 22:03:30 +0500 Subject: [PATCH 3/3] Mention _PyTrash_thread_deposit_object and _PyTrash_thread_destroy_chain --- Include/cpython/pystate.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 224096b9a240a6..bd9d8aaefe5400 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -158,7 +158,10 @@ struct _ts { unsigned long native_thread_id; /* List of objects that still need to be cleaned up, singly linked - * via their gc headers' gc_next pointers. */ + * via their gc headers' gc_next pointers. The list is populated by + * _PyTrash_thread_deposit_object and cleaned up by + * _PyTrash_thread_destroy_chain. + */ PyObject *delete_later; /* Tagged pointer to top-most critical section, or zero if there is no