summaryrefslogtreecommitdiffstats
path: root/Modules/gcmodule.c
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2021-04-28 16:12:16 (GMT)
committerGitHub <noreply@github.com>2021-04-28 16:12:16 (GMT)
commit3cc481b9de43c234889c8010e7da3af7c0f42319 (patch)
tree1166babff0120ad235c37789907d640eec280c8f /Modules/gcmodule.c
parentbaecfbd849dbf42360d3a84af6cc13160838f24d (diff)
downloadcpython-3cc481b9de43c234889c8010e7da3af7c0f42319.zip
cpython-3cc481b9de43c234889c8010e7da3af7c0f42319.tar.gz
cpython-3cc481b9de43c234889c8010e7da3af7c0f42319.tar.bz2
bpo-28254: Add a C-API for controlling the GC state (GH-25687)
Add new C-API functions to control the state of the garbage collector: PyGC_Enable(), PyGC_Disable(), PyGC_IsEnabled(), corresponding to the functions in the gc module. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r--Modules/gcmodule.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index d6b5142..e5e5aa3 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1484,8 +1484,7 @@ static PyObject *
gc_enable_impl(PyObject *module)
/*[clinic end generated code: output=45a427e9dce9155c input=81ac4940ca579707]*/
{
- GCState *gcstate = get_gc_state();
- gcstate->enabled = 1;
+ PyGC_Enable();
Py_RETURN_NONE;
}
@@ -1499,8 +1498,7 @@ static PyObject *
gc_disable_impl(PyObject *module)
/*[clinic end generated code: output=97d1030f7aa9d279 input=8c2e5a14e800d83b]*/
{
- GCState *gcstate = get_gc_state();
- gcstate->enabled = 0;
+ PyGC_Disable();
Py_RETURN_NONE;
}
@@ -1514,8 +1512,7 @@ static int
gc_isenabled_impl(PyObject *module)
/*[clinic end generated code: output=1874298331c49130 input=30005e0422373b31]*/
{
- GCState *gcstate = get_gc_state();
- return gcstate->enabled;
+ return PyGC_IsEnabled();
}
/*[clinic input]
@@ -2053,6 +2050,32 @@ PyInit_gc(void)
return PyModuleDef_Init(&gcmodule);
}
+/* C API for controlling the state of the garbage collector */
+int
+PyGC_Enable(void)
+{
+ GCState *gcstate = get_gc_state();
+ int old_state = gcstate->enabled;
+ gcstate->enabled = 1;
+ return old_state;
+}
+
+int
+PyGC_Disable(void)
+{
+ GCState *gcstate = get_gc_state();
+ int old_state = gcstate->enabled;
+ gcstate->enabled = 0;
+ return old_state;
+}
+
+int
+PyGC_IsEnabled(void)
+{
+ GCState *gcstate = get_gc_state();
+ return gcstate->enabled;
+}
+
/* Public API to invoke gc.collect() from C */
Py_ssize_t
PyGC_Collect(void)