From ccd9a5c6da392acc75d9c0fc643b43e775c53d5c Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 3 Feb 2012 19:56:22 +0400 Subject: [PATCH] Declare privately and use handy GC_base_C() for constant object pointers * dbg_mlc.c (GC_debug_change_stubborn, GC_debug_end_stubborn_change): Use GC_base_C() instead of GC_base() (remove cast to void pointer). * finalize.c (GC_general_register_disappearing_link): Likewise. * finalize.c (GC_register_disappearing_link, GC_finalize): Remove redundant cast to void pointer and ptr_t. * include/private/gc_priv.h (GC_base_C): New macro definition. --- dbg_mlc.c | 4 ++-- finalize.c | 6 +++--- include/private/gc_priv.h | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dbg_mlc.c b/dbg_mlc.c index daf8d23b..00586d18 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -574,7 +574,7 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb, GC_API void GC_CALL GC_debug_change_stubborn(const void *p) { - const void * q = GC_base((void *)p); + const void * q = GC_base_C(p); hdr * hhdr; if (q == 0) { @@ -591,7 +591,7 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb, GC_API void GC_CALL GC_debug_end_stubborn_change(const void *p) { - const void * q = GC_base((void *)p); + const void * q = GC_base_C(p); hdr * hhdr; if (q == 0) { diff --git a/finalize.c b/finalize.c index f66d76e0..94977773 100644 --- a/finalize.c +++ b/finalize.c @@ -137,7 +137,7 @@ GC_API int GC_CALL GC_register_disappearing_link(void * * link) { ptr_t base; - base = (ptr_t)GC_base((void *)link); + base = (ptr_t)GC_base(link); if (base == 0) ABORT("Bad arg to GC_register_disappearing_link"); return(GC_general_register_disappearing_link(link, base)); @@ -154,7 +154,7 @@ GC_API int GC_CALL GC_general_register_disappearing_link(void * * link, if (((word)link & (ALIGNMENT-1)) || link == NULL) ABORT("Bad arg to GC_general_register_disappearing_link"); LOCK(); - GC_ASSERT(obj != NULL && GC_base((void *)obj) == obj); + GC_ASSERT(obj != NULL && GC_base_C(obj) == obj); if (log_dl_table_size == -1 || GC_dl_entries > ((word)1 << log_dl_table_size)) { GC_grow_table((struct hash_chain_entry ***)(&dl_head), @@ -664,7 +664,7 @@ GC_INNER void GC_finalize(void) GC_bytes_finalized += curr_fo -> fo_object_size + sizeof(struct finalizable_object); - GC_ASSERT(GC_is_marked(GC_base((ptr_t)curr_fo))); + GC_ASSERT(GC_is_marked(GC_base(curr_fo))); curr_fo = next_fo; } else { prev_fo = curr_fo; diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 09584afc..e2af73f3 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1945,6 +1945,9 @@ GC_EXTERN GC_bool GC_print_back_height; GC_INNER void GC_dirty_init(void); #endif /* !GC_DISABLE_INCREMENTAL */ +/* Same as GC_base but excepts and returns a pointer to const object. */ +#define GC_base_C(p) ((const void *)GC_base((/* no const */ void *)(p))) + /* Stubborn objects: */ void GC_read_changed(void); /* Analogous to GC_read_dirty */ GC_bool GC_page_was_changed(struct hblk * h); -- 2.40.0