Skip to content

Commit

Permalink
Remove redundant pointer casts to void pointer
Browse files Browse the repository at this point in the history
(refactoring)

* alloc.c (GC_add_to_heap, GC_expand_hp_inner): Remove redundant cast
of a pointer to void*.
* cord/cordxtra.c [!CORD_USE_GCC_ATOMIC] (get_cache_line): Likewise.
* dbg_mlc.c (GC_make_closure, GC_debug_invoke_finalizer): Likewise.
* finalize.c (GC_register_disappearing_link_inner,
GC_register_finalizer_inner): Likewise.
* misc.c [ENABLE_TRACE] (GC_init): Likewise.
* misc.c (GC_call_with_stack_base): Likewise.
* os_dep.c [USE_MUNMAP] (block_unmap_inner, GC_remap): Likewise.
* pthread_support.c (GC_get_my_stackbottom): Likewise.
* ptr_chck.c (GC_pre_incr, GC_post_incr): Likewise.
* tests/gctest.c [GC_GCJ_SUPPORT] (fake_gcj_mark_proc): Likewise.
* tests/gctest.c (reverse_test_inner): Likewise.
* tests/gctest.c [!GC_NO_FINALIZATION] (mktree): Likewise.
* tests/weakmap.c (weakmap_add): Likewise.
* misc.c [!ALWAYS_SMALL_CLEAR_STACK && !STACK_NOT_SCANNED && THREADS]
(GC_clear_stack): Specify that cast of a volatile pointer to void* is
needed.
* pthread_start.c (GC_pthread_start_inner): Likewise.
* tests/gctest.c [THREADS && !GC_PTHREADS && GC_WIN32_THREADS
&& !TEST_ENDTHREADEX] (fork_a_thread): Replace (GC_word)0 to 0U in
arguments of CreateThread() call.
* tests/gctest.c [!GC_NO_FINALIZATION] (mktree): Remove redundant
parentheses around live_indicators[my_index].
  • Loading branch information
ivmai committed Apr 15, 2024
1 parent e37ab2a commit 10af6eb
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 44 deletions.
8 changes: 4 additions & 4 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1484,14 +1484,14 @@ STATIC void GC_add_to_heap(struct hblk *h, size_t bytes)

if (ADDR_GE((ptr_t)GC_least_plausible_heap_addr, (ptr_t)h)
|| EXPECT(NULL == GC_least_plausible_heap_addr, FALSE)) {
GC_least_plausible_heap_addr = (void *)((ptr_t)h - sizeof(word));
GC_least_plausible_heap_addr = (ptr_t)h - sizeof(word);
/* Making it a little smaller than necessary prevents */
/* us from getting a false hit from the variable */
/* itself. There's some unintentional reflection */
/* here. */
}
if (ADDR_LT((ptr_t)GC_greatest_plausible_heap_addr, endp)) {
GC_greatest_plausible_heap_addr = (void *)endp;
GC_greatest_plausible_heap_addr = endp;
}
# ifdef SET_REAL_HEAP_BOUNDS
if (ADDR_LT((ptr_t)h, GC_least_real_heap_addr)
Expand Down Expand Up @@ -1622,14 +1622,14 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)

if (ADDR_LT((ptr_t)space, new_limit)
&& ADDR_LT((ptr_t)GC_greatest_plausible_heap_addr, new_limit))
GC_greatest_plausible_heap_addr = (void *)new_limit;
GC_greatest_plausible_heap_addr = new_limit;
} else {
/* Heap is growing down. */
ptr_t new_limit = (ptr_t)space - expansion_slop - sizeof(word);

if (ADDR_LT(new_limit, (ptr_t)space)
&& ADDR_LT(new_limit, (ptr_t)GC_least_plausible_heap_addr))
GC_least_plausible_heap_addr = (void *)new_limit;
GC_least_plausible_heap_addr = new_limit;
}
GC_last_heap_addr = (ptr_t)space;

Expand Down
2 changes: 1 addition & 1 deletion cord/cordxtra.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ static void * GC_CALLBACK refill_cache(void * client_data)
#ifndef CORD_USE_GCC_ATOMIC
static void * GC_CALLBACK get_cache_line(void * client_data)
{
return (void *)(*(cache_line **)client_data);
return *(cache_line **)client_data;
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions dbg_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,15 +1011,15 @@ STATIC void * GC_make_closure(GC_finalization_proc fn, void * data)
result -> cl_fn = fn;
result -> cl_data = data;
}
return (void *)result;
return result;
}

