py: Factor duplicated function to calculate size of formatted int.

This commit is contained in:
Damien George
2016-10-11 13:11:32 +11:00
parent df3e5d2b2f
commit 8bb7d958f1
5 changed files with 10 additions and 31 deletions

View File

@@ -95,7 +95,7 @@ char *mp_obj_int_formatted_impl(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
const mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t needed_size = mpz_as_str_size(&self->mpz, base, prefix, comma);
mp_uint_t needed_size = mp_int_format_size(mpz_max_num_bits(&self->mpz), base, prefix, comma);
if (needed_size > *buf_size) {
*buf = m_new(char, needed_size);
*buf_size = needed_size;