py/objint: Allow to print long-long ints without using the heap.
Some stack is allocated to format ints, and when the int implementation uses long-long there should be additional stack allocated compared with the other cases. This patch uses the existing "fmt_int_t" type to determine the amount of stack to allocate.
This commit is contained in:
parent
4f29b315a6
commit
d1ae6ae080
14
py/objint.c
14
py/objint.c
@ -127,11 +127,17 @@ mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
|
|||||||
#undef MP_FLOAT_EXP_SHIFT_I32
|
#undef MP_FLOAT_EXP_SHIFT_I32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
|
||||||
|
typedef mp_longint_impl_t fmt_int_t;
|
||||||
|
#else
|
||||||
|
typedef mp_int_t fmt_int_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||||
(void)kind;
|
(void)kind;
|
||||||
// The size of this buffer is rather arbitrary. If it's not large
|
// The size of this buffer is rather arbitrary. If it's not large
|
||||||
// enough, a dynamic one will be allocated.
|
// enough, a dynamic one will be allocated.
|
||||||
char stack_buf[sizeof(mp_int_t) * 4];
|
char stack_buf[sizeof(fmt_int_t) * 4];
|
||||||
char *buf = stack_buf;
|
char *buf = stack_buf;
|
||||||
size_t buf_size = sizeof(stack_buf);
|
size_t buf_size = sizeof(stack_buf);
|
||||||
size_t fmt_size;
|
size_t fmt_size;
|
||||||
@ -144,12 +150,6 @@ void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
|
|
||||||
typedef mp_longint_impl_t fmt_int_t;
|
|
||||||
#else
|
|
||||||
typedef mp_int_t fmt_int_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
STATIC const uint8_t log_base2_floor[] = {
|
STATIC const uint8_t log_base2_floor[] = {
|
||||||
0, 1, 1, 2,
|
0, 1, 1, 2,
|
||||||
2, 2, 2, 3,
|
2, 2, 2, 3,
|
||||||
|
Loading…
Reference in New Issue
Block a user