diff options
Diffstat (limited to 'py/objint_longlong.c')
-rw-r--r-- | py/objint_longlong.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/py/objint_longlong.c b/py/objint_longlong.c index 1e0167b464..82db9e6608 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -34,6 +34,7 @@ #include "misc.h" #include "qstr.h" #include "obj.h" +#include "smallint.h" #include "mpz.h" #include "objint.h" #include "runtime0.h" @@ -140,7 +141,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } mp_obj_t mp_obj_new_int(machine_int_t value) { - if (MP_OBJ_FITS_SMALL_INT(value)) { + if (MP_SMALL_INT_FITS(value)) { return MP_OBJ_NEW_SMALL_INT(value); } return mp_obj_new_int_from_ll(value); @@ -162,26 +163,22 @@ mp_obj_t mp_obj_new_int_from_ll(long long val) { return o; } -mp_obj_t mp_obj_new_int_from_qstr(qstr qst) { - const char *s = qstr_str(qst); - long long v; - char *end; - // TODO: this doesn't handle Python hacked 0o octal syntax - v = strtoll(s, &end, 0); - if (*end != 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_SyntaxError, "invalid syntax for number")); - } +mp_obj_t mp_obj_new_int_from_str_len(const char **str, uint len, bool neg, uint base) { + // TODO this does not honor the given length of the string, but it all cases it should anyway be null terminated + // TODO check overflow mp_obj_int_t *o = m_new_obj(mp_obj_int_t); o->base.type = &mp_type_int; - o->val = v; + char *endptr; + o->val = strtoll(*str, &endptr, base); + *str = endptr; 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 self->val; } } |