mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
gh-112529: Implement GC for free-threaded builds (#114262)
* gh-112529: Implement GC for free-threaded builds This implements a mark and sweep GC for the free-threaded builds of CPython. The implementation relies on mimalloc to find GC tracked objects (i.e., "containers").
This commit is contained in:
parent
4850410b60
commit
b52fc70d1a
18 changed files with 1952 additions and 22 deletions
|
@ -15,6 +15,8 @@
|
|||
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
|
||||
#include "pydtrace.h"
|
||||
|
||||
#ifndef Py_GIL_DISABLED
|
||||
|
||||
typedef struct _gc_runtime_state GCState;
|
||||
|
||||
#ifdef Py_DEBUG
|
||||
|
@ -964,10 +966,10 @@ finalize_garbage(PyThreadState *tstate, PyGC_Head *collectable)
|
|||
PyGC_Head *gc = GC_NEXT(collectable);
|
||||
PyObject *op = FROM_GC(gc);
|
||||
gc_list_move(gc, &seen);
|
||||
if (!_PyGCHead_FINALIZED(gc) &&
|
||||
if (!_PyGC_FINALIZED(op) &&
|
||||
(finalize = Py_TYPE(op)->tp_finalize) != NULL)
|
||||
{
|
||||
_PyGCHead_SET_FINALIZED(gc);
|
||||
_PyGC_SET_FINALIZED(op);
|
||||
Py_INCREF(op);
|
||||
finalize(op);
|
||||
assert(!_PyErr_Occurred(tstate));
|
||||
|
@ -1942,3 +1944,5 @@ PyUnstable_GC_VisitObjects(gcvisitobjects_t callback, void *arg)
|
|||
done:
|
||||
gcstate->enabled = origenstate;
|
||||
}
|
||||
|
||||
#endif // Py_GIL_DISABLED
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue