bpo-43439: Add audit hooks for gc functions (GH-24794)
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 21f6bd1..225da2b 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1690,6 +1690,10 @@ Return the list of objects that directly refer to any of objs.");
static PyObject *
gc_get_referrers(PyObject *self, PyObject *args)
{
+ if (PySys_Audit("gc.get_referrers", "O", args) < 0) {
+ return NULL;
+ }
+
PyObject *result = PyList_New(0);
if (!result) {
return NULL;
@@ -1720,6 +1724,9 @@ static PyObject *
gc_get_referents(PyObject *self, PyObject *args)
{
Py_ssize_t i;
+ if (PySys_Audit("gc.get_referents", "O", args) < 0) {
+ return NULL;
+ }
PyObject *result = PyList_New(0);
if (result == NULL)
@@ -1762,6 +1769,10 @@ gc_get_objects_impl(PyObject *module, Py_ssize_t generation)
PyObject* result;
GCState *gcstate = &tstate->interp->gc;
+ if (PySys_Audit("gc.get_objects", "n", generation) < 0) {
+ return NULL;
+ }
+
result = PyList_New(0);
if (result == NULL) {
return NULL;