Let it run on builds without long ints
This commit is contained in:
parent
5f6ae74dad
commit
c6ccecde89
@ -196,11 +196,13 @@ STATIC mp_map_elem_t *dict_iter_next(mp_obj_dict_t *dict, size_t *cur) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void pack_int(msgpack_stream_t *s, mp_obj_t obj, bool _signed) {
|
STATIC void pack_int(msgpack_stream_t *s, mp_obj_t obj) {
|
||||||
byte buffer[9];
|
byte buffer[9];
|
||||||
byte *buf = (buffer + 1);
|
byte *buf = (buffer + 1);
|
||||||
byte *type = buffer;
|
byte *type = buffer;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
// encode signed or unsigned
|
||||||
|
bool _signed = mp_obj_int_sign(obj) < 0;
|
||||||
if (mp_obj_is_small_int(obj)) {
|
if (mp_obj_is_small_int(obj)) {
|
||||||
int32_t x = MP_OBJ_SMALL_INT_VALUE(obj);
|
int32_t x = MP_OBJ_SMALL_INT_VALUE(obj);
|
||||||
if (x > -32 && x < 128) {
|
if (x > -32 && x < 128) {
|
||||||
@ -218,10 +220,17 @@ STATIC void pack_int(msgpack_stream_t *s, mp_obj_t obj, bool _signed) {
|
|||||||
}
|
}
|
||||||
mp_binary_set_int(len, true, buf, x);
|
mp_binary_set_int(len, true, buf, x);
|
||||||
} else {
|
} else {
|
||||||
|
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
|
||||||
|
// raise if long int overflows
|
||||||
|
mp_obj_int_buffer_overflow_check(obj, 8, _signed);
|
||||||
// todo: encode remaining 32 bit values as 0xd2/0xce ?
|
// todo: encode remaining 32 bit values as 0xd2/0xce ?
|
||||||
*type = _signed ? 0xd3 : 0xcf;
|
*type = _signed ? 0xd3 : 0xcf;
|
||||||
len = 8;
|
len = 8;
|
||||||
mp_obj_int_to_bytes_impl(obj, true, len, buf);
|
mp_obj_int_to_bytes_impl(obj, true, len, buf);
|
||||||
|
#else
|
||||||
|
// never reached because you can't have mp_obj_is_small_int false
|
||||||
|
// if there is no LONGINT implemented !
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
write(s, buffer, len + 1);
|
write(s, buffer, len + 1);
|
||||||
}
|
}
|
||||||
@ -292,12 +301,8 @@ STATIC void pack_dict(msgpack_stream_t *s, size_t len) {
|
|||||||
|
|
||||||
STATIC void pack(mp_obj_t obj, msgpack_stream_t *s, mp_obj_t default_handler) {
|
STATIC void pack(mp_obj_t obj, msgpack_stream_t *s, mp_obj_t default_handler) {
|
||||||
if (mp_obj_is_int(obj)) {
|
if (mp_obj_is_int(obj)) {
|
||||||
// big int
|
// all ints
|
||||||
// encode signed or unsigned
|
pack_int(s, obj);
|
||||||
bool _signed = mp_obj_int_sign(obj) < 0;
|
|
||||||
// raise if overflow
|
|
||||||
mp_obj_int_buffer_overflow_check(obj, 8, _signed);
|
|
||||||
pack_int(s, obj, _signed);
|
|
||||||
} else if (mp_obj_is_str(obj)) {
|
} else if (mp_obj_is_str(obj)) {
|
||||||
// string
|
// string
|
||||||
size_t len;
|
size_t len;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user