Skip to content

Commit 79da2d6

Browse files
committed
be more conservative for now with reverse methods
1 parent df06a05 commit 79da2d6

File tree

1 file changed

+5
-6
lines changed
  • graalpython/com.oracle.graal.python.cext/src

1 file changed

+5
-6
lines changed

graalpython/com.oracle.graal.python.cext/src/object.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ static Py_hash_t wrap_hashfunc(hashfunc f, PyObject* a) {
255255
return PyLong_FromSsize_t(f(a));
256256
}
257257

258+
static PyObject* wrap_reverse_binop(binaryfunc f, PyObject* a, PyObject* b) {
259+
return f(b, a);
260+
}
258261

259262
int PyType_Ready(PyTypeObject* cls) {
260263
#define ADD_IF_MISSING(attr, def) if (!(attr)) { attr = def; }
@@ -433,11 +436,10 @@ int PyType_Ready(PyTypeObject* cls) {
433436
PyNumberMethods* numbers = cls->tp_as_number;
434437
if (numbers) {
435438
ADD_SLOT("__add__", numbers->nb_add, -2);
436-
ADD_SLOT("__radd__", numbers->nb_add, -2);
439+
ADD_SLOT_CONV("__radd__", wrap_reverse_binop, numbers->nb_add, -2);
437440
ADD_SLOT("__sub__", numbers->nb_subtract, -2);
438-
ADD_SLOT("__rsub__", numbers->nb_subtract, -2);
441+
ADD_SLOT_CONV("__rsub__", wrap_reverse_binop, numbers->nb_subtract, -2);
439442
ADD_SLOT("__mul__", numbers->nb_multiply, -2);
440-
ADD_SLOT("__rmul__", numbers->nb_multiply, -2);
441443
ADD_SLOT("__rem__", numbers->nb_remainder, -2);
442444
ADD_SLOT("__divmod__", numbers->nb_divmod, -2);
443445
ADD_SLOT_CONV("__pow__", wrap_pow, numbers->nb_power, -3);
@@ -449,11 +451,8 @@ int PyType_Ready(PyTypeObject* cls) {
449451
ADD_SLOT("__lshift__", numbers->nb_lshift, -2);
450452
ADD_SLOT("__rshift__", numbers->nb_rshift, -2);
451453
ADD_SLOT("__and__", numbers->nb_and, -2);
452-
ADD_SLOT("__rand__", numbers->nb_and, -2);
453454
ADD_SLOT("__xor__", numbers->nb_xor, -2);
454-
ADD_SLOT("__rxor__", numbers->nb_xor, -2);
455455
ADD_SLOT("__or__", numbers->nb_or, -2);
456-
ADD_SLOT("__ror__", numbers->nb_or, -2);
457456
ADD_SLOT("__int__", numbers->nb_int, -1);
458457
ADD_SLOT("__float__", numbers->nb_float, -1);
459458
ADD_SLOT("__iadd__", numbers->nb_inplace_add, -2);

0 commit comments

Comments
 (0)