summaryrefslogtreecommitdiff
path: root/py/objint_longlong.c
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2025-07-15 11:23:28 +1000
committerDamien George <damien@micropython.org>2025-07-18 00:12:16 +1000
commit17fbc5abdc7e139a922f6a11619deb7cb031e0cb (patch)
treea280d07a0c2e781e9605a863c33a723d941b08b9 /py/objint_longlong.c
parente9845ab20ec798c1d5bf00bd3b64ff5d96d94500 (diff)
py/parsenum: Extend mp_parse_num_integer() to parse long long.
If big integer support is 'long long' then mp_parse_num_integer() can parse to it directly instead of failing over from small int. This means strtoll() is no longer pulled in, and fixes some bugs parsing long long integers (i.e. can now parse negative values correctly, can now parse values which aren't NULL terminated). The (default) smallint parsing compiled code should stay the same here, macros and a typedef are used to abstract some parts of it out. When bigint is long long we parse to 'unsigned long long' first (to avoid the code size hit of pulling in signed 64-bit math routines) and the convert to signed at the end. One tricky case this routine correctly overflows on is int("9223372036854775808") which is one more than LLONG_MAX in decimal. No unit test case added for this as it's too hard to detect 64-bit long integer mode. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'py/objint_longlong.c')
-rw-r--r--py/objint_longlong.c10
1 files changed, 0 insertions, 10 deletions
diff --git a/py/objint_longlong.c b/py/objint_longlong.c
index db0950321..22ac0ba12 100644
--- a/py/objint_longlong.c
+++ b/py/objint_longlong.c
@@ -292,22 +292,12 @@ mp_obj_t mp_obj_new_int_from_ll(long long val) {
}
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
- // TODO raise an exception if the unsigned long long won't fit
if (val >> (sizeof(unsigned long long) * 8 - 1) != 0) {
raise_long_long_overflow();
}
return mp_obj_new_int_from_ll(val);
}
-mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int 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
- char *endptr;
- mp_obj_t result = mp_obj_new_int_from_ll(strtoll(*str, &endptr, base));
- *str = endptr;
- return result;
-}
-
mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in) {
if (mp_obj_is_small_int(self_in)) {
return MP_OBJ_SMALL_INT_VALUE(self_in);