summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alloc.c6
-rw-r--r--backgraph.c5
-rw-r--r--headers.c27
-rw-r--r--include/private/gc_priv.h3
4 files changed, 22 insertions, 19 deletions
diff --git a/alloc.c b/alloc.c
index f269dbfe..02852ed2 100644
--- a/alloc.c
+++ b/alloc.c
@@ -1334,7 +1334,7 @@ GC_API void GC_CALL GC_gcollect_and_unmap(void)
/* Defined to do nothing if USE_PROC_FOR_LIBRARIES not set. */
GC_INNER void GC_add_to_our_memory(ptr_t p, size_t bytes)
{
- if (0 == p) return;
+ GC_ASSERT(p != NULL);
if (GC_n_memory >= MAX_HEAP_SECTS)
ABORT("Too many GC-allocated memory sections: Increase MAX_HEAP_SECTS");
GC_our_memory[GC_n_memory].hs_start = p;
@@ -1555,12 +1555,12 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
return(FALSE);
}
space = GET_MEM(bytes);
- GC_add_to_our_memory((ptr_t)space, bytes);
- if (space == 0) {
+ if (EXPECT(NULL == space, FALSE)) {
WARN("Failed to expand heap by %" WARN_PRIdPTR " bytes\n",
(word)bytes);
return(FALSE);
}
+ GC_add_to_our_memory((ptr_t)space, bytes);
GC_INFOLOG_PRINTF("Grow heap to %lu KiB after %lu bytes allocated\n",
TO_KiB_UL(GC_heapsize + (word)bytes),
(unsigned long)GC_bytes_allocd);
diff --git a/backgraph.c b/backgraph.c
index 6c8f5660..43fe4026 100644
--- a/backgraph.c
+++ b/backgraph.c
@@ -148,8 +148,9 @@ static void push_in_progress(ptr_t p)
BCOPY(in_progress_space, new_in_progress_space,
n_in_progress * sizeof(ptr_t));
}
- GC_add_to_our_memory((ptr_t)new_in_progress_space,
- in_progress_size * sizeof(ptr_t));
+ if (EXPECT(new_in_progress_space != NULL, TRUE))
+ GC_add_to_our_memory((ptr_t)new_in_progress_space,
+ in_progress_size * sizeof(ptr_t));
# ifndef GWW_VDB
GC_scratch_recycle_no_gww(in_progress_space,
n_in_progress * sizeof(ptr_t));
diff --git a/headers.c b/headers.c
index 25524176..d2d3da8a 100644
--- a/headers.c
+++ b/headers.c
@@ -120,34 +120,37 @@ GC_INNER ptr_t GC_scratch_alloc(size_t bytes)
if (bytes >= MINHINCR * HBLKSIZE) {
bytes_to_get = ROUNDUP_PAGESIZE_IF_MMAP(bytes);
result = (ptr_t)GET_MEM(bytes_to_get);
- GC_add_to_our_memory(result, bytes_to_get);
- /* No update of scratch free area pointer; get memory directly. */
-# ifdef USE_SCRATCH_LAST_END_PTR
- if (result != NULL) {
+ if (result != NULL) {
+ GC_add_to_our_memory(result, bytes_to_get);
+ /* No update of scratch free area pointer; */
+ /* get memory directly. */
+# ifdef USE_SCRATCH_LAST_END_PTR
/* Update end point of last obtained area (needed only */
/* by GC_register_dynamic_libraries for some targets). */
GC_scratch_last_end_ptr = result + bytes;
- }
-# endif
+# endif
+ }
return result;
}
bytes_to_get = ROUNDUP_PAGESIZE_IF_MMAP(MINHINCR * HBLKSIZE);
/* round up for safety */
result = (ptr_t)GET_MEM(bytes_to_get);
- GC_add_to_our_memory(result, bytes_to_get);
- if (NULL == result) {
+ if (EXPECT(NULL == result, FALSE)) {
WARN("Out of memory - trying to allocate requested amount"
" (%" WARN_PRIdPTR " bytes)...\n", (word)bytes);
bytes_to_get = ROUNDUP_PAGESIZE_IF_MMAP(bytes);
result = (ptr_t)GET_MEM(bytes_to_get);
- GC_add_to_our_memory(result, bytes_to_get);
-# ifdef USE_SCRATCH_LAST_END_PTR
- if (result != NULL)
+ if (result != NULL) {
+ GC_add_to_our_memory(result, bytes_to_get);
+# ifdef USE_SCRATCH_LAST_END_PTR
GC_scratch_last_end_ptr = result + bytes;
-# endif
+# endif
+ }
return result;
}
+
+ GC_add_to_our_memory(result, bytes_to_get);
/* TODO: some amount of unallocated space may remain unused forever */
/* Update scratch area pointers and retry. */
GC_scratch_free_ptr = result;
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index 60840b92..54fd8173 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -2261,9 +2261,8 @@ GC_INNER hdr * GC_find_header(ptr_t h);
#ifdef USE_PROC_FOR_LIBRARIES
GC_INNER void GC_add_to_our_memory(ptr_t p, size_t bytes);
/* Add a chunk to GC_our_memory. */
- /* If p == 0, do nothing. */
#else
-# define GC_add_to_our_memory(p, bytes)
+# define GC_add_to_our_memory(p, bytes) ((void)(p), (void)(bytes))
#endif
GC_INNER void GC_print_all_errors(void);