Commit bcb93877 authored by Robert Bradshaw's avatar Robert Bradshaw

Invoke binop super method via direct slot access.

parent d849fb23
......@@ -1916,15 +1916,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
return bool(entry and entry.is_special and entry.func_cname)
def call_slot_method(method_name, reverse):
entry = scope.lookup(method_name)
if reverse:
operands = "right, left"
else:
operands = "left, right"
if entry and entry.is_special and entry.func_cname:
return "%s(%s%s)" % (entry.func_cname, operands, extra_arg)
return "%s(%s%s)" % (entry.func_cname, "right, left" if reverse else "left, right", extra_arg)
else:
py_ident = code.intern_identifier(EncodedString(method_name))
return "%s_maybe_call_super(%s, %s)" % (func_name, operands, py_ident)
super = 'Py_TYPE(right)->tp_base' if reverse else 'Py_TYPE(left)->tp_base'
return ('(%s->tp_as_number && %s->tp_as_number->%s)'
' ? %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",
......@@ -1934,7 +1933,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"overloads_left": int(has_slot_method(slot.left_slot.method_name)),
"call_left": call_slot_method(slot.left_slot.method_name, reverse=False),
"call_right": call_slot_method(slot.right_slot.method_name, reverse=True),
"type_cname": '((PyTypeObject*) %s)' % scope.namespace_cname,
"type_cname": scope.parent_type.typeptr_cname,
"extra_arg": extra_arg,
"extra_arg_decl": extra_arg_decl,
}).impl.strip())
......
......@@ -281,30 +281,6 @@ __PYX_GOOD:
/////////////// 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}}) {
PyObject *res;
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