diff options
author | Damien George <damien.p.george@gmail.com> | 2014-12-05 23:13:52 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-12-05 23:13:52 +0000 |
commit | be6d8be91e133e98117025062df0e63aaf87efd2 (patch) | |
tree | 692495154f547612c148312b4abc0afc3f4a50d6 /extmod | |
parent | 451a0870753be89f5a284fd39727705a3ad2109b (diff) | |
download | micropython-be6d8be91e133e98117025062df0e63aaf87efd2.tar.gz micropython-be6d8be91e133e98117025062df0e63aaf87efd2.zip |
py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.
mp_obj_int_get_truncated is used as a "fast path" int accessor that
doesn't check for overflow and returns the int truncated to the machine
word size, ie mp_int_t.
Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word
sized values.
Addresses issues #779 and #998.
Diffstat (limited to 'extmod')
-rw-r--r-- | extmod/moductypes.c | 4 | ||||
-rw-r--r-- | extmod/modure.c | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 83cfbbcc57..b8f68bf8c1 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -571,7 +571,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof /// captured by reference (and thus memory pointed by bytearray may change /// or become invalid at later time). Use bytes_at() to capture by value. mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) { - return mp_obj_new_bytearray_by_ref(mp_obj_int_get(size), (void*)mp_obj_int_get(ptr)); + return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)mp_obj_int_get_truncated(ptr)); } MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at); @@ -580,7 +580,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytear /// captured by value, i.e. copied. Use bytearray_at() to capture by reference /// ("zero copy"). mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) { - return mp_obj_new_bytes((void*)mp_obj_int_get(ptr), mp_obj_int_get(size)); + return mp_obj_new_bytes((void*)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size)); } MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at); diff --git a/extmod/modure.c b/extmod/modure.c index eb010faf90..910166249c 100644 --- a/extmod/modure.c +++ b/extmod/modure.c @@ -62,7 +62,7 @@ STATIC void match_print(void (*print)(void *env, const char *fmt, ...), void *en STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) { mp_obj_match_t *self = self_in; - mp_int_t no = mp_obj_int_get(no_in); + mp_int_t no = mp_obj_int_get_truncated(no_in); if (no < 0 || no >= self->num_matches / 2) { nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, no_in)); } @@ -130,7 +130,7 @@ STATIC mp_obj_t re_split(uint n_args, const mp_obj_t *args) { int maxsplit = 0; if (n_args > 2) { - maxsplit = mp_obj_int_get(args[2]); + maxsplit = mp_obj_int_get_truncated(args[2]); } mp_obj_t retval = mp_obj_new_list(0, NULL); |