diff options
author | Sam Gross <colesbury@gmail.com> | 2024-01-05 20:17:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-05 20:17:16 (GMT) |
commit | 99854ce1701ca4d1a0d153e501a29f9eec306ce5 (patch) | |
tree | 15eb59f79b9abbb5e23bfaadb37946fe01871dd1 /Include | |
parent | 0b7476080b58ea2ee71c6c1229994a3bb62fe4fa (diff) | |
download | cpython-99854ce1701ca4d1a0d153e501a29f9eec306ce5.zip cpython-99854ce1701ca4d1a0d153e501a29f9eec306ce5.tar.gz cpython-99854ce1701ca4d1a0d153e501a29f9eec306ce5.tar.bz2 |
gh-113688: Split up gcmodule.c (gh-113715)
This splits part of Modules/gcmodule.c of into Python/gc.c, which
now contains the core garbage collection implementation. The Python
module remain in the Modules/gcmodule.c file.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_gc.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h index 2d33aa7..2a79c40 100644 --- a/Include/internal/pycore_gc.h +++ b/Include/internal/pycore_gc.h @@ -64,6 +64,26 @@ static inline int _PyObject_GC_MAY_BE_TRACKED(PyObject *obj) { #define _PyGC_PREV_SHIFT (2) #define _PyGC_PREV_MASK (((uintptr_t) -1) << _PyGC_PREV_SHIFT) +/* set for debugging information */ +#define _PyGC_DEBUG_STATS (1<<0) /* print collection statistics */ +#define _PyGC_DEBUG_COLLECTABLE (1<<1) /* print collectable objects */ +#define _PyGC_DEBUG_UNCOLLECTABLE (1<<2) /* print uncollectable objects */ +#define _PyGC_DEBUG_SAVEALL (1<<5) /* save all garbage in gc.garbage */ +#define _PyGC_DEBUG_LEAK _PyGC_DEBUG_COLLECTABLE | \ + _PyGC_DEBUG_UNCOLLECTABLE | \ + _PyGC_DEBUG_SAVEALL + +typedef enum { + // GC was triggered by heap allocation + _Py_GC_REASON_HEAP, + + // GC was called during shutdown + _Py_GC_REASON_SHUTDOWN, + + // GC was called by gc.collect() or PyGC_Collect() + _Py_GC_REASON_MANUAL +} _PyGC_Reason; + // Lowest bit of _gc_next is used for flags only in GC. // But it is always 0 for normal code. static inline PyGC_Head* _PyGCHead_NEXT(PyGC_Head *gc) { @@ -203,8 +223,19 @@ struct _gc_runtime_state { extern void _PyGC_InitState(struct _gc_runtime_state *); +extern Py_ssize_t _PyGC_Collect(PyThreadState *tstate, int generation, + _PyGC_Reason reason); extern Py_ssize_t _PyGC_CollectNoFail(PyThreadState *tstate); +/* Freeze objects tracked by the GC and ignore them in future collections. */ +extern void _PyGC_Freeze(PyInterpreterState *interp); +/* Unfreezes objects placing them in the oldest generation */ +extern void _PyGC_Unfreeze(PyInterpreterState *interp); +/* Number of frozen objects */ +extern Py_ssize_t _PyGC_GetFreezeCount(PyInterpreterState *interp); + +extern PyObject *_PyGC_GetObjects(PyInterpreterState *interp, Py_ssize_t generation); +extern PyObject *_PyGC_GetReferrers(PyInterpreterState *interp, PyObject *objs); // Functions to clear types free lists extern void _PyTuple_ClearFreeList(PyInterpreterState *interp); |