Commit cd8b2baf authored by Damien George's avatar Damien George
Browse files

py: Fix bug in mpz int, where small int is on lhs, mpz on rhs.

parent 494600bc
......@@ -44,11 +44,22 @@ mp_obj_t int_unary_op(int op, mp_obj_t o_in) {
}
mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mpz_t *zlhs = &((mp_obj_int_t*)lhs_in)->mpz;
const mpz_t *zlhs;
const mpz_t *zrhs;
mpz_t z_int;
mpz_dig_t z_int_dig[MPZ_NUM_DIG_FOR_INT];
// lhs could be a small int (eg small-int + mpz)
if (MP_OBJ_IS_SMALL_INT(lhs_in)) {
mpz_init_fixed_from_int(&z_int, z_int_dig, MPZ_NUM_DIG_FOR_INT, MP_OBJ_SMALL_INT_VALUE(lhs_in));
zlhs = &z_int;
} else if (MP_OBJ_IS_TYPE(lhs_in, &int_type)) {
zlhs = &((mp_obj_int_t*)lhs_in)->mpz;
} else {
return MP_OBJ_NULL;
}
// if rhs is small int, then lhs was not (otherwise rt_binary_op handles it)
if (MP_OBJ_IS_SMALL_INT(rhs_in)) {
mpz_init_fixed_from_int(&z_int, z_int_dig, MPZ_NUM_DIG_FOR_INT, MP_OBJ_SMALL_INT_VALUE(rhs_in));
zrhs = &z_int;
......
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