Commit 352a8b64 authored by Stefan Behnel's avatar Stefan Behnel

Use new PyGC_Enable() and PyGC_Disable() functions in CPython 3.10 where we...

Use new PyGC_Enable() and PyGC_Disable() functions in CPython 3.10 where we need to temporarily disable the GC.
parent db1a7dab
......@@ -72,8 +72,15 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
{
// Make sure GC does not pick up our non-heap type as heap type with this hack!
// For details, see https://github.com/cython/cython/issues/3603
PyObject *ret, *py_status;
int gc_was_enabled;
#if PY_VERSION_HEX >= 0x030A00b1
// finally added in Py3.10 :)
gc_was_enabled = PyGC_Disable();
(void)__Pyx_PyObject_CallMethod0;
#else
// Call gc.disable() as a backwards compatible fallback, but only if needed.
PyObject *ret, *py_status;
PyObject *gc = NULL;
#if PY_VERSION_HEX >= 0x030700a1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400)
// https://foss.heptapod.net/pypy/pypy/-/issues/3385
......@@ -99,6 +106,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
Py_DECREF(gc);
return -1;
}
#endif
// As of https://bugs.python.org/issue22079
// PyType_Ready enforces that all bases of a non-heap type are
......@@ -119,6 +127,9 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE;
if (gc_was_enabled) {
#if PY_VERSION_HEX >= 0x030A00b1
PyGC_Enable();
#else
PyObject *t, *v, *tb;
PyErr_Fetch(&t, &v, &tb);
ret = __Pyx_PyObject_CallMethod0(gc, PYUNICODE("enable"));
......@@ -135,6 +146,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
}
}
Py_DECREF(gc);
#endif
}
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment