diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-03-06 12:15:25 +0100 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-03-06 12:15:25 +0100 |
commit | 96aa3a31023d9b170c4e3d0ef5090a2f21f0b64b (patch) | |
tree | 06c73d3e12ffd23a32932d2a16417b81dbda9c00 /py | |
parent | 914648ce0e353b5af59dbd3412bb4aa438864010 (diff) | |
download | micropython-96aa3a31023d9b170c4e3d0ef5090a2f21f0b64b.tar.gz micropython-96aa3a31023d9b170c4e3d0ef5090a2f21f0b64b.zip |
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.
Diffstat (limited to 'py')
-rw-r--r-- | py/modsys.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/py/modsys.c b/py/modsys.c index 8c368ac35b..b208c88bd6 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -32,6 +32,7 @@ #include "py/objstr.h" #include "py/objint.h" #include "py/stream.h" +#include "py/smallint.h" #if MICROPY_PY_SYS @@ -162,12 +163,12 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { #if MICROPY_PY_SYS_MAXSIZE #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE - // INT_MAX is not representable as small int, as we know that small int - // takes one bit for tag. So, we have little choice but to provide this - // value. Apps also should be careful to not try to compare sys.maxsize - // with some number (which may not fit in available int size), but instead - // count number of significant bits in sys.maxsize. - { MP_ROM_QSTR(MP_QSTR_maxsize), MP_OBJ_NEW_SMALL_INT(INT_MAX >> 1) }, + // Maximum mp_int_t value is not representable as small int, so we have + // little choice but to use MP_SMALL_INT_MAX. Apps also should be careful + // to not try to compare sys.maxsize to some literal number (as this + // number might not fit in available int size), but instead count number + // of "one" bits in sys.maxsize. + { MP_ROM_QSTR(MP_QSTR_maxsize), MP_OBJ_NEW_SMALL_INT(MP_SMALL_INT_MAX) }, #else { MP_ROM_QSTR(MP_QSTR_maxsize), MP_ROM_PTR(&mp_maxsize_obj) }, #endif |