From 60af658b0071b5ed3c9b8e6c0ad6ac3adc086a3e Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 16 Oct 2015 01:38:08 +0300 Subject: [PATCH] Consistently set type of DATASTART/END to ptr_t (code refactoring) * dyn_load.c (GC_register_map_entries, GC_register_dynamic_libraries_dl_iterate_phdr): Remove redundant casting to ptr_t of DATASTART, DATAEND, DATAEND2. * os_dep.c (GC_register_data_segments): Likewise. * include/private/gcconfig.h (DATAEND, DATASTART): Add cast to ptr_t where missing. --- dyn_load.c | 10 +++++----- include/private/gcconfig.h | 9 +++++---- os_dep.c | 14 +++++++------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/dyn_load.c b/dyn_load.c index 381e945a..c8d051ab 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -314,11 +314,11 @@ STATIC word GC_register_map_entries(char *maps) /* Evaluate DATASTART only once. */ if (datastart_cached == (ptr_t)(word)-1) { - datastart_cached = (ptr_t)(DATASTART); + datastart_cached = DATASTART; } datastart = datastart_cached; # else - datastart = (ptr_t)(DATASTART); + datastart = DATASTART; # endif GC_ASSERT(I_HOLD_LOCK()); @@ -606,7 +606,7 @@ STATIC GC_bool GC_register_dynamic_libraries_dl_iterate_phdr(void) /* Evaluate DATASTART only once. */ if (datastart_cached == (ptr_t)(word)-1) { - datastart_cached = (ptr_t)(DATASTART); + datastart_cached = DATASTART; } datastart = (char *)datastart_cached; # else @@ -617,7 +617,7 @@ STATIC GC_bool GC_register_dynamic_libraries_dl_iterate_phdr(void) static ptr_t dataend_cached = 0; /* Evaluate DATAEND only once. */ if (dataend_cached == 0) { - dataend_cached = (ptr_t)(DATAEND); + dataend_cached = DATAEND; } dataend = (char *)dataend_cached; } @@ -629,7 +629,7 @@ STATIC GC_bool GC_register_dynamic_libraries_dl_iterate_phdr(void) /* statically linked executables. */ GC_add_roots_inner(datastart, dataend, TRUE); # if defined(DATASTART2) - GC_add_roots_inner(DATASTART2, (char *)(DATAEND2), TRUE); + GC_add_roots_inner(DATASTART2, DATAEND2, TRUE); # endif } return TRUE; diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 758a3348..638b7051 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -64,7 +64,7 @@ extern char etext[]; extern int _end[]; # define DATASTART ((ptr_t)(etext)) -# define DATAEND (_end) +# define DATAEND ((ptr_t)(_end)) # define mach_type_known # endif @@ -1043,7 +1043,7 @@ # define ALIGNMENT 4 # define OS_TYPE "NOSYS" extern void __end[], __dso_handle[]; -# define DATASTART (__dso_handle) /* OK, that's ugly. */ +# define DATASTART ((ptr_t)__dso_handle) /* OK, that's ugly. */ # define DATAEND ((ptr_t)(__end)) /* Stack starts at 0xE0000000 for the simulator. */ # undef STACK_GRAN @@ -2013,7 +2013,8 @@ extern int etext[]; # ifdef CX_UX # define OS_TYPE "CX_UX" -# define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000) +# define DATASTART ((ptr_t)((((word)(etext) + 0x3fffff) & ~0x3fffff) \ + + 0x10000)) # endif # ifdef DGUX # define OS_TYPE "DGUX" @@ -2317,7 +2318,7 @@ # define LINUX_STACKBOTTOM # define SEARCH_FOR_DATA_START extern int _end[]; -# define DATAEND (_end) +# define DATAEND ((ptr_t)(_end)) # endif # ifdef M32R diff --git a/os_dep.c b/os_dep.c index 5548ca43..879d2adb 100644 --- a/os_dep.c +++ b/os_dep.c @@ -1839,7 +1839,7 @@ void GC_register_data_segments(void) /* string constants in the text segment, but after etext. */ /* Use plan B. Note that we now know there is a gap between */ /* text and data segments, so plan A bought us something. */ - result = (char *)GC_find_limit((ptr_t)(DATAEND), FALSE); + result = (char *)GC_find_limit(DATAEND, FALSE); } return((ptr_t)result); } @@ -1864,13 +1864,13 @@ void GC_register_data_segments(void) if (SETJMP(GC_jmp_buf) == 0) { /* Try reading at the address. */ /* This should happen before there is another thread. */ - for (; next_page < (word)(DATAEND); next_page += (word)max_page_size) + for (; next_page < (word)DATAEND; next_page += (word)max_page_size) *(volatile char *)next_page; GC_reset_fault_handler(); } else { GC_reset_fault_handler(); /* As above, we go to plan B */ - result = GC_find_limit((ptr_t)(DATAEND), FALSE); + result = GC_find_limit(DATAEND, FALSE); } return(result); } @@ -1895,7 +1895,7 @@ void GC_register_data_segments(void) for (;;) { region_end = GC_find_limit_openbsd(region_start, DATAEND); GC_add_roots_inner(region_start, region_end, FALSE); - if ((word)region_end >= (word)(DATAEND)) + if ((word)region_end >= (word)DATAEND) break; region_start = GC_skip_hole_openbsd(region_end, DATAEND); } @@ -1917,14 +1917,14 @@ void GC_register_data_segments(void) GC_ASSERT(DATASTART); { ptr_t p = (ptr_t)sbrk(0); - if ((word)(DATASTART) < (word)p) + if ((word)DATASTART < (word)p) GC_add_roots_inner(DATASTART, p, FALSE); } # else GC_ASSERT(DATASTART); - GC_add_roots_inner(DATASTART, (ptr_t)(DATAEND), FALSE); + GC_add_roots_inner(DATASTART, DATAEND, FALSE); # if defined(DATASTART2) - GC_add_roots_inner(DATASTART2, (ptr_t)(DATAEND2), FALSE); + GC_add_roots_inner(DATASTART2, DATAEND2, FALSE); # endif # endif # endif -- 2.40.0