mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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>
This commit is contained in:
parent
1dad23edbc
commit
e001027188
6 changed files with 121 additions and 20 deletions
11
Python/gc.c
11
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue