summaryrefslogtreecommitdiff
path: root/alloc.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-10-31 21:27:32 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-11-01 00:50:08 +0300
commit2343f553de8e127eb8540c5044d355dc5fb490cd (patch)
treef41632cce4bb5df45669071f00d756e95de740ee /alloc.c
parentc0e2c507f11e43f043a866514b5b75c60f71dc53 (diff)
downloadbdwgc-2343f553de8e127eb8540c5044d355dc5fb490cd.tar.gz
Fix negative heap size values reported in WARN
Issue #496 (bdwgc). WARN_PRIuPTR is now used to print unsigned values in WARN() calls. Also, byte values are replaced with KiB ones in some WARN() calls. * allchblk.c (GC_allochblk_nth): Use WARN_PRIuPTR specifier instead of WARN_PRIdPTR. * alloc.c (GC_expand_hp_inner, GC_collect_or_expand): Likewise. * headers.c (GC_scratch_alloc): Likewise. * mark.c (alloc_mark_stack): Likewise. * misc.c (GC_enable): Likewise. * os_dep.c [NEED_PROC_MAPS] (GC_get_maps): Likewise. * os_dep.c [PROC_VDB] (GC_proc_read_dirty): Likewise. * win32_threads.c (GC_delete_thread): Likewise. * allchblk.c (GC_allochblk_nth): Print KiB value instead of in bytes in WARN message. * alloc.c (GC_expand_hp_inner): Likewise. * misc.c (GC_enable): Likewise. * alloc.c (GC_expand_hp_inner): Remove unneeded cast of bytes to word. * headers.c (GC_scratch_alloc): Likewise. * alloc.c [(!AMIGA || !GC_AMIGA_FASTALLOC) && USE_MUNMAP] (GC_collect_or_expand): Add assertion to indicate that there is no underflow in GC_heapsize-GC_unmapped_bytes. * include/private/gc_priv.h (WARN): Update comment. * include/private/gc_priv.h [!WARN_PRIdPTR] (WARN_PRIuPTR): Define.
Diffstat (limited to 'alloc.c')
-rw-r--r--alloc.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/alloc.c b/alloc.c
index dd873190..5dc43963 100644
--- a/alloc.c
+++ b/alloc.c
@@ -1529,14 +1529,13 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
}
space = GET_MEM(bytes);
if (EXPECT(NULL == space, FALSE)) {
- WARN("Failed to expand heap by %" WARN_PRIdPTR " bytes\n",
- (word)bytes);
+ WARN("Failed to expand heap by %" WARN_PRIuPTR " KiB\n", bytes >> 10);
return FALSE;
}
GC_add_to_our_memory((ptr_t)space, bytes);
GC_last_heap_growth_gc_no = GC_gc_no;
GC_INFOLOG_PRINTF("Grow heap to %lu KiB after %lu bytes allocated\n",
- TO_KiB_UL(GC_heapsize + (word)bytes),
+ TO_KiB_UL(GC_heapsize + bytes),
(unsigned long)GC_bytes_allocd);
/* Adjust heap limits generously for blacklisting to work better. */
@@ -1708,7 +1707,10 @@ GC_INNER GC_bool GC_collect_or_expand(word needed_blocks,
GC_gcollect_inner();
} else {
# if !defined(AMIGA) || !defined(GC_AMIGA_FASTALLOC)
- WARN("Out of Memory! Heap size: %" WARN_PRIdPTR " MiB."
+# ifdef USE_MUNMAP
+ GC_ASSERT(GC_heapsize >= GC_unmapped_bytes);
+# endif
+ WARN("Out of Memory! Heap size: %" WARN_PRIuPTR " MiB."
" Returning NULL!\n", (GC_heapsize - GC_unmapped_bytes) >> 20);
# endif
RESTORE_CANCEL(cancel_state);