Skip to content

Commit 6224ceb

Browse files
committed
runtime: Fix printing failed allocation amounts.
On LP64 and LLP64 systems, size_t is bigger than unsigned. Printing the failed allocation as mp_uint_t allows the correct failed allocation size to be shown. However, there are occasions where mp_uint_t is bigger than size_t (nanbox). In that case, preserve the existing code path to avoid growth in executable size. Example where this affects the failed allocation message (on x86_64 coverage build): ``` >>> "a" * (1 << 54) ``` Before, this would print the size as 1. Now it prints it as 18014398509481985 (2**54 + 1). Signed-off-by: Jeff Epler <jepler@gmail.com>
1 parent 79e6805 commit 6224ceb

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

py/runtime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,14 +1684,14 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i
16841684
#endif // MICROPY_ENABLE_COMPILER
16851685

16861686
MP_NORETURN void m_malloc_fail(size_t num_bytes) {
1687-
DEBUG_printf("memory allocation failed, allocating %u bytes\n", (uint)num_bytes);
1687+
DEBUG_printf("memory allocation failed, allocating " SIZE_FMT " bytes\n", num_bytes);
16881688
#if MICROPY_ENABLE_GC
16891689
if (gc_is_locked()) {
16901690
mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("memory allocation failed, heap is locked"));
16911691
}
16921692
#endif
16931693
mp_raise_msg_varg(&mp_type_MemoryError,
1694-
MP_ERROR_TEXT("memory allocation failed, allocating %u bytes"), (uint)num_bytes);
1694+
MP_ERROR_TEXT("memory allocation failed, allocating " SIZE_FMT " bytes"), (mp_uint_t)num_bytes);
16951695
}
16961696

16971697
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NONE

0 commit comments

Comments
 (0)