summaryrefslogtreecommitdiff
path: root/py/objint_mpz.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-07-31 13:41:43 +0000
committerDamien George <damien.p.george@gmail.com>2014-07-31 13:41:43 +0000
commitc9aa58e6381018cca2513e3468363af0b5442d1f (patch)
tree47fa6e3a4971fe4053b08bb085710c325d11bfd0 /py/objint_mpz.c
parent94fbe9711a1179b3c4d0eb2e9822787d90231719 (diff)
py: Improve handling of long-int overflow.
This removes mpz_as_int, since that was a terrible function (it implemented saturating conversion). Use mpz_as_int_checked and mpz_as_uint_checked. These now work correctly (they previously had wrong overflow checking, eg print(chr(10000000000000)) on 32-bit machine would incorrectly convert this large number to a small int).
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r--py/objint_mpz.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index c60e5c2b8..8233773b8 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -225,8 +225,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case MP_BINARY_OP_INPLACE_LSHIFT:
case MP_BINARY_OP_RSHIFT:
case MP_BINARY_OP_INPLACE_RSHIFT: {
- // TODO check conversion overflow
- mp_int_t irhs = mpz_as_int(zrhs);
+ mp_int_t irhs = mp_obj_int_get_checked(rhs_in);
if (irhs < 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "negative shift count"));
}
@@ -303,7 +302,8 @@ mp_int_t mp_obj_int_get(mp_const_obj_t self_in) {
return MP_OBJ_SMALL_INT_VALUE(self_in);
} else {
const mp_obj_int_t *self = self_in;
- return mpz_as_int(&self->mpz);
+ // TODO this is a hack until we remove mp_obj_int_get function entirely
+ return mpz_hash(&self->mpz);
}
}