py: Support conversion of bignum to bytes.
This gets int.to_bytes working for bignum, and also struct.pack with 'q'
and 'Q' args on 32-bit machines.
Addresses issue #1155.
diff --git a/py/binary.c b/py/binary.c
index 927a426..8b5c05a 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -32,6 +32,7 @@
#include "py/binary.h"
#include "py/smallint.h"
+#include "py/objint.h"
// Helpers to work with binary-encoded data
@@ -282,10 +283,13 @@
}
#endif
default:
- // we handle large ints here by calling the truncated accessor
+ #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
if (MP_OBJ_IS_TYPE(val_in, &mp_type_int)) {
- val = mp_obj_int_get_truncated(val_in);
- } else {
+ mp_obj_int_to_bytes_impl(val_in, struct_type == '>', size, p);
+ return;
+ } else
+ #endif
+ {
val = mp_obj_get_int(val_in);
}
}