Skip to content

Commit

Permalink
Convert GC source files to valid C++ code
Browse files Browse the repository at this point in the history
Issue #206 (bdwgc).

* alloc.c (GC_copyright): Change type from char* const to
const char* const.
* alloc.c (GC_set_fl_marks, GC_clear_fl_marks, GC_finish_collection,
GC_allocobj): Add missing explicit casts from void* to ptr_t.
* backgraph.c [MAKE_BACK_GRAPH] (add_back_edges): Likewise.
* blacklst.c (GC_default_print_heap_obj_proc,
GC_print_blacklisted_ptr): Likewise.
* dbg_mlc.c (GC_get_back_ptr_info, GC_store_debug_info_inner,
GC_store_debug_info, GC_debug_malloc, GC_debug_malloc_ignore_off_page,
GC_debug_malloc_atomic_ignore_off_page, GC_debug_generic_malloc,
GC_debug_malloc_stubborn, GC_debug_malloc_atomic,
GC_debug_malloc_uncollectable, GC_debug_malloc_atomic_uncollectable,
GC_debug_free, GC_debug_free_inner, GC_debug_register_finalizer,
GC_debug_register_finalizer_no_order,
GC_debug_register_finalizer_unreachable,
GC_debug_register_finalizer_ignore_self): Likewise.
* finalize.c (GC_grow_table, push_and_mark_object,
ensure_toggleref_capacity, GC_dump_finalization_links,
GC_dump_finalization, GC_make_disappearing_links_disappear,
GC_remove_dangling_disappearing_links, GC_finalize): Likewise.
* gcj_mlc.c (GC_gcj_malloc, GC_debug_gcj_malloc,
GC_gcj_malloc_ignore_off_page): Likewise.
* include/private/gc_pmark.h (PUSH_CONTENTS_HDR): Likewise.
* mallocx.c (GC_memalign): Likewise.
* mark.c (GC_mark_from, GC_mark_and_push, GC_push_all_eager,
GC_push_all_stack, GC_push_marked1, GC_push_marked2, GC_push_marked4):
Likewise.
* mark_rts.c (GC_exclude_static_roots_inner): Likewise.
* misc.c (GC_base): Likewise.
* new_hblk.c (GC_new_hblk): Likewise.
* pthread_support.c (GC_register_altstack, GC_thr_init,
GC_record_stack_base): Likewise.
* ptr_chck.c (GC_is_visible): Likewise.
* reclaim.c (GC_reclaim_small_nonempty_block,
GC_disclaim_and_reclaim_or_free_small_block): Likewise.
* thread_local_alloc.c (GC_mark_thread_local_fls_for): Likewise.
* typd_mlc.c (GC_typed_mark_proc,
GC_malloc_explicitly_typed_ignore_off_page): Likewise.
* win32_threads.c (GC_record_stack_base, GC_get_stack_min,
GC_push_stack_for): Likewise.
* blacklst.c (GC_copy_bl): Rename "new" argument to "dest".
* dbg_mlc.c (GC_store_debug_info_inner, GC_print_smashed_obj): Change
type of p argument from ptr_t to void*.
* include/private/gc_priv.h (GC_is_heap_base, GC_is_static_root):
Likewise.
* mark_rts.c [!THREADS] (GC_is_static_root): Likewise.
* os_dep.c (GC_is_malloc_heap_base, GC_is_heap_base): Likewise.
* ptr_chck.c (GC_on_stack): Likewise.
* dbg_mlc.c (GC_print_obj): Change type of kind_str local variable
from char* to const char*.
* dbg_mlc.c (GC_debug_strdup, GC_debug_strndup): Cast result of
GC_debug_malloc_atomic() to char*.
* mallocx.c (GC_strdup, GC_strndup): Likewise.
* dbg_mlc.c (GC_debug_wcsdup): Cast result of GC_debug_malloc_atomic()
to wchar_t*.
* mallocx.c (GC_wcsdup): Likewise.
* dyn_load.c [MSWIN32 || MSWINCE || CYGWIN32]
(GC_register_dynamic_libraries): Cast p local variable to char*.
* os_dep.c (GC_register_data_segments): Likewise.
* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_finalized_disclaim): Cast masked
fc_word to struct GC_finalizer_closure* (instead of void*).
* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_finalized_malloc): Cast result of
GC_malloc_kind() to word*.
* typd_mlc.c (GC_malloc_explicitly_typed, GC_calloc_explicitly_typed):
Likewise.
* include/private/gc_priv.h (WARN): Cast away const qualifier for msg
(and the string literal).
* misc.c (GC_default_on_abort): Remove cast to void* for WRITE()
buf argument.
* misc.c (GC_new_free_list_inner): Cast result local variable to void**.
* misc.c (GC_new_free_list): Change type of result local variable from
void* to void**.
* pthread_support.c (GC_start_rtn_prepare_thread): Cast arg to
struct start_info*.
* win32_threads.c [GC_PTHREADS] (GC_pthread_start_inner): Likewise.
* reclaim.c (GC_print_free_list): Replace ptr_t flh to void *flh_next
local variable; remove redundant casts.
* tools/if_mach.c (EXECV_ARGV_T): New macro; add comment.
* tools/if_not_there.c (EXECV_ARGV_T): Likewise.
* tools/if_mach.c (main): Use EXECV_ARGV_T instead of void* for
execvp() argument.
* tools/if_not_there.c (main): Likewise.
* typd_mlc.c (LeafDescriptor, ComplexArrayDescriptor,
SequenceDescriptor): Move struct definition out of union
ComplexDescriptor.
* typd_mlc.c (GC_add_ext_descriptor): Rename "new" local variable to
newExtD.
* win32_threads.c (GC_CreateThread, GC_beginthreadex): Cast result
of GC_malloc_uncollectable() to thread_args*.
* win32_threads.c [PARALLEL_MARK && !MSWINCE && __cplusplus]
(GC_thr_init): Do not cast GetProcessAffinityMask() arguments to void*.
  • Loading branch information
