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.
diff --git a/Doc/c-api/gcsupport.rst b/Doc/c-api/gcsupport.rst
index 924a7fd..4cab0f5 100644
--- a/Doc/c-api/gcsupport.rst
+++ b/Doc/c-api/gcsupport.rst
@@ -60,6 +60,24 @@
followed by the :c:member:`~PyTypeObject.tp_traverse` handler become valid, usually near the
end of the constructor.
+.. c:function:: int PyObject_GC_IsTracked(PyObject *op)
+
+ Returns 1 if the object type of *op* implements the GC protocol and *op* is being
+ currently tracked by the garbage collector and 0 otherwise.
+
+ This is analogous to the Python function :func:`gc.is_tracked`.
+
+ .. versionadded:: 3.9
+
+
+.. c:function:: int PyObject_GC_IsFinalized(PyObject *op)
+
+ Returns 1 if the object type of *op* implements the GC protocol and *op* has been
+ already finalized by the garbage collector and 0 otherwise.
+
+ This is analogous to the Python function :func:`gc.is_finalized`.
+
+ .. versionadded:: 3.9
Similarly, the deallocator for the object must conform to a similar pair of
rules: