summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2021-04-20 18:43:19 +0200
committerStefan Behnel <stefan_ml@behnel.de>2021-04-20 18:43:19 +0200
commitee712b9c032dfaaf9ca20dc6486c7de73b3f51f5 (patch)
tree95f18f582e4561e6d82ece2906d94f7bbc609e82
parent3aa0524228a02bb877c926a9b500825fccd94580 (diff)
parent434882af22b8c1941f078557b6411a1af63d099b (diff)
downloadcython-ee712b9c032dfaaf9ca20dc6486c7de73b3f51f5.tar.gz
Merge branch 'master' into clean_up_capi_features
-rw-r--r--Cython/Utility/ExtensionTypes.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/Cython/Utility/ExtensionTypes.c b/Cython/Utility/ExtensionTypes.c
index b8f54b6c7..f18cc671d 100644
--- a/Cython/Utility/ExtensionTypes.c
+++ b/Cython/Utility/ExtensionTypes.c
@@ -161,7 +161,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t);/*proto*/
#endif
/////////////// PyType_Ready ///////////////
-//@requires: ObjectHandling.c::PyObjectCallNoArg
+//@requires: ObjectHandling.c::PyObjectCallMethod0
//@requires: ValidateBasesTuple
#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API
@@ -179,35 +179,29 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
// For details, see https://github.com/cython/cython/issues/3603
PyObject *ret, *py_status;
int gc_was_enabled;
- static PyObject *gc = NULL;
- static PyObject *gc_isenabled = NULL, *gc_enable = NULL, *gc_disable = NULL;
- if (unlikely(!gc)) {
- 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);
+ 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
+ gc = PyImport_GetModule(PYUNICODE("gc"));
+ #endif
+ if (unlikely(!gc)) gc = PyImport_Import(PYUNICODE("gc"));
+ if (unlikely(!gc)) return -1;
+ py_status = __Pyx_PyObject_CallMethod0(gc, PYUNICODE("isenabled"));
if (unlikely(!py_status)) {
+ Py_DECREF(gc);
return -1;
}
gc_was_enabled = __Pyx_PyObject_IsTrue(py_status);
Py_DECREF(py_status);
if (gc_was_enabled > 0) {
- ret = __Pyx_PyObject_CallNoArg(gc_disable);
+ ret = __Pyx_PyObject_CallMethod0(gc, PYUNICODE("disable"));
if (unlikely(!ret)) {
+ Py_DECREF(gc);
return -1;
}
Py_DECREF(ret);
} else if (unlikely(gc_was_enabled == -1)) {
+ Py_DECREF(gc);
return -1;
}
@@ -219,6 +213,9 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
// Other than this check, the Py_TPFLAGS_HEAPTYPE flag is unused
// in PyType_Ready().
t->tp_flags |= Py_TPFLAGS_HEAPTYPE;
+#else
+ // avoid C warning about unused helper function
+ (void)__Pyx_PyObject_CallMethod0;
#endif
r = PyType_Ready(t);
@@ -229,7 +226,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
if (gc_was_enabled) {
PyObject *t, *v, *tb;
PyErr_Fetch(&t, &v, &tb);
- ret = __Pyx_PyObject_CallNoArg(gc_enable);
+ ret = __Pyx_PyObject_CallMethod0(gc, PYUNICODE("enable"));
if (likely(ret || r == -1)) {
Py_XDECREF(ret);
// do not overwrite exceptions raised by PyType_Ready() above
@@ -242,6 +239,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
r = -1;
}
}
+ Py_DECREF(gc);
}
#endif