Commit a29b2a6b authored by Stefan Behnel's avatar Stefan Behnel

Revert "Efficiency improvements for enabling/disabling gc in __Pyx_PyType_Ready()."

This change introduced Python object statics, which has a negative impact on multiple interpreter support etc.

This reverts commit b68f2585.
parent 3048be77
...@@ -8,7 +8,6 @@ static int __Pyx_PyType_Ready(PyTypeObject *t);/*proto*/ ...@@ -8,7 +8,6 @@ static int __Pyx_PyType_Ready(PyTypeObject *t);/*proto*/
#endif #endif
/////////////// PyType_Ready /////////////// /////////////// PyType_Ready ///////////////
//@requires: ObjectHandling.c::PyObjectCallNoArg
#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API
// Wrapper around PyType_Ready() with some runtime checks and fixes // Wrapper around PyType_Ready() with some runtime checks and fixes
...@@ -74,35 +73,24 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) { ...@@ -74,35 +73,24 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
// For details, see https://github.com/cython/cython/issues/3603 // For details, see https://github.com/cython/cython/issues/3603
PyObject *ret, *py_status; PyObject *ret, *py_status;
int gc_was_enabled; int gc_was_enabled;
static PyObject *gc = NULL; PyObject *gc = PyImport_Import(PYUNICODE("gc"));
static PyObject *gc_isenabled = NULL, *gc_enable = NULL, *gc_disable = NULL; if (unlikely(!gc)) return -1;
if (unlikely(!gc)) { py_status = PyObject_CallMethodObjArgs(gc, PYUNICODE("isenabled"), NULL);
gc = PyImport_Import(PYUNICODE("gc"));
if (unlikely(!gc)) return -1;
gc_isenabled = PyObject_GetAttr(gc, PYUNICODE("isenabled"));
gc_enable = PyObject_GetAttr(gc, PYUNICODE("enable"));
gc_disable = PyObject_GetAttr(gc, PYUNICODE("disable"));
if (unlikely(!gc_isenabled || !gc_enable || !gc_disable)) {
Py_XDECREF(gc_isenabled); gc_isenabled = NULL;
Py_XDECREF(gc_enable); gc_enable = NULL;
Py_XDECREF(gc_disable); gc_disable = NULL;
Py_XDECREF(gc); gc = NULL;
return -1;
}
}
py_status = __Pyx_PyObject_CallNoArg(gc_isenabled);
if (unlikely(!py_status)) { if (unlikely(!py_status)) {
Py_DECREF(gc);
return -1; return -1;
} }
gc_was_enabled = __Pyx_PyObject_IsTrue(py_status); gc_was_enabled = __Pyx_PyObject_IsTrue(py_status);
Py_DECREF(py_status); Py_DECREF(py_status);
if (gc_was_enabled > 0) { if (gc_was_enabled > 0) {
ret = __Pyx_PyObject_CallNoArg(gc_disable); ret = PyObject_CallMethodObjArgs(gc, PYUNICODE("disable"), NULL);
if (unlikely(!ret)) { if (unlikely(!ret)) {
Py_DECREF(gc);
return -1; return -1;
} }
Py_DECREF(ret); Py_DECREF(ret);
} else if (unlikely(gc_was_enabled == -1)) { } else if (unlikely(gc_was_enabled == -1)) {
Py_DECREF(gc);
return -1; return -1;
} }
...@@ -124,7 +112,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) { ...@@ -124,7 +112,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
if (gc_was_enabled) { if (gc_was_enabled) {
PyObject *t, *v, *tb; PyObject *t, *v, *tb;
PyErr_Fetch(&t, &v, &tb); PyErr_Fetch(&t, &v, &tb);
ret = __Pyx_PyObject_CallNoArg(gc_enable); ret = PyObject_CallMethodObjArgs(gc, PYUNICODE("enable"), NULL);
if (likely(ret || r == -1)) { if (likely(ret || r == -1)) {
Py_XDECREF(ret); Py_XDECREF(ret);
// do not overwrite exceptions raised by PyType_Ready() above // do not overwrite exceptions raised by PyType_Ready() above
...@@ -137,6 +125,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) { ...@@ -137,6 +125,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
r = -1; r = -1;
} }
} }
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