diff options
author | Damien George <damien.p.george@gmail.com> | 2015-09-01 16:25:29 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-09-01 16:31:48 +0100 |
commit | 81794fcd31e604fb74bef89d749ee839b7dfc58f (patch) | |
tree | e068b70223daa7c9eca54b0a3aad4c7112654591 /py | |
parent | 22602cc37bc2454568cc9e8834a8ba444c85be05 (diff) | |
download | micropython-81794fcd31e604fb74bef89d749ee839b7dfc58f.tar.gz micropython-81794fcd31e604fb74bef89d749ee839b7dfc58f.zip |
py/binary: Add support for array('q') and array('Q').
Diffstat (limited to 'py')
-rw-r--r-- | py/binary.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/py/binary.c b/py/binary.c index 9205018b5f..d8f865ebe5 100644 --- a/py/binary.c +++ b/py/binary.c @@ -130,12 +130,12 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) { return mp_obj_new_int(((long*)p)[index]); case 'L': return mp_obj_new_int_from_uint(((unsigned long*)p)[index]); -#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE + #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE case 'q': - case 'Q': - // TODO: Explode API more to cover signedness return mp_obj_new_int_from_ll(((long long*)p)[index]); -#endif + case 'Q': + return mp_obj_new_int_from_ull(((unsigned long long*)p)[index]); + #endif #if MICROPY_PY_BUILTINS_FLOAT case 'f': return mp_obj_new_float(((float*)p)[index]); @@ -316,6 +316,13 @@ void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t v ((mp_obj_t*)p)[index] = val_in; break; default: + #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE + if ((typecode | 0x20) == 'q' && MP_OBJ_IS_TYPE(val_in, &mp_type_int)) { + mp_obj_int_to_bytes_impl(val_in, MP_ENDIANNESS_BIG, + sizeof(long long), (byte*)&((long long*)p)[index]); + return; + } + #endif mp_binary_set_val_array_from_int(typecode, p, index, mp_obj_get_int(val_in)); } } @@ -347,13 +354,13 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m case 'L': ((unsigned long*)p)[index] = val; break; -#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE + #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE case 'q': - case 'Q': - assert(0); ((long long*)p)[index] = val; + case 'Q': + ((unsigned long long*)p)[index] = val; break; -#endif + #endif #if MICROPY_PY_BUILTINS_FLOAT case 'f': ((float*)p)[index] = val; |