diff options
author | Damien George <damien.p.george@gmail.com> | 2015-04-25 23:16:39 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-04-25 23:16:39 +0100 |
commit | 271d18eb08ec488ee45f8e6cd852e8236074f082 (patch) | |
tree | f5ba5d1b28cb48e72334fb079a5d6ef148083970 /py/objint_mpz.c | |
parent | 7c8b4c1a8b8278d864649c127857e34a6bd29504 (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/objint_mpz.c')
-rw-r--r-- | py/objint_mpz.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 2746f4dff..369e5af32 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -104,6 +104,12 @@ mp_int_t mp_obj_int_hash(mp_obj_t self_in) { return mpz_hash(&self->mpz); } +void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, mp_uint_t len, byte *buf) { + assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int)); + mp_obj_int_t *self = self_in; + mpz_as_bytes(&self->mpz, big_endian, len, buf); +} + bool mp_obj_int_is_positive(mp_obj_t self_in) { if (MP_OBJ_IS_SMALL_INT(self_in)) { return MP_OBJ_SMALL_INT_VALUE(self_in) >= 0; |