ivmai committed Feb 16, 2018
1 parent c59a2ec commit a825a2d
Show file tree
Hide file tree
Showing 24 changed files with 192 additions and 152 deletions.
18 changes: 10 additions & 8 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ STATIC GC_bool GC_need_full_gc = FALSE;
STATIC word GC_used_heap_size_after_full = 0;

/* GC_copyright symbol is externally visible. */
char * const GC_copyright[] =
const char * const GC_copyright[] =
{"Copyright 1988,1989 Hans-J. Boehm and Alan J. Demers ",
"Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved. ",
"Copyright (c) 1996-1998 by Silicon Graphics. All rights reserved. ",
Expand Down Expand Up @@ -817,7 +817,7 @@ GC_INNER void GC_set_fl_marks(ptr_t q)
++hhdr -> hb_n_marks;
}

q = obj_link(q);
q = (ptr_t)obj_link(q);
if (q == NULL)
break;

Expand Down Expand Up @@ -905,7 +905,7 @@ STATIC void GC_clear_fl_marks(ptr_t q)
}
GC_bytes_found -= sz;

q = obj_link(q);
q = (ptr_t)obj_link(q);
if (q == NULL)
break;

Expand Down Expand Up @@ -976,8 +976,9 @@ STATIC void GC_finish_collection(void)

for (kind = 0; kind < GC_n_kinds; kind++) {
for (size = 1; size <= MAXOBJGRANULES; size++) {
q = GC_obj_kinds[kind].ok_freelist[size];
if (q != 0) GC_set_fl_marks(q);
q = (ptr_t)GC_obj_kinds[kind].ok_freelist[size];
if (q != NULL)
GC_set_fl_marks(q);
}
}
GC_start_reclaim(TRUE);
Expand Down Expand Up @@ -1018,8 +1019,9 @@ STATIC void GC_finish_collection(void)

for (kind = 0; kind < GC_n_kinds; kind++) {
for (size = 1; size <= MAXOBJGRANULES; size++) {
q = GC_obj_kinds[kind].ok_freelist[size];
if (q != 0) GC_clear_fl_marks(q);
q = (ptr_t)GC_obj_kinds[kind].ok_freelist[size];
if (q != NULL)
GC_clear_fl_marks(q);
}
}
}
Expand Down Expand Up @@ -1496,5 +1498,5 @@ GC_INNER ptr_t GC_allocobj(size_t gran, int kind)
/* Successful allocation; reset failure count. */
GC_fail_count = 0;

