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:
Pablo Galindo 2020-04-11 01:21:54 +01:00 committed by GitHub
parent 0361556537
commit f13072b8a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 1 deletions

View file

@ -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;
}