diff options
author | Damien George <damien.p.george@gmail.com> | 2016-03-19 21:41:01 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-03-19 21:41:01 +0000 |
commit | 12154b1774c0a05ce97af13307d106a76169ecc7 (patch) | |
tree | fa14b3c13515142e361fc0d10f03c0eb1449206e | |
parent | 8d4d6731f56f9b1163f19d2455e8998aa0499afd (diff) |
extmod/uctypes: Use mp_binary_get_val helper when extracting value.
It handles more cases than mp_binary_get_int.
-rw-r--r-- | extmod/moductypes.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 9b078387b..ad16284d9 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -282,12 +282,9 @@ STATIC mp_obj_t uctypes_struct_sizeof(mp_obj_t obj_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_sizeof_obj, uctypes_struct_sizeof); STATIC inline mp_obj_t get_unaligned(uint val_type, void *p, int big_endian) { - mp_int_t val = mp_binary_get_int(GET_SCALAR_SIZE(val_type), val_type & 1, big_endian, p); - if (val_type == UINT32) { - return mp_obj_new_int_from_uint(val); - } else { - return mp_obj_new_int(val); - } + char struct_type = big_endian ? '>' : '<'; + static const char type2char[8] = "BbHhIiQq"; + return mp_binary_get_val(struct_type, type2char[val_type], (byte**)&p); } STATIC inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_t val) { |