/* An auxiliary fns to make finalization work correctly with displaced */
/* pointers introduced by the debugging allocators. */
STATIC void GC_CALLBACK GC_debug_invoke_finalizer(void * obj, void * data)
{
struct closure * cl = (struct closure *) data;
(*(cl -> cl_fn))((void *)((char *)obj + sizeof(oh)), cl -> cl_data);
cl -> cl_fn((ptr_t)obj + sizeof(oh), cl -> cl_data);
}

/* Special finalizer_proc value to detect GC_register_finalizer() failure. */
Expand Down
12 changes: 6 additions & 6 deletions finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ STATIC int GC_register_disappearing_link_inner(
UNLOCK();
# ifndef DBG_HDRS_ALL
/* Free unused new_dl returned by GC_oom_fn() */
GC_free((void *)new_dl);
GC_free(new_dl);
# endif
return GC_DUPLICATE;
}
Expand Down Expand Up @@ -723,7 +723,7 @@ STATIC void GC_register_finalizer_inner(void * obj,
/* Interruption by a signal in the middle of this */
/* should be safe. The client may see only *ocd */
/* updated, but we'll declare that to be his problem. */
if (ocd) *ocd = (void *)(curr_fo -> fo_client_data);
if (ocd) *ocd = curr_fo -> fo_client_data;
if (ofn) *ofn = curr_fo -> fo_fn;
/* Delete the structure for obj. */
if (prev_fo == 0) {
Expand All @@ -738,7 +738,7 @@ STATIC void GC_register_finalizer_inner(void * obj,
/* estimate will only make the table larger than */
/* necessary. */
# if !defined(THREADS) && !defined(DBG_HDRS_ALL)
GC_free((void *)curr_fo);
GC_free(curr_fo);
# endif
} else {
curr_fo -> fo_fn = fn;
Expand All @@ -759,7 +759,7 @@ STATIC void GC_register_finalizer_inner(void * obj,
UNLOCK();
# ifndef DBG_HDRS_ALL
/* Free unused new_fo returned by GC_oom_fn() */
GC_free((void *)new_fo);
GC_free(new_fo);
# endif
return;
}
Expand Down Expand Up @@ -1298,8 +1298,8 @@ GC_API int GC_CALL GC_invoke_finalizers(void)
UNLOCK();
fo_set_next(curr_fo, 0);
real_ptr = (ptr_t)(curr_fo -> fo_hidden_base); /* revealed */
(*(curr_fo -> fo_fn))(real_ptr, curr_fo -> fo_client_data);
curr_fo -> fo_client_data = 0;
curr_fo -> fo_fn(real_ptr, curr_fo -> fo_client_data);
curr_fo -> fo_client_data = NULL;
++count;
/* Explicit freeing of curr_fo is probably a bad idea. */
/* It throws off accounting if nearly all objects are */
Expand Down
8 changes: 4 additions & 4 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ STATIC void GC_init_size_map(void)
/* implementations of GC_clear_stack_inner. */
return GC_clear_stack_inner(arg, limit);
}
BZERO((void *)dummy, SMALL_CLEAR_SIZE*sizeof(word));
BZERO((/* no volatile */ void *)dummy, SMALL_CLEAR_SIZE * sizeof(word));
# else
if (GC_gc_no != GC_stack_last_cleared) {
/* Start things over, so we clear the entire stack again. */
Expand Down Expand Up @@ -1177,7 +1177,7 @@ GC_API void GC_CALL GC_init(void)
ptr_t addr = (ptr_t)STRTOULL(str, NULL, 16);

if ((word)addr < 0x1000)
WARN("Unlikely trace address: %p\n", (void *)addr);
WARN("Unlikely trace address: %p\n", addr);
GC_trace_addr = addr;
# endif
}
Expand Down Expand Up @@ -2283,9 +2283,9 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func fn, void *arg)
struct GC_stack_base base;
void *result;

base.mem_base = (void *)&base;
base.mem_base = &base;
# ifdef IA64
base.reg_base = (void *)GC_save_regs_in_stack();
base.reg_base = GC_save_regs_in_stack();
/* TODO: Unnecessarily flushes register stack, */
/* but that probably doesn't hurt. */
# elif defined(E2K)
Expand Down
4 changes: 2 additions & 2 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -2660,7 +2660,7 @@ static void block_unmap_inner(ptr_t start_addr, size_t len)

if (EXPECT(MAP_FAILED == result, FALSE))
ABORT_ON_REMAP_FAIL("unmap: mmap", start_addr, len);
if (result != (void *)start_addr)
if (result != start_addr)
ABORT("unmap: mmap() result differs from start_addr");
# if defined(CPPCHECK) || defined(LINT2)
/* Explicitly store the resource handle to a global variable. */
Expand Down Expand Up @@ -2741,7 +2741,7 @@ GC_INNER void GC_remap(ptr_t start, size_t bytes)
zero_fd, 0 /* offset */);
if (EXPECT(MAP_FAILED == result, FALSE))
ABORT_ON_REMAP_FAIL("remap: mmap", start_addr, len);
if (result != (void *)start_addr)
if (result != start_addr)
ABORT("remap: mmap() result differs from start_addr");
# if defined(CPPCHECK) || defined(LINT2)
GC_noop1((word)result);
Expand Down
4 changes: 2 additions & 2 deletions pthread_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GC_INNER_PTHRSTART void *GC_CALLBACK GC_pthread_start_inner(
GC_start_rtn_prepare_thread(&start, &start_arg, sb, arg);

# ifndef NACL
pthread_cleanup_push(GC_thread_exit_proc, (void *)me);
pthread_cleanup_push(GC_thread_exit_proc, (/* no volatile */ void *)me);
# endif
result = (*start)(start_arg);
# if defined(DEBUG_THREADS) && !defined(GC_PTHREAD_START_STANDALONE)
Expand All @@ -62,7 +62,7 @@ GC_INNER_PTHRSTART void *GC_CALLBACK GC_pthread_start_inner(
/* Cleanup acquires the allocator lock, ensuring that we cannot exit */
/* while a collection that thinks we are alive is trying to stop us. */
# ifdef NACL
GC_thread_exit_proc((void *)me);
GC_thread_exit_proc((/* no volatile */ void *)me);
# else
pthread_cleanup_pop(1);
# endif
Expand Down
2 changes: 1 addition & 1 deletion pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ GC_API void * GC_CALL GC_get_my_stackbottom(struct GC_stack_base *sb)
sb -> reg_base = crtn -> backing_store_end;
# endif
READER_UNLOCK();
return (void *)me; /* gc_thread_handle */
return me; /* gc_thread_handle */
}

/* GC_call_with_gc_active() has the opposite to GC_do_blocking() */
Expand Down
8 changes: 4 additions & 4 deletions ptr_chck.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ GC_API void * GC_CALL GC_is_visible(void *p)

GC_API void * GC_CALL GC_pre_incr(void **p, ptrdiff_t how_much)
{
void * initial = *p;
void * result = GC_same_obj((void *)((ptr_t)initial + how_much), initial);
void *initial = *p;
void *result = GC_same_obj((ptr_t)initial + how_much, initial);

if (!GC_all_interior_pointers) {
(void)GC_is_valid_displacement(result);
Expand All @@ -229,8 +229,8 @@ GC_API void * GC_CALL GC_pre_incr(void **p, ptrdiff_t how_much)

GC_API void * GC_CALL GC_post_incr(void **p, ptrdiff_t how_much)
{
void * initial = *p;
void * result = GC_same_obj((void *)((ptr_t)initial + how_much), initial);
void *initial = *p;
void *result = GC_same_obj((ptr_t)initial + how_much, initial);

if (!GC_all_interior_pointers) {
(void)GC_is_valid_displacement(result);
Expand Down
32 changes: 15 additions & 17 deletions tests/gctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,11 @@ static struct GC_ms_entry *GC_CALLBACK fake_gcj_mark_proc(GC_word *addr,
addr = (GC_word *)GC_USR_PTR_FROM_BASE(addr);
}
x = (sexpr)(addr + 1); /* Skip the vtable pointer. */
mark_stack_top = GC_MARK_AND_PUSH((void *)(x -> sexpr_cdr),
mark_stack_top = GC_MARK_AND_PUSH(x -> sexpr_cdr,
mark_stack_top, mark_stack_limit,
(void **)&(x -> sexpr_cdr));
mark_stack_top = GC_MARK_AND_PUSH((void *)(x -> sexpr_car),
mark_stack_top, mark_stack_limit,
(void **)&(x -> sexpr_car));
return mark_stack_top;
return GC_MARK_AND_PUSH(x -> sexpr_car, mark_stack_top, mark_stack_limit,
(void **)&(x -> sexpr_car));
}

#endif /* GC_GCJ_SUPPORT */
Expand Down Expand Up @@ -793,7 +791,7 @@ static void check_uncollectable_ints(sexpr list, int low, int up)
# else
DWORD thread_id;

h = CreateThread((SECURITY_ATTRIBUTES *)NULL, (GC_word)0,
h = CreateThread((SECURITY_ATTRIBUTES *)NULL, 0U,
tiny_reverse_test, NULL, (DWORD)0, &thread_id);
/* Explicitly specify types of the */
/* arguments to test the prototype. */
Expand Down Expand Up @@ -896,18 +894,18 @@ static void *GC_CALLBACK reverse_test_inner(void *data)
/* Check that realloc updates object descriptors correctly */
f = (sexpr *)checkOOM(GC_MALLOC(4 * sizeof(sexpr)));
AO_fetch_and_add1(&collectable_count);
f = (sexpr *)checkOOM(GC_REALLOC((void *)f, 6 * sizeof(sexpr)));
f = (sexpr *)checkOOM(GC_REALLOC(f, 6 * sizeof(sexpr)));
AO_fetch_and_add1(&realloc_count);
GC_PTR_STORE_AND_DIRTY(f + 5, ints(1, 17));
g = (sexpr *)checkOOM(GC_MALLOC(513 * sizeof(sexpr)));
AO_fetch_and_add1(&collectable_count);
test_generic_malloc_or_special(g);
g = (sexpr *)checkOOM(GC_REALLOC((void *)g, 800 * sizeof(sexpr)));
g = (sexpr *)checkOOM(GC_REALLOC(g, 800 * sizeof(sexpr)));
AO_fetch_and_add1(&realloc_count);
GC_PTR_STORE_AND_DIRTY(g + 799, ints(1, 18));
h = (sexpr *)checkOOM(GC_MALLOC(1025 * sizeof(sexpr)));
AO_fetch_and_add1(&collectable_count);
h = (sexpr *)checkOOM(GC_REALLOC((void *)h, 2000 * sizeof(sexpr)));
h = (sexpr *)checkOOM(GC_REALLOC(h, 2000 * sizeof(sexpr)));
AO_fetch_and_add1(&realloc_count);
# ifdef GC_GCJ_SUPPORT
GC_PTR_STORE_AND_DIRTY(h + 1999, gcj_ints(1, 200));
Expand All @@ -926,7 +924,7 @@ static void *GC_CALLBACK reverse_test_inner(void *data)
c = (sexpr)((char *)c + sizeof(char *));
d = (sexpr)((char *)d + sizeof(char *));

GC_FREE((void *)e);
GC_FREE(e);

check_ints(b,1,50);
# ifdef PRINT_AND_CHECK_INT_LIST
Expand Down Expand Up @@ -1103,25 +1101,25 @@ static tn * mktree(int n)

# ifndef GC_NO_FINALIZATION
if (!GC_get_find_leak()) {
GC_REGISTER_FINALIZER((void *)result, finalizer, (void *)(GC_word)n,
GC_REGISTER_FINALIZER(result, finalizer, (void *)(GC_word)n,
(GC_finalization_proc *)0, (void **)0);
if (my_index >= MAX_FINALIZED) {
GC_printf("live_indicators overflowed\n");
FAIL;
}
live_indicators[my_index] = 13;
if (GC_GENERAL_REGISTER_DISAPPEARING_LINK(
(void **)(&(live_indicators[my_index])), result) != 0) {
(void **)&live_indicators[my_index], result) != 0) {
GC_printf("GC_general_register_disappearing_link failed\n");
FAIL;
}
if (GC_move_disappearing_link((void **)(&(live_indicators[my_index])),
(void **)(&(live_indicators[my_index]))) != GC_SUCCESS) {
if (GC_move_disappearing_link((void **)&live_indicators[my_index],
(void **)&live_indicators[my_index]) != GC_SUCCESS) {
GC_printf("GC_move_disappearing_link(link,link) failed\n");
FAIL;
}
*new_link = (void *)live_indicators[my_index];
if (GC_move_disappearing_link((void **)(&(live_indicators[my_index])),
if (GC_move_disappearing_link((void **)&live_indicators[my_index],
new_link) != GC_SUCCESS) {
GC_printf("GC_move_disappearing_link(new_link) failed\n");
FAIL;
Expand All @@ -1135,13 +1133,13 @@ static tn * mktree(int n)
GC_printf("GC_unregister_disappearing_link failed\n");
FAIL;
}
if (GC_move_disappearing_link((void **)(&(live_indicators[my_index])),
if (GC_move_disappearing_link((void **)&live_indicators[my_index],
new_link) != GC_NOT_FOUND) {
GC_printf("GC_move_disappearing_link(new_link) failed 2\n");
FAIL;
}
if (GC_GENERAL_REGISTER_DISAPPEARING_LINK(
(void **)(&(live_indicators[my_index])), result) != 0) {
(void **)&live_indicators[my_index], result) != 0) {
GC_printf("GC_general_register_disappearing_link failed 2\n");
FAIL;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/weakmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static void *weakmap_add(struct weakmap *wm, void *obj, size_t obj_size)
(int)wm->weakobj_kind);
CHECK_OUT_OF_MEMORY(new_base);
*new_base = (GC_word)wm | FINALIZER_CLOSURE_FLAG;
new_obj = (void *)(new_base + 1);
new_obj = new_base + 1;
memcpy(new_obj, obj, wm->obj_size);
GC_end_stubborn_change(new_base);

Expand Down

0 comments on commit 10af6eb

Please sign in to comment.