mp_obj_equal(): Compare small and long ints properly.

By dispatching to long int methods.
This commit is contained in:
Paul Sokolovsky 2014-01-13 16:29:14 +02:00
parent 76a90f2f60
commit ca318bba0d
1 changed files with 8 additions and 2 deletions

View File

@ -108,9 +108,15 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
return val == 0;
} else if (o2 == mp_const_true) {
return val == 1;
} else {
return false;
} else if (MP_OBJ_IS_TYPE(o2, &int_type)) {
// If o2 is long int, dispatch to its virtual methods
mp_obj_base_t *o = o2;
if (o->type->binary_op != NULL) {
mp_obj_t r = o->type->binary_op(RT_COMPARE_OP_EQUAL, o2, o1);
return r == mp_const_true ? true : false;
}
}
return false;
}
} else if (MP_OBJ_IS_QSTR(o1) || MP_OBJ_IS_QSTR(o2)) {
return false;