summaryrefslogtreecommitdiffstats
path: root/Python/gc.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-08-15 16:09:11 (GMT)
committerGitHub <noreply@github.com>2024-08-15 16:09:11 (GMT)
commite001027188001f4bdf6ea16f70726ca0fabe85c4 (patch)
tree49ef595c47159c755e5e847f1aac863da92cc330 /Python/gc.c
parent1dad23edbc9db3a13268c1000c8dd428edba29f8 (diff)
downloadcpython-e001027188001f4bdf6ea16f70726ca0fabe85c4.zip
cpython-e001027188001f4bdf6ea16f70726ca0fabe85c4.tar.gz
cpython-e001027188001f4bdf6ea16f70726ca0fabe85c4.tar.bz2
gh-117139: Garbage collector support for deferred refcounting (#122956)
The free-threaded GC now visits interpreter stacks to keep objects that use deferred reference counting alive. Interpreter frames are zero initialized in the free-threaded GC so that the GC doesn't see garbage data. This is a temporary measure until stack spilling around escaping calls is implemented. Co-authored-by: Ken Jin <kenjin@python.org>
Diffstat (limited to 'Python/gc.c')
-rw-r--r--Python/gc.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Python/gc.c b/Python/gc.c
index 38a0da9..923a792 100644
--- a/Python/gc.c
+++ b/Python/gc.c
@@ -534,6 +534,17 @@ visit_decref(PyObject *op, void *parent)
return 0;
}
+int
+_PyGC_VisitFrameStack(_PyInterpreterFrame *frame, visitproc visit, void *arg)
+{
+ _PyStackRef *ref = _PyFrame_GetLocalsArray(frame);
+ /* locals and stack */
+ for (; ref < frame->stackpointer; ref++) {
+ Py_VISIT(PyStackRef_AsPyObjectBorrow(*ref));
+ }
+ return 0;
+}
+
/* Subtract internal references from gc_refs. After this, gc_refs is >= 0
* for all objects in containers, and is GC_REACHABLE for all tracked gc
* objects not in containers. The ones with gc_refs > 0 are directly