diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-12 15:38:15 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-12 15:38:15 +0000 |
commit | 9d68e9ccdd4d7f4ecb7a8765ca694e355753d686 (patch) | |
tree | 73926072f5555829e31dfb1a1b72abe259bacd03 /py/obj.h | |
parent | bb4a43f35ccb128aeb42e483d9937764353de49e (diff) | |
download | micropython-9d68e9ccdd4d7f4ecb7a8765ca694e355753d686.tar.gz micropython-9d68e9ccdd4d7f4ecb7a8765ca694e355753d686.zip |
py: Implement integer overflow checking for * and << ops.
If operation will overflow, a multi-precision integer is created.
Diffstat (limited to 'py/obj.h')
-rw-r--r-- | py/obj.h | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -29,6 +29,8 @@ typedef struct _mp_obj_base_t mp_obj_base_t; // - xxxx...xx00: a pointer to an mp_obj_base_t // In SMALL_INT, next-to-highest bits is used as sign, so both must match for value in range +#define MP_SMALL_INT_MIN ((mp_small_int_t)(((machine_int_t)WORD_MSBIT_HIGH) >> 1)) +#define MP_SMALL_INT_MAX ((mp_small_int_t)(~(MP_SMALL_INT_MIN))) #define MP_OBJ_FITS_SMALL_INT(n) ((((n) ^ ((n) << 1)) & WORD_MSBIT_HIGH) == 0) #define MP_OBJ_IS_SMALL_INT(o) ((((mp_small_int_t)(o)) & 1) != 0) #define MP_OBJ_IS_QSTR(o) ((((mp_small_int_t)(o)) & 3) == 2) @@ -218,9 +220,7 @@ mp_obj_t mp_obj_new_cell(mp_obj_t obj); mp_obj_t mp_obj_new_int(machine_int_t value); mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value); mp_obj_t mp_obj_new_int_from_long_str(const char *s); -#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE -mp_obj_t mp_obj_new_int_from_ll(long long val); -#endif +mp_obj_t mp_obj_new_int_from_ll(long long val); // this must return a multi-precision integer object (or raise an overflow exception) mp_obj_t mp_obj_new_str(const byte* data, uint len, bool make_qstr_if_not_already); mp_obj_t mp_obj_new_bytes(const byte* data, uint len); #if MICROPY_ENABLE_FLOAT |