Skip to content

Commit 96aa3a3

Browse files
committed
py/modsys: Use MP_SMALL_INT_MAX for sys.maxsize in case of LONGINT_IMPL_NONE.
INT_MAX used previosly is indeed max value for int, whereas on LP64 platforms, long is used for mp_int_t. Using MP_SMALL_INT_MAX is the correct way to do it anyway.
1 parent 914648c commit 96aa3a3

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

py/modsys.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "py/objstr.h"
3333
#include "py/objint.h"
3434
#include "py/stream.h"
35+
#include "py/smallint.h"
3536

3637
#if MICROPY_PY_SYS
3738

@@ -162,12 +163,12 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
162163

163164
#if MICROPY_PY_SYS_MAXSIZE
164165
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
165-
// INT_MAX is not representable as small int, as we know that small int
166-
// takes one bit for tag. So, we have little choice but to provide this
167-
// value. Apps also should be careful to not try to compare sys.maxsize
168-
// with some number (which may not fit in available int size), but instead
169-
// count number of significant bits in sys.maxsize.
170-
{ MP_ROM_QSTR(MP_QSTR_maxsize), MP_OBJ_NEW_SMALL_INT(INT_MAX >> 1) },
166+
// Maximum mp_int_t value is not representable as small int, so we have
167+
// little choice but to use MP_SMALL_INT_MAX. Apps also should be careful
168+
// to not try to compare sys.maxsize to some literal number (as this
169+
// number might not fit in available int size), but instead count number
170+
// of "one" bits in sys.maxsize.
171+
{ MP_ROM_QSTR(MP_QSTR_maxsize), MP_OBJ_NEW_SMALL_INT(MP_SMALL_INT_MAX) },
171172
#else
172173
{ MP_ROM_QSTR(MP_QSTR_maxsize), MP_ROM_PTR(&mp_maxsize_obj) },
173174
#endif

0 commit comments

Comments
 (0)