summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2021-04-16 00:05:29 +0200
committerStefan Behnel <stefan_ml@behnel.de>2021-04-16 00:05:29 +0200
commitcbda1b712d8883e262874b8e8916598153dcefe6 (patch)
tree43549ea0e0fafda569c9ffa829af8ecd7af17d68
parent8f99b3abf4dd963fb9dd80a3370913233ef1f35c (diff)
parent0f4a15d907bb095bc93f93afe6bd30f224c98989 (diff)
downloadcython-cbda1b712d8883e262874b8e8916598153dcefe6.tar.gz
Merge branch 'master' into clean_up_capi_features
-rw-r--r--Cython/Compiler/Annotate.py2
-rw-r--r--Cython/Compiler/Nodes.py14
-rw-r--r--Cython/Utility/ExtensionTypes.c29
-rw-r--r--tests/run/cdef_multiple_inheritance_cimport.srctree44
4 files changed, 72 insertions, 17 deletions
diff --git a/Cython/Compiler/Annotate.py b/Cython/Compiler/Annotate.py
index 67e4662a8..48e73f853 100644
--- a/Cython/Compiler/Annotate.py
+++ b/Cython/Compiler/Annotate.py
@@ -87,7 +87,7 @@ class AnnotationCCodeWriter(CCodeWriter):
body.cython { font-family: courier; font-size: 12; }
.cython.tag { }
- .cython.line { margin: 0em }
+ .cython.line { color: #000000; margin: 0em }
.cython.code { font-size: 9; color: #444444; display: none; margin: 0px 0px 0px 8px; border-left: 8px none; }
.cython.line .run { background-color: #B0FFB0; }
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py
index 2cddd065a..5fd378c96 100644
--- a/Cython/Compiler/Nodes.py
+++ b/Cython/Compiler/Nodes.py
@@ -5393,13 +5393,9 @@ class CClassDefNode(ClassDefNode):
code.putln("#endif")
code.putln("#if !CYTHON_USE_TYPE_SPECS")
- if check_heap_type_bases:
- code.globalstate.use_utility_code(
- UtilityCode.load_cached('PyType_Ready', 'ExtensionTypes.c'))
- readyfunc = "__Pyx_PyType_Ready"
- else:
- readyfunc = "PyType_Ready"
- code.put_error_if_neg(entry.pos, "%s(%s)" % (readyfunc, typeptr_cname))
+ code.globalstate.use_utility_code(
+ UtilityCode.load_cached('PyType_Ready', 'ExtensionTypes.c'))
+ code.put_error_if_neg(entry.pos, "__Pyx_PyType_Ready(%s)" % typeptr_cname)
code.putln("#endif")
# Don't inherit tp_print from builtin types in Python 2, restoring the
@@ -5463,6 +5459,7 @@ class CClassDefNode(ClassDefNode):
code.putln('#endif')
if preprocessor_guard:
code.putln('#endif')
+
if type.vtable_cname:
code.globalstate.use_utility_code(
UtilityCode.load_cached('SetVTable', 'ImportExport.c'))
@@ -5474,6 +5471,7 @@ class CClassDefNode(ClassDefNode):
code.globalstate.use_utility_code(
UtilityCode.load_cached('MergeVTables', 'ImportExport.c'))
code.put_error_if_neg(entry.pos, "__Pyx_MergeVtables(%s)" % typeptr_cname)
+
if not type.scope.is_internal and not type.scope.directives.get('internal'):
# scope.is_internal is set for types defined by
# Cython (such as closures), the 'internal'
@@ -5483,6 +5481,7 @@ class CClassDefNode(ClassDefNode):
code.intern_identifier(scope.class_name),
typeptr_cname,
))
+
weakref_entry = scope.lookup_here("__weakref__") if not scope.is_closure_class_scope else None
if weakref_entry:
if weakref_entry.type is py_object_type:
@@ -5498,6 +5497,7 @@ class CClassDefNode(ClassDefNode):
weakref_entry.cname))
else:
error(weakref_entry.pos, "__weakref__ slot must be of type 'object'")
+
if scope.lookup_here("__reduce_cython__") if not scope.is_closure_class_scope else None:
# Unfortunately, we cannot reliably detect whether a
# superclass defined __reduce__ at compile time, so we must
diff --git a/Cython/Utility/ExtensionTypes.c b/Cython/Utility/ExtensionTypes.c
index ac42e8225..e19df8578 100644
--- a/Cython/Utility/ExtensionTypes.c
+++ b/Cython/Utility/ExtensionTypes.c
@@ -156,6 +156,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t);
#endif
/////////////// PyType_Ready ///////////////
+//@requires: ObjectHandling.c::PyObjectCallNoArg
//@requires: ValidateBasesTuple
// Wrapper around PyType_Ready() with some runtime checks and fixes
@@ -172,24 +173,35 @@ 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;
- PyObject *gc = PyImport_Import(PYUNICODE("gc"));
- if (unlikely(!gc)) return -1;
- py_status = PyObject_CallMethodObjArgs(gc, PYUNICODE("isenabled"), NULL);
+ 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);
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 = PyObject_CallMethodObjArgs(gc, PYUNICODE("disable"), NULL);
+ ret = __Pyx_PyObject_CallNoArg(gc_disable);
if (unlikely(!ret)) {
- Py_DECREF(gc);
return -1;
}
Py_DECREF(ret);
} else if (unlikely(gc_was_enabled == -1)) {
- Py_DECREF(gc);
return -1;
}
@@ -211,7 +223,7 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
if (gc_was_enabled) {
PyObject *t, *v, *tb;
PyErr_Fetch(&t, &v, &tb);
- ret = PyObject_CallMethodObjArgs(gc, PYUNICODE("enable"), NULL);
+ ret = __Pyx_PyObject_CallNoArg(gc_enable);
if (likely(ret || r == -1)) {
Py_XDECREF(ret);
// do not overwrite exceptions raised by PyType_Ready() above
@@ -224,7 +236,6 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) {
r = -1;
}
}
- Py_DECREF(gc);
}
#endif
diff --git a/tests/run/cdef_multiple_inheritance_cimport.srctree b/tests/run/cdef_multiple_inheritance_cimport.srctree
new file mode 100644
index 000000000..dd56b3e30
--- /dev/null
+++ b/tests/run/cdef_multiple_inheritance_cimport.srctree
@@ -0,0 +1,44 @@
+# Test for https://github.com/cython/cython/issues/4106
+
+PYTHON setup.py build_ext --inplace
+PYTHON -c "import sub"
+
+######## setup.py ########
+
+from Cython.Build import cythonize
+from distutils.core import setup
+
+setup(
+ ext_modules = cythonize("*.pyx"),
+)
+
+######## base.pxd ########
+
+cdef class A:
+ cdef dict __dict__
+ cdef int a(self)
+
+cdef class B(A):
+ cdef int b(self)
+
+######## base.pyx ########
+
+cdef class A:
+ cdef int a(self):
+ return 1
+
+class PyA:
+ pass
+
+cdef class B(A, PyA):
+ cdef int b(self):
+ return 2
+
+######## sub.pyx ########
+
+from base cimport B
+print(B)
+
+cdef class C(B):
+ cdef int c(self):
+ return 3