8000 mp_obj_equal(): Compare small and long ints properly. · ronc/micropython@ca318bb · GitHub
[go: up one dir, main page]

Skip to content

Commit ca318bb

Browse files
committed
mp_obj_equal(): Compare small and long ints properly.
By dispatching to long int methods.
1 parent 76a90f2 commit ca318bb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

py/obj.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,15 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
108108
return val == 0;
109109
} else if (o2 == mp_const_true) {
110110
return val == 1;
111-
} else {
112-
return false;
111+
} else if (MP_OBJ_IS_TYPE(o2, &int_type)) {
112+
// If o2 is long int, dispatch to its virtual methods
113+
mp_obj_base_t *o = o2;
114+
if (o->type->binary_op != NULL) {
115+
mp_obj_t r = o->type->binary_op(RT_COMPARE_OP_EQUAL, o2, o1);
116+
return r == mp_const_true ? true : false;
117+
}
113118
}
119+
return false;
114120
}
115121
} else if (MP_OBJ_IS_QSTR(o1) || MP_OBJ_IS_QSTR(o2)) {
116122
return false;

0 commit comments

Comments
 (0)
0