summaryrefslogtreecommitdiffstats
path: root/Modules/gcmodule.c
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-04-11 00:21:54 (GMT)
committerGitHub <noreply@github.com>2020-04-11 00:21:54 (GMT)
commitf13072b8a89a922285737988b086beb4b06c6648 (patch)
tree14b73d6eb614949e2ce81db59f13c3b13eb475d9 /Modules/gcmodule.c
parent0361556537686f857f1025ead75e6af4ca7cc94a (diff)
downloadcpython-f13072b8a89a922285737988b086beb4b06c6648.zip
cpython-f13072b8a89a922285737988b086beb4b06c6648.tar.gz
cpython-f13072b8a89a922285737988b086beb4b06c6648.tar.bz2
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.
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r--Modules/gcmodule.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 1bc41fb..1754182 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -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;
+}