diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-04-11 00:21:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-11 00:21:54 (GMT) |
commit | f13072b8a89a922285737988b086beb4b06c6648 (patch) | |
tree | 14b73d6eb614949e2ce81db59f13c3b13eb475d9 /Modules | |
parent | 0361556537686f857f1025ead75e6af4ca7cc94a (diff) | |
download | cpython-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')
-rw-r--r-- | Modules/_testcapimodule.c | 2 | ||||
-rw-r--r-- | Modules/gcmodule.c | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 3cc5586..0a30fea 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3588,7 +3588,7 @@ slot_tp_del(PyObject *self) _Py_NewReference(self); Py_SET_REFCNT(self, refcnt); } - assert(!PyType_IS_GC(Py_TYPE(self)) || _PyObject_GC_IS_TRACKED(self)); + assert(!PyType_IS_GC(Py_TYPE(self)) || PyObject_GC_IsTracked(self)); /* If Py_REF_DEBUG macro is defined, _Py_NewReference() increased _Py_RefTotal, so we need to undo that. */ #ifdef Py_REF_DEBUG 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; +} |