return(*flh);
return (ptr_t)(*flh);
}
2 changes: 1 addition & 1 deletion backgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static void add_back_edges(ptr_t p, size_t n_bytes, word gc_descr)
FIXUP_POINTER(current);
if (current >= (word)GC_least_plausible_heap_addr &&
current <= (word)GC_greatest_plausible_heap_addr) {
ptr_t target = GC_base((void *)current);
ptr_t target = (ptr_t)GC_base((void *)current);
if (0 != target) {
add_edge(p, target);
}
Expand Down
8 changes: 4 additions & 4 deletions blacklst.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ STATIC void GC_clear_bl(word *);

GC_INNER void GC_default_print_heap_obj_proc(ptr_t p)
{
ptr_t base = GC_base(p);
ptr_t base = (ptr_t)GC_base(p);
int kind = HDR(base)->hb_obj_kind;

GC_err_printf("object at %p of appr. %lu bytes (%s)\n",
Expand All @@ -71,7 +71,7 @@ GC_INNER void (*GC_print_heap_obj)(ptr_t p) = GC_default_print_heap_obj_proc;
STATIC void GC_print_blacklisted_ptr(word p, ptr_t source,
const char *kind_str)
{
ptr_t base = GC_base(source);
ptr_t base = (ptr_t)GC_base(source);

if (0 == base) {
GC_err_printf("Black listing (%s) %p referenced from %p in %s\n",
Expand Down Expand Up @@ -125,9 +125,9 @@ STATIC void GC_clear_bl(word *doomed)
BZERO(doomed, sizeof(page_hash_table));
}

STATIC void GC_copy_bl(word *old, word *new)
STATIC void GC_copy_bl(word *old, word *dest)
{
BCOPY(old, new, sizeof(page_hash_table));
BCOPY(old, dest, sizeof(page_hash_table));
}

static word total_stack_black_listed(void);
Expand Down
68 changes: 34 additions & 34 deletions dbg_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
}
}
# endif
bp_base = GC_base(bp);
if (0 == bp_base) {
bp_base = (ptr_t)GC_base(bp);
if (NULL == bp_base) {
*base_p = bp;
*offset_p = 0;
return GC_REFD_FROM_ROOT;
Expand Down Expand Up @@ -191,8 +191,8 @@
ptr_t base;
do {
result = GC_generate_random_heap_address();
base = GC_base(result);
} while (base == 0 || !GC_is_marked(base));
base = (ptr_t)GC_base(result);
} while (NULL == base || !GC_is_marked(base));
return result;
}

Expand Down Expand Up @@ -269,13 +269,13 @@

/* Store debugging info into p. Return displaced pointer. */
/* This version assumes we do hold the allocation lock. */
STATIC ptr_t GC_store_debug_info_inner(ptr_t p, word sz GC_ATTR_UNUSED,
STATIC void *GC_store_debug_info_inner(void *p, word sz GC_ATTR_UNUSED,
const char *string, int linenum)
{
word * result = (word *)((oh *)p + 1);

GC_ASSERT(GC_size(p) >= sizeof(oh) + sz);
GC_ASSERT(!(SMALL_OBJ(sz) && CROSSES_HBLK(p, sz)));
GC_ASSERT(!(SMALL_OBJ(sz) && CROSSES_HBLK((ptr_t)p, sz)));
# ifdef KEEP_BACK_PTRS
((oh *)p) -> oh_back_ptr = HIDE_BACK_PTR(NOT_MARKED);
# endif
Expand All @@ -290,7 +290,7 @@ STATIC ptr_t GC_store_debug_info_inner(ptr_t p, word sz GC_ATTR_UNUSED,
((word *)p)[BYTES_TO_WORDS(GC_size(p))-1] =
result[SIMPLE_ROUNDED_UP_WORDS(sz)] = END_FLAG ^ (word)result;
# endif
return((ptr_t)result);
return result;
}

GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *string,
Expand All @@ -300,7 +300,7 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *string,
DCL_LOCK_STATE;

LOCK();
result = GC_store_debug_info_inner(p, sz, string, linenum);
result = (ptr_t)GC_store_debug_info_inner(p, sz, string, linenum);
UNLOCK();
return result;
}
Expand Down Expand Up @@ -356,7 +356,7 @@ STATIC void GC_print_obj(ptr_t p)
ptr_t q;
hdr * hhdr;
int kind;
char *kind_str;
const char *kind_str;
char buffer[GC_TYPE_DESCR_LEN + 1];

GC_ASSERT(I_DONT_HOLD_LOCK());
Expand Down Expand Up @@ -433,7 +433,7 @@ STATIC void GC_debug_print_heap_obj_proc(ptr_t p)
/* Use GC_err_printf and friends to print a description of the object */
/* whose client-visible address is p, and which was smashed at */
/* clobbered_addr. */
STATIC void GC_print_smashed_obj(const char *msg, ptr_t p,
STATIC void GC_print_smashed_obj(const char *msg, void *p,
ptr_t clobbered_addr)
{
oh * ohdr = (oh *)GC_base(p);
Expand All @@ -446,11 +446,11 @@ STATIC void GC_debug_print_heap_obj_proc(ptr_t p)
|| ohdr -> oh_string == 0) {
GC_err_printf(
"%s %p in or near object at %p(<smashed>, appr. sz = %lu)\n",
msg, (void *)clobbered_addr, (void *)p,
msg, (void *)clobbered_addr, p,
(unsigned long)(GC_size((ptr_t)ohdr) - DEBUG_BYTES));
} else {
GC_err_printf("%s %p in or near object at %p (%s:%d, sz=%lu)\n",
msg, (void *)clobbered_addr, (void *)p,
msg, (void *)clobbered_addr, p,
(word)(ohdr -> oh_string) < HBLKSIZE ? "(smashed string)" :
ohdr -> oh_string[0] == '\0' ? "EMPTY(smashed?)" :
ohdr -> oh_string,
Expand Down Expand Up @@ -550,7 +550,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc(size_t lb,
GC_start_debugging();
}
ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, i));
return GC_store_debug_info((ptr_t)result, (word)lb, s, i);
}

GC_API GC_ATTR_MALLOC void * GC_CALL
Expand All @@ -567,7 +567,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL
GC_start_debugging();
}
ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, i));
return GC_store_debug_info((ptr_t)result, (word)lb, s, i);
}

