summaryrefslogtreecommitdiff
path: root/py/binary.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-04-25 23:16:39 +0100
committerDamien George <damien.p.george@gmail.com>2015-04-25 23:16:39 +0100
commit271d18eb08ec488ee45f8e6cd852e8236074f082 (patch)
treef5ba5d1b28cb48e72334fb079a5d6ef148083970 /py/binary.c
parent7c8b4c1a8b8278d864649c127857e34a6bd29504 (diff)
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.
Diffstat (limited to 'py/binary.c')
-rw-r--r--py/binary.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/py/binary.c b/py/binary.c
index 927a42640..8b5c05ab3 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 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
}
#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);
}
}