diff options
author | Damien George <damien.p.george@gmail.com> | 2014-05-28 14:07:21 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-05-28 14:07:21 +0100 |
commit | 503d6110338ab2d79e6c0f8f591a0ca6397717de (patch) | |
tree | bb57f7338aa07d248fb17cc6260d1f36c8bb8b86 /py/objint_mpz.c | |
parent | 1d567592b18ea9796515436754877aac3948bd29 (diff) | |
download | micropython-503d6110338ab2d79e6c0f8f591a0ca6397717de.tar.gz micropython-503d6110338ab2d79e6c0f8f591a0ca6397717de.zip |
py: Implement long int parsing in int(...).
Addresses issue #627.
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r-- | py/objint_mpz.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 2df3232e9c..733dc096a6 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -260,26 +260,18 @@ mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) { return mp_obj_new_int_from_ll(value); } -mp_obj_t mp_obj_new_int_from_qstr(qstr qst) { +mp_obj_t mp_obj_new_int_from_str_len(const char **str, uint len, bool neg, uint base) { mp_obj_int_t *o = mp_obj_int_new_mpz(); - uint len; - const char* str = (const char*)qstr_data(qst, &len); - int base = 0; - int skip = mp_parse_num_base(str, len, &base); - str += skip; - len -= skip; - uint n = mpz_set_from_str(&o->mpz, str, len, false, base); - if (n != len) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_SyntaxError, "invalid syntax for number")); - } + uint n = mpz_set_from_str(&o->mpz, *str, len, neg, base); + *str += n; return o; } -machine_int_t mp_obj_int_get(mp_obj_t self_in) { +machine_int_t mp_obj_int_get(mp_const_obj_t self_in) { if (MP_OBJ_IS_SMALL_INT(self_in)) { return MP_OBJ_SMALL_INT_VALUE(self_in); } else { - mp_obj_int_t *self = self_in; + const mp_obj_int_t *self = self_in; return mpz_as_int(&self->mpz); } } |