summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@gmail.com>2020-05-25 09:57:08 -0700
committerGitHub <noreply@github.com>2020-05-25 09:57:08 -0700
commiteb33d89b4604a0e87b9e4c9322cc84f7bd34014d (patch)
tree2d8ffb9713a74cf98224c3060889b0ebf48c71e2
parent9edeabfdc537c1290bc00a2c1c6eb474b1dc18b4 (diff)
downloadcython-gh2056_special_binop.tar.gz
Apply suggestions from code review gh2056_special_binop
Use special __Pyx methods. Co-authored-by: scoder <stefan_ml@behnel.de>
-rw-r--r--Cython/Compiler/ModuleNode.py2
-rw-r--r--Cython/Utility/ExtensionTypes.c6
2 files changed, 5 insertions, 3 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 568088ef7..c7829f85e 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -2049,6 +2049,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
extra_arg_decl = ', PyObject* extra_arg'
else:
error(entry.pos, "Unexpected type lost signature: %s" % slot)
+
def has_slot_method(method_name):
entry = scope.lookup(method_name)
return bool(entry and entry.is_special and entry.func_cname)
@@ -2062,6 +2063,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
' ? %s->tp_as_number->%s(left, right %s)'
' : (Py_INCREF(Py_NotImplemented), Py_NotImplemented)') % (
super, super, slot.slot_name, super, slot.slot_name, extra_arg)
+
code.putln(
TempitaUtilityCode.load_cached(
"BinopSlot", "ExtensionTypes.c",
diff --git a/Cython/Utility/ExtensionTypes.c b/Cython/Utility/ExtensionTypes.c
index 215d16ec2..e27d468a1 100644
--- a/Cython/Utility/ExtensionTypes.c
+++ b/Cython/Utility/ExtensionTypes.c
@@ -334,12 +334,12 @@ static PyObject *{{func_name}}(PyObject *left, PyObject *right {{extra_arg_decl}
int maybe_self_is_left, maybe_self_is_right = 0;
maybe_self_is_left = Py_TYPE(left) == Py_TYPE(right)
|| (Py_TYPE(left)->tp_as_number && Py_TYPE(left)->tp_as_number->{{slot_name}} == &{{func_name}})
- || PyType_IsSubtype(Py_TYPE(left), {{type_cname}});
+ || __Pyx_TypeCheck(left, {{type_cname}});
// Optimize for the common case where the left operation is defined (and successful).
if (!{{overloads_left}}) {
maybe_self_is_right = Py_TYPE(left) == Py_TYPE(right)
|| (Py_TYPE(right)->tp_as_number && Py_TYPE(right)->tp_as_number->{{slot_name}} == &{{func_name}})
- || PyType_IsSubtype(Py_TYPE(right), {{type_cname}});
+ || __Pyx_TypeCheck(right, {{type_cname}});
}
if (maybe_self_is_left) {
if (maybe_self_is_right && !{{overloads_left}}) {
@@ -360,5 +360,5 @@ static PyObject *{{func_name}}(PyObject *left, PyObject *right {{extra_arg_decl}
if (maybe_self_is_right) {
return {{call_right}};
}
- return Py_INCREF(Py_NotImplemented), Py_NotImplemented;
+ return __Pyx_NewRef(Py_NotImplemented);
}