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.
This commit is contained in:
10
py/binary.c
10
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user