summaryrefslogtreecommitdiff
path: root/Modules/gcmodule.c
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-01-14 12:06:45 +0000
committerGitHub <noreply@github.com>2020-01-14 12:06:45 +0000
commita2ec3f07f7f028ff6229d6be2a7cfbda1f4efaeb (patch)
tree2ca30015db1da7016d3f0eff8e253dcfc298452a /Modules/gcmodule.c
parent1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d (diff)
downloadcpython-git-a2ec3f07f7f028ff6229d6be2a7cfbda1f4efaeb.tar.gz
bpo-39322: Add gc.is_finalized to check if an object has been finalised by the gc (GH-17989)
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r--Modules/gcmodule.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 5fef114d73..4ad9d228f5 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1870,6 +1870,25 @@ gc_is_tracked(PyObject *module, PyObject *obj)
}
/*[clinic input]
+gc.is_finalized
+
+ obj: object
+ /
+
+Returns true if the object has been already finalized by the GC.
+[clinic start generated code]*/
+
+static PyObject *
+gc_is_finalized(PyObject *module, PyObject *obj)
+/*[clinic end generated code: output=e1516ac119a918ed input=201d0c58f69ae390]*/
+{
+ if (PyObject_IS_GC(obj) && _PyGCHead_FINALIZED(AS_GC(obj))) {
+ Py_RETURN_TRUE;
+ }
+ Py_RETURN_FALSE;
+}
+
+/*[clinic input]
gc.freeze
Freeze all current tracked objects and ignore them for future collections.
@@ -1961,6 +1980,7 @@ static PyMethodDef GcMethods[] = {
GC_GET_OBJECTS_METHODDEF
GC_GET_STATS_METHODDEF
GC_IS_TRACKED_METHODDEF
+ GC_IS_FINALIZED_METHODDEF
{"get_referrers", gc_get_referrers, METH_VARARGS,
gc_get_referrers__doc__},
{"get_referents", gc_get_referents, METH_VARARGS,