diff options
author | Brandt Bucher <brandtbucher@gmail.com> | 2020-10-15 01:44:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-15 01:44:07 (GMT) |
commit | c13b847a6f913b72eeb71651ff626390b738d973 (patch) | |
tree | b5cc26798d51fd3a93fd8cea1c5177fba49ddd94 /Modules/_testcapimodule.c | |
parent | 302b6166fbb15c51f58b040c62e987d486742189 (diff) | |
download | cpython-c13b847a6f913b72eeb71651ff626390b738d973.zip cpython-c13b847a6f913b72eeb71651ff626390b738d973.tar.gz cpython-c13b847a6f913b72eeb71651ff626390b738d973.tar.bz2 |
bpo-41984: GC track all user classes (GH-22701)
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 8c7544f..28d2c12 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3888,6 +3888,25 @@ with_tp_del(PyObject *self, PyObject *args) return obj; } +static PyObject * +without_gc(PyObject *Py_UNUSED(self), PyObject *obj) +{ + PyTypeObject *tp = (PyTypeObject*)obj; + if (!PyType_Check(obj) || !PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE)) { + return PyErr_Format(PyExc_TypeError, "heap type expected, got %R", obj); + } + if (PyType_IS_GC(tp)) { + // Don't try this at home, kids: + tp->tp_flags -= Py_TPFLAGS_HAVE_GC; + tp->tp_free = PyObject_Del; + tp->tp_traverse = NULL; + tp->tp_clear = NULL; + } + assert(!PyType_IS_GC(tp)); + Py_INCREF(obj); + return obj; +} + static PyMethodDef ml; static PyObject * @@ -5805,6 +5824,7 @@ static PyMethodDef TestMethods[] = { {"meth_fastcall", (PyCFunction)(void(*)(void))meth_fastcall, METH_FASTCALL}, {"meth_fastcall_keywords", (PyCFunction)(void(*)(void))meth_fastcall_keywords, METH_FASTCALL|METH_KEYWORDS}, {"pynumber_tobase", pynumber_tobase, METH_VARARGS}, + {"without_gc", without_gc, METH_O}, {NULL, NULL} /* sentinel */ }; |