Commit a442b59d authored by Stefan Behnel's avatar Stefan Behnel

Revert "Invoke binop super method via direct slot access."

This reverts commit bcb93877.
parent 5a8a513a
...@@ -1918,14 +1918,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1918,14 +1918,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
return bool(entry and entry.is_special and entry.func_cname) return bool(entry and entry.is_special and entry.func_cname)
def call_slot_method(method_name, reverse): def call_slot_method(method_name, reverse):
entry = scope.lookup(method_name) entry = scope.lookup(method_name)
if reverse:
operands = "right, left"
else:
operands = "left, right"
if entry and entry.is_special and entry.func_cname: if entry and entry.is_special and entry.func_cname:
return "%s(%s%s)" % (entry.func_cname, "right, left" if reverse else "left, right", extra_arg) return "%s(%s%s)" % (entry.func_cname, operands, extra_arg)
else: else:
super = 'Py_TYPE(right)->tp_base' if reverse else 'Py_TYPE(left)->tp_base' py_ident = code.intern_identifier(EncodedString(method_name))
return ('(%s->tp_as_number && %s->tp_as_number->%s)' return "%s_maybe_call_super(%s, %s)" % (func_name, operands, py_ident)
' ? %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( code.putln(
TempitaUtilityCode.load_cached( TempitaUtilityCode.load_cached(
"BinopSlot", "ExtensionTypes.c", "BinopSlot", "ExtensionTypes.c",
...@@ -1935,7 +1936,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1935,7 +1936,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"overloads_left": int(has_slot_method(slot.left_slot.method_name)), "overloads_left": int(has_slot_method(slot.left_slot.method_name)),
"call_left": call_slot_method(slot.left_slot.method_name, reverse=False), "call_left": call_slot_method(slot.left_slot.method_name, reverse=False),
"call_right": call_slot_method(slot.right_slot.method_name, reverse=True), "call_right": call_slot_method(slot.right_slot.method_name, reverse=True),
"type_cname": scope.parent_type.typeptr_cname, "type_cname": '((PyTypeObject*) %s)' % scope.namespace_cname,
"extra_arg": extra_arg, "extra_arg": extra_arg,
"extra_arg_decl": extra_arg_decl, "extra_arg_decl": extra_arg_decl,
}).impl.strip()) }).impl.strip())
......
...@@ -281,6 +281,30 @@ __PYX_GOOD: ...@@ -281,6 +281,30 @@ __PYX_GOOD:
/////////////// BinopSlot /////////////// /////////////// BinopSlot ///////////////
static CYTHON_INLINE PyObject *{{func_name}}_maybe_call_super(PyObject *self, PyObject *other, PyObject* name {{extra_arg_decl}}) {
PyObject *res;
PyObject *method;
if (!Py_TYPE(self)->tp_base) {
return Py_INCREF(Py_NotImplemented), Py_NotImplemented;
}
// TODO: Use _PyType_LookupId or similar.
method = PyObject_GetAttr((PyObject*) Py_TYPE(self)->tp_base, name);
if (!method) {
PyErr_Clear();
return Py_INCREF(Py_NotImplemented), Py_NotImplemented;
}
#if {{int(not extra_arg)}}
res = __Pyx_PyObject_Call2Args(method, self, other);
#else
res = PyObject_CallFunctionObjArgs(method, self, other {{extra_arg}}, NULL);
#endif
Py_DECREF(method);
if (!res) {
return Py_INCREF(Py_NotImplemented), Py_NotImplemented;
}
return res;
}
static PyObject *{{func_name}}(PyObject *left, PyObject *right {{extra_arg_decl}}) { static PyObject *{{func_name}}(PyObject *left, PyObject *right {{extra_arg_decl}}) {
PyObject *res; PyObject *res;
int maybe_self_is_left, maybe_self_is_right = 0; int maybe_self_is_left, maybe_self_is_right = 0;
......
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