GC_API GC_ATTR_MALLOC void * GC_CALL
Expand All @@ -585,7 +585,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL
GC_start_debugging();
}
ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, i));
return GC_store_debug_info((ptr_t)result, (word)lb, s, i);
}

STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS)
Expand All @@ -602,7 +602,7 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS)
GC_start_debugging();
}
ADD_CALL_CHAIN(result, ra);
return GC_store_debug_info(result, (word)lb, s, i);
return GC_store_debug_info((ptr_t)result, (word)lb, s, i);
}

#ifdef DBG_HDRS_ALL
Expand Down Expand Up @@ -662,7 +662,7 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS)
GC_start_debugging();
}
ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, i));
return GC_store_debug_info((ptr_t)result, (word)lb, s, i);
}

GC_API void GC_CALL GC_debug_change_stubborn(const void *p)
Expand Down Expand Up @@ -725,7 +725,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc_atomic(size_t lb,
GC_start_debugging();
}
ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, i));
return GC_store_debug_info((ptr_t)result, (word)lb, s, i);
}

GC_API GC_ATTR_MALLOC char * GC_CALL GC_debug_strdup(const char *str,
Expand All @@ -740,7 +740,7 @@ GC_API GC_ATTR_MALLOC char * GC_CALL GC_debug_strdup(const char *str,
}

lb = strlen(str) + 1;
copy = GC_debug_malloc_atomic(lb, OPT_RA s, i);
copy = (char *)GC_debug_malloc_atomic(lb, OPT_RA s, i);
if (copy == NULL) {
# ifndef MSWINCE
errno = ENOMEM;
Expand All @@ -758,7 +758,7 @@ GC_API GC_ATTR_MALLOC char * GC_CALL GC_debug_strndup(const char *str,
size_t len = strlen(str); /* str is expected to be non-NULL */
if (len > size)
len = size;
copy = GC_debug_malloc_atomic(len + 1, OPT_RA s, i);
copy = (char *)GC_debug_malloc_atomic(len + 1, OPT_RA s, i);
if (copy == NULL) {
# ifndef MSWINCE
errno = ENOMEM;
Expand All @@ -778,7 +778,7 @@ GC_API GC_ATTR_MALLOC char * GC_CALL GC_debug_strndup(const char *str,
GC_EXTRA_PARAMS)
{
size_t lb = (wcslen(str) + 1) * sizeof(wchar_t);
wchar_t *copy = GC_debug_malloc_atomic(lb, OPT_RA s, i);
wchar_t *copy = (wchar_t *)GC_debug_malloc_atomic(lb, OPT_RA s, i);
if (copy == NULL) {
# ifndef MSWINCE
errno = ENOMEM;
Expand All @@ -805,7 +805,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc_uncollectable(size_t lb,
GC_start_debugging();
}
ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, i));
return GC_store_debug_info((ptr_t)result, (word)lb, s, i);
}

#ifdef GC_ATOMIC_UNCOLLECTABLE
Expand All @@ -824,7 +824,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc_uncollectable(size_t lb,
GC_start_debugging();
}
ADD_CALL_CHAIN(result, ra);
return (GC_store_debug_info(result, (word)lb, s, i));
return GC_store_debug_info((ptr_t)result, (word)lb, s, i);
}
#endif /* GC_ATOMIC_UNCOLLECTABLE */

Expand All @@ -841,8 +841,8 @@ GC_API void GC_CALL GC_debug_free(void * p)
ptr_t base;
if (0 == p) return;

base = GC_base(p);
if (base == 0) {
base = (ptr_t)GC_base(p);
if (NULL == base) {
# if defined(REDIRECT_MALLOC) \
&& ((defined(NEED_CALLINFO) && defined(GC_HAVE_BUILTIN_BACKTRACE)) \
|| defined(GC_LINUX_THREADS) || defined(GC_SOLARIS_THREADS) \
Expand Down Expand Up @@ -909,7 +909,7 @@ GC_API void GC_CALL GC_debug_free(void * p)
/* Used internally; we assume it's called correctly. */
GC_INNER void GC_debug_free_inner(void * p)
{
ptr_t base = GC_base(p);
ptr_t base = (ptr_t)GC_base(p);
GC_ASSERT((ptr_t)p - (ptr_t)base == sizeof(oh));
# ifdef LINT2
if (!base) ABORT("Invalid GC_debug_free_inner argument");
Expand Down Expand Up @@ -1185,8 +1185,8 @@ GC_API void GC_CALL GC_debug_register_finalizer(void * obj,
{
GC_finalization_proc my_old_fn = OFN_UNSET;
void * my_old_cd;
ptr_t base = GC_base(obj);
if (0 == base) {
ptr_t base = (ptr_t)GC_base(obj);
if (NULL == base) {
/* We won't collect it, hence finalizer wouldn't be run. */
if (ocd) *ocd = 0;
if (ofn) *ofn = 0;
Expand Down Expand Up @@ -1214,8 +1214,8 @@ GC_API void GC_CALL GC_debug_register_finalizer_no_order
{
GC_finalization_proc my_old_fn = OFN_UNSET;
void * my_old_cd;
ptr_t base = GC_base(obj);
if (0 == base) {
ptr_t base = (ptr_t)GC_base(obj);
if (NULL == base) {
/* We won't collect it, hence finalizer wouldn't be run. */
if (ocd) *ocd = 0;
if (ofn) *ofn = 0;
Expand Down Expand Up @@ -1243,8 +1243,8 @@ GC_API void GC_CALL GC_debug_register_finalizer_unreachable
{
GC_finalization_proc my_old_fn = OFN_UNSET;
void * my_old_cd;
ptr_t base = GC_base(obj);
if (0 == base) {
ptr_t base = (ptr_t)GC_base(obj);
if (NULL == base) {
/* We won't collect it, hence finalizer wouldn't be run. */
if (ocd) *ocd = 0;
if (ofn) *ofn = 0;
Expand Down Expand Up @@ -1272,8 +1272,8 @@ GC_API void GC_CALL GC_debug_register_finalizer_ignore_self
{
GC_finalization_proc my_old_fn = OFN_UNSET;
void * my_old_cd;
ptr_t base = GC_base(obj);
if (0 == base) {
ptr_t base = (ptr_t)GC_base(obj);
if (NULL == base) {
/* We won't collect it, hence finalizer wouldn't be run. */
if (ocd) *ocd = 0;
if (ofn) *ofn = 0;
Expand Down
5 changes: 3 additions & 2 deletions dyn_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,8 @@ GC_INNER void GC_register_dynamic_libraries(void)
# ifdef MSWIN32
if (GC_no_win32_dlls) return;
# endif
base = limit = p = GC_sysinfo.lpMinimumApplicationAddress;
p = GC_sysinfo.lpMinimumApplicationAddress;
base = limit = (char *)p;
while ((word)p < (word)GC_sysinfo.lpMaximumApplicationAddress) {
size_t result = VirtualQuery(p, &buf, sizeof(buf));

Expand Down Expand Up @@ -1033,7 +1034,7 @@ GC_INNER void GC_register_dynamic_libraries(void)
# endif
if ((char *)p != limit) {
GC_cond_add_roots(base, limit);
base = p;
base = (char *)p;
}
limit = new_limit;
}
Expand Down
Loading

0 comments on commit a825a2d

Please sign in to comment.