Skip to content

Commit d1ae6ae

Browse files
committed
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.
1 parent 4f29b31 commit d1ae6ae

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

py/objint.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,17 @@ mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
127127
#undef MP_FLOAT_EXP_SHIFT_I32
128128
#endif
129129

130+
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
131+
typedef mp_longint_impl_t fmt_int_t;
132+
#else
133+
typedef mp_int_t fmt_int_t;
134+
#endif
135+
130136
void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
131137
(void)kind;
132138
// The size of this buffer is rather arbitrary. If it's not large
133139
// enough, a dynamic one will be allocated.
134-
char stack_buf[sizeof(mp_int_t) * 4];
140+
char stack_buf[sizeof(fmt_int_t) * 4];
135141
char *buf = stack_buf;
136142
size_t buf_size = sizeof(stack_buf);
137143
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
144150
}
145151
}
146152

147-
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
148-
typedef mp_longint_impl_t fmt_int_t;
149-
#else
150-
typedef mp_int_t fmt_int_t;
151-
#endif
152-
153153
STATIC const uint8_t log_base2_floor[] = {
154154
0, 1, 1, 2,
155155
2, 2, 2, 3,

0 commit comments

Comments
 (0)