aboutsummaryrefslogtreecommitdiff
path: root/py/objint_mpz.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-01-21 20:14:18 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-01-21 20:14:18 +0300
commitbec7bfb29d76f995dbf223c20f5d04ae1e33cee6 (patch)
treef44914a3ee66ef924f15f477f0fc87ade4a06c5d /py/objint_mpz.c
parent1b42f5251fb126496584e2fc61fad12bca7f7152 (diff)
py/objint: from_bytes(): Implement "byteorder" param and arbitrary precision.
If result guaranteedly fits in a small int, it is handled in objint.c. Otherwise, it is delegated to mp_obj_int_from_bytes_impl(), which should be implemented by individual objint_*.c, similar to mp_obj_int_to_bytes_impl().
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r--py/objint_mpz.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 5ca2bf53b..d465ef965 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -107,6 +107,12 @@ char *mp_obj_int_formatted_impl(char **buf, size_t *buf_size, size_t *fmt_size,
return str;
}
+mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf) {
+ mp_obj_int_t *o = mp_obj_int_new_mpz();
+ mpz_set_from_bytes(&o->mpz, big_endian, len, buf);
+ return MP_OBJ_FROM_PTR(o);
+}
+
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);