Skip to content

Commit acaccb3

Browse files
committed
py/gc: When printing info, use %u instead of UINT_FMT for size_t args.
Ideally we'd use %zu for size_t args, but that's unlikely to be supported by all runtimes, and we would then need to implement it in mp_printf. So simplest and most portable option is to use %u and cast the argument to uint(=unsigned int). Note: reason for the change is that UINT_FMT can be %llu (size suitable for mp_uint_t) which is wider than size_t and prints incorrect results.
1 parent dd5353a commit acaccb3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

py/gc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,10 +658,10 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
658658
void gc_dump_info(void) {
659659
gc_info_t info;
660660
gc_info(&info);
661-
mp_printf(&mp_plat_print, "GC: total: " UINT_FMT ", used: " UINT_FMT ", free: " UINT_FMT "\n",
662-
info.total, info.used, info.free);
663-
mp_printf(&mp_plat_print, " No. of 1-blocks: " UINT_FMT ", 2-blocks: " UINT_FMT ", max blk sz: " UINT_FMT "\n",
664-
info.num_1block, info.num_2block, info.max_block);
661+
mp_printf(&mp_plat_print, "GC: total: %u, used: %u, free: %u\n",
662+
(uint)info.total, (uint)info.used, (uint)info.free);
663+
mp_printf(&mp_plat_print, " No. of 1-blocks: %u, 2-blocks: %u, max blk sz: %u\n",
664+
(uint)info.num_1block, (uint)info.num_2block, (uint)info.max_block);
665665
}
666666

667667
void gc_dump_alloc_table(void) {
@@ -682,7 +682,7 @@ void gc_dump_alloc_table(void) {
682682
}
683683
if (bl2 - bl >= 2 * DUMP_BYTES_PER_LINE) {
684684
// there are at least 2 lines containing only free blocks, so abbreviate their printing
685-
mp_printf(&mp_plat_print, "\n (" UINT_FMT " lines all free)", (bl2 - bl) / DUMP_BYTES_PER_LINE);
685+
mp_printf(&mp_plat_print, "\n (%u lines all free)", (uint)(bl2 - bl) / DUMP_BYTES_PER_LINE);
686686
bl = bl2 & (~(DUMP_BYTES_PER_LINE - 1));
687687
if (bl >= MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB) {
688688
// got to end of heap

0 commit comments

Comments
 (0)