Skip to content

Commit 776883c

Browse files
committed
py/objint_longlong: Implement mp_obj_int_from_bytes_impl().
This makes int.from_bytes() work for MICROPY_LONGINT_IMPL_LONGLONG.
1 parent bc5bffb commit 776883c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

py/objint_longlong.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ const mp_obj_int_t mp_maxsize_obj = {{&mp_type_int}, MP_SSIZE_MAX};
5454
#endif
5555

5656
mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf) {
57-
mp_not_implemented("");
57+
int delta = 1;
58+
if (!big_endian) {
59+
buf += len - 1;
60+
delta = -1;
61+
}
62+
63+
mp_longint_impl_t value = 0;
64+
for (; len--; buf += delta) {
65+
value = (value << 8) | *buf;
66+
}
67+
return mp_obj_new_int_from_ll(value);
5868
}
5969

6070
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf) {

0 commit comments

Comments
 (0)