mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-40241: Add PyObject_GC_IsTracked and PyObject_GC_IsFinalized to the public C-API (GH-19461)
Add the functions PyObject_GC_IsTracked and PyObject_GC_IsFinalized to the public API to allow to query if Python objects are being currently tracked or have been already finalized by the garbage collector respectively.
This commit is contained in:
parent
0361556537
commit
f13072b8a8
6 changed files with 50 additions and 1 deletions
|
@ -2312,3 +2312,21 @@ PyObject_GC_Del(void *op)
|
|||
}
|
||||
PyObject_FREE(g);
|
||||
}
|
||||
|
||||
int
|
||||
PyObject_GC_IsTracked(PyObject* obj)
|
||||
{
|
||||
if (PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
PyObject_GC_IsFinalized(PyObject *obj)
|
||||
{
|
||||
if (PyObject_IS_GC(obj) && _PyGCHead_FINALIZED(AS_GC(obj))) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue