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

genexit-inst
Damien George 2014-03-19 23:15:25 +00:00
parent 494600bc99
commit cd8b2baf43
1 changed files with 12 additions and 1 deletions

View File

@ -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;