diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-04-30 19:00:14 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-05-01 00:22:50 +0300 |
commit | d833880a0f3cab314cd1f06a1a1bec5024cfdacd (patch) | |
tree | 2946a5fa0779341719b677e08d97c53626646610 | |
parent | dad61d707e943043174e171cc1b2b6a1497a0d36 (diff) | |
download | bdwgc-d833880a0f3cab314cd1f06a1a1bec5024cfdacd.tar.gz |
Remove extra parentheses in return statement
(refactoring)
Also, replace 0 to NULL where appropriate.
* allchblk.c (setup_header, GC_get_first_part, GC_allochblk_nth):
Remove outermost parentheses in the expression of return statement.
* alloc.c (GC_never_stop_func, GC_timeout_stop_func,
GC_adj_bytes_allocd, GC_try_to_collect_inner, GC_collect_a_little,
GC_stopped_mark, GC_try_to_collect_general, GC_expand_hp_inner,
GC_collect_or_expand, GC_allocobj): Likewise.
* blacklst.c (GC_is_black_listed, GC_number_stack_black_listed,
total_stack_black_listed): Likewise.
* checksums.c (GC_checksum): Likewise.
* cord/cordbscs.c (CORD_cat_char_star, CORD_cat, CORD_len,
CORD_index_access_fn, CORD_apply_access_fn, CORD_substr_checked,
CORD_substr, CORD_iter5, CORD_iter, CORD_riter4, CORD_riter,
CORD_concat_forest, CORD_balance, CORD__pos_fetch, CORD__prev,
CORD_prev, CORD_pos_to_cord, CORD_pos_valid): Likewise.
* cord/cordprnt.c (extract_conv_spec, CORD_vsprintf, CORD_sprintf,
CORD_fprintf, CORD_vfprintf, CORD_printf, CORD_vprintf): Likewise.
* cord/cordxtra.c (CORD_cat_char, CORD_catn, CORD_fill_proc,
CORD_batched_fill_proc, CORD_cmp, CORD_ncmp, CORD_to_char_star,
CORD_from_char_star, CORD_to_const_char_star, CORD_fetch,
CORD_put_proc, CORD_batched_put_proc, CORD_put, CORD_chr_proc,
CORD_rchr_proc, CORD_batched_chr_proc, CORD_chr, CORD_rchr, CORD_str,
CORD_from_file_eager, CORD_lf_func, CORD_from_file_lazy_inner,
CORD_from_file_lazy, CORD_from_file): Likewise.
* cord/tests/cordtest.c (test_fn, id_cord_fn, test_basics): Likewise.
* cord/tests/de.c (line_pos, add_hist, retrieve_line, beep): Likewise.
* cord/tests/de_win.c (WinMain, plain_chars, control_chars, WndProc):
Likewise.
* dbg_mlc.c (store_debug_info, GC_debug_generic_malloc,
GC_debug_generic_malloc, GC_debug_realloc, GC_make_closure): Likewise.
* dyn_load.c (GC_FirstDLOpenedLinkMap): Likewise.
* extra/real_malloc.c (real_malloc): Likewise.
* finalize.c (GC_register_disappearing_link,
GC_unregister_disappearing_link): Likewise.
* gc_dlopen.c (dlopen): Likewise.
* gcj_mlc.c (maybe_finalize, GC_debug_gcj_malloc,
GC_gcj_malloc_ignore_off_page): Likewise.
* headers.c (GC_find_header, alloc_hdr, get_index, GC_install_header,
GC_next_block, GC_prev_block): Likewise.
* malloc.c (GC_generic_malloc): Likewise.
* mallocx.c (GC_realloc, GC_generic_malloc_ignore_off_page): Likewise.
* mark.c (GC_collection_in_progress, GC_mark_some,
GC_signal_mark_stack_overflow, GC_block_was_dirty,
GC_push_next_marked, GC_push_next_marked_dirty,
GC_push_next_marked_uncollectable): Likewise.
* mark_rts.c (GC_is_static_root, rt_hash, GC_roots_present,
GC_remove_tmp_roots, GC_approx_sp): Likewise.
* misc.c (GC_default_oom_fn, GC_clear_stack_inner, GC_base,
GC_write, GC_get_warn_proc, GC_call_with_alloc_lock): Likewise.
* new_hblk.c (GC_build_fl_clear2, GC_build_fl_clear4, GC_build_fl2,
GC_build_fl4, GC_build_fl): Likewise.
* obj_map.c (GC_register_displacement_inner): Likewise.
* os_dep.c (GC_find_limit_openbsd, GC_skip_hole_openbsd,
GC_get_writable_length, GC_get_writable_length, GC_get_main_stack_base,
GC_FreeBSDGetDataStart, GC_unix_mmap_get_mem, GC_unix_sbrk_get_mem,
os2_alloc, GC_wince_get_mem, GC_win32_get_mem, GC_push_thread_stack,
GC_push_old_obj, GC_write_fault_handler, catch_exception_raise_state,
catch_exception_raise_state_identity): Likewise.
* pthread_support.c (GC_new_thread, GC_lookup_thread, GC_get_nprocs,
pthread_sigmask, pthread_create): Likewise.
* ptr_chck.c (GC_same_obj, GC_default_is_visible_print_proc,
GC_default_is_valid_displacement_print_proc, GC_is_visible,
GC_pre_incr, GC_post_incr): Likewise.
* reclaim.c (GC_block_empty, GC_reclaim_uninit, GC_n_set_marks,
GC_reclaim_all): Likewise.
* tests/cpp.cc (main): Likewise.
* tests/gctest.c (fake_gcj_mark_proc, reverse1, reverse, ints,
gcj_reverse1, gcj_reverse, gcj_ints, uncollectable_ints, mktree,
alloc8bytes, main, test): Likewise.
* tools/if_mach.c (main): Likewise.
* tools/if_not_there.c (main): Likewise.
* tools/setjmp_t.c (getpagesize, main, g): Likewise.
* typd_mlc.c (GC_add_ext_descriptor, GC_add_ext_descriptor,
GC_double_descr, GC_make_array_descriptor,
GC_make_sequence_descriptor, GC_typed_mark_proc, GC_descr_obj_size,
GC_push_complex_descriptor, GC_array_mark_proc, GC_make_descriptor,
GC_calloc_explicitly_typed): Likewise.
* win32_threads.c (GC_new_thread, GC_lookup_thread_inner,
GC_get_stack_min, GC_pthread_create, GC_pthread_start_inner): Likewise.
* allchblk.c (GC_get_first_part, GC_allochblk_nth): Replace 0 to NULL
where appropriate.
* alloc.c (GC_allocobj): Likewise.
* blacklst.c (GC_is_black_listed): Likewise.
* cord/cordbscs.c (CORD_from_fn_inner, CORD_substr_checked): Likewise.
* cord/cordxtra.c (CORD_cat_char, CORD_to_char_star,
CORD_from_char_star, CORD_lf_func, CORD_from_file_lazy_inner):
Likewise.
* dbg_mlc.c (store_debug_info, GC_debug_generic_malloc,
GC_debug_generic_malloc): Likewise.
* dyn_load.c (GC_FirstDLOpenedLinkMap): Likewise.
* gcj_mlc.c (GC_debug_gcj_malloc): Likewise.
* headers.c (GC_next_block, GC_prev_block): Likewise.
* malloc.c (GC_generic_malloc, strdup): Likewise.
* mallocx.c (GC_realloc): Likewise.
* misc.c (GC_default_oom_fn, GC_base): Likewise.
* os_dep.c (GC_get_main_stack_base, os2_alloc, GC_win32_get_mem):
Likewise.
* pthread_support.c (GC_new_thread, GC_lookup_thread): Likewise.
* ptr_chck.c (GC_same_obj, GC_is_visible,
GC_default_is_valid_displacement_print_proc): Likewise.
* tests/gctest.c (mktree): Likewise.
* typd_mlc.c (GC_make_array_descriptor, GC_push_complex_descriptor,
GC_array_mark_proc, GC_calloc_explicitly_typed): Likewise.
* win32_threads.c (GC_new_thread, GC_lookup_thread_inner): Likewise.
* alloc.c (GC_never_stop_func, GC_timeout_stop_func): Replace 0 and 1
(in return statement) to FALSE and TRUE, respectively.
* include/private/gcconfig.h: Remove outermost parentheses in the
expression of return statement in comment.
-rw-r--r-- | allchblk.c | 14 | ||||
-rw-r--r-- | alloc.c | 50 | ||||
-rw-r--r-- | blacklst.c | 12 | ||||
-rw-r--r-- | checksums.c | 2 | ||||
-rw-r--r-- | cord/cordbscs.c | 135 | ||||
-rw-r--r-- | cord/cordprnt.c | 28 | ||||
-rw-r--r-- | cord/cordxtra.c | 158 | ||||
-rw-r--r-- | cord/tests/cordtest.c | 8 | ||||
-rw-r--r-- | cord/tests/de.c | 12 | ||||
-rw-r--r-- | cord/tests/de_win.c | 28 | ||||
-rw-r--r-- | dbg_mlc.c | 20 | ||||
-rw-r--r-- | dyn_load.c | 6 | ||||
-rw-r--r-- | extra/real_malloc.c | 2 | ||||
-rw-r--r-- | finalize.c | 6 | ||||
-rw-r--r-- | gc_dlopen.c | 2 | ||||
-rw-r--r-- | gcj_mlc.c | 12 | ||||
-rw-r--r-- | headers.c | 41 | ||||
-rw-r--r-- | include/private/gcconfig.h | 2 | ||||
-rw-r--r-- | malloc.c | 12 | ||||
-rw-r--r-- | mallocx.c | 8 | ||||
-rw-r--r-- | mark.c | 31 | ||||
-rw-r--r-- | mark_rts.c | 23 | ||||
-rw-r--r-- | misc.c | 33 | ||||
-rw-r--r-- | new_hblk.c | 10 | ||||
-rw-r--r-- | obj_map.c | 6 | ||||
-rw-r--r-- | os_dep.c | 52 | ||||
-rw-r--r-- | pthread_support.c | 20 | ||||
-rw-r--r-- | ptr_chck.c | 54 | ||||
-rw-r--r-- | reclaim.c | 10 | ||||
-rw-r--r-- | tests/cpp.cc | 6 | ||||
-rw-r--r-- | tests/gctest.c | 44 | ||||
-rw-r--r-- | tools/if_mach.c | 6 | ||||
-rw-r--r-- | tools/if_not_there.c | 10 | ||||
-rw-r--r-- | tools/setjmp_t.c | 6 | ||||
-rw-r--r-- | typd_mlc.c | 67 | ||||
-rw-r--r-- | win32_threads.c | 15 |
36 files changed, 456 insertions, 495 deletions
@@ -294,7 +294,7 @@ static GC_bool setup_header(hdr * hhdr, struct hblk *block, size_t byte_sz, GC_clear_hdr_marks(hhdr); hhdr -> hb_last_reclaimed = (unsigned short)GC_gc_no; - return(TRUE); + return TRUE; } /* Remove hhdr from the free list (it is assumed to specified by index). */ @@ -594,10 +594,10 @@ STATIC struct hblk * GC_get_first_part(struct hblk *h, hdr *hhdr, if (total_size == bytes) return h; rest = (struct hblk *)((word)h + bytes); rest_hdr = GC_install_header(rest); - if (0 == rest_hdr) { + if (NULL == rest_hdr) { /* FIXME: This is likely to be very bad news ... */ WARN("Header allocation failed: dropping block\n", 0); - return(0); + return NULL; } rest_hdr -> hb_sz = total_size - bytes; rest_hdr -> hb_flags = 0; @@ -890,16 +890,16 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, int may_split) } } - if (0 == hbp) return 0; + if (NULL == hbp) return NULL; /* Add it to map of valid blocks */ - if (!GC_install_counts(hbp, (word)size_needed)) return(0); + if (!GC_install_counts(hbp, (word)size_needed)) return NULL; /* This leaks memory under very rare conditions. */ /* Set up header */ if (!setup_header(hhdr, hbp, sz, kind, flags)) { GC_remove_counts(hbp, (word)size_needed); - return(0); /* ditto */ + return NULL; /* ditto */ } # ifndef GC_DISABLE_INCREMENTAL /* Notify virtual dirty bit implementation that we are about to */ @@ -917,7 +917,7 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, int may_split) GC_large_free_bytes -= size_needed; GC_ASSERT(IS_MAPPED(hhdr)); - return( hbp ); + return hbp; } /* @@ -171,7 +171,7 @@ GC_API unsigned GC_CALL GC_get_version(void) GC_INNER int GC_CALLBACK GC_never_stop_func(void) { - return(0); + return FALSE; } #if defined(GC_TIME_LIMIT) && !defined(CPPCHECK) @@ -251,11 +251,11 @@ GC_API GC_stop_func GC_CALL GC_get_stop_func(void) static unsigned count = 0; unsigned long time_diff, nsec_diff; - if ((*GC_default_stop_func)()) - return(1); + if (GC_default_stop_func()) + return TRUE; if (GC_time_limit == GC_TIME_UNLIMITED || (count++ & 3) != 0) - return 0; + return FALSE; GET_TIME(current_time); time_diff = MS_TIME_DIFF(current_time,GC_start_time); @@ -268,9 +268,10 @@ GC_API GC_stop_func GC_CALL GC_get_stop_func(void) GC_COND_LOG_PRINTF("Abandoning stopped marking after %lu ms %lu ns" " (attempt %d)\n", time_diff, nsec_diff, GC_n_attempts); - return 1; + return TRUE; } - return(0); + + return FALSE; } #endif /* !GC_DISABLE_INCREMENTAL */ @@ -372,10 +373,9 @@ STATIC word GC_adj_bytes_allocd(void) /* to collect too infrequently, since that would inhibit */ /* coalescing of free storage blocks. */ /* This also makes us partially robust against client bugs. */ - return(GC_bytes_allocd >> 3); - } else { - return(result); + result = (signed_word)(GC_bytes_allocd >> 3); } + return (word)result; } @@ -560,7 +560,7 @@ GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func stop_func) while(GC_collection_in_progress()) { if ((*stop_func)()) { /* TODO: Notify GC_EVENT_ABANDON */ - return(FALSE); + return FALSE; } ENTER_GC(); GC_collect_a_little_inner(1); @@ -591,7 +591,7 @@ GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func stop_func) && !GC_reclaim_all(stop_func, FALSE)) { /* Aborted. So far everything is still consistent. */ /* TODO: Notify GC_EVENT_ABANDON */ - return(FALSE); + return FALSE; } GC_invalidate_mark_state(); /* Flush mark stack. */ GC_clear_marks(); @@ -609,7 +609,7 @@ GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func stop_func) } /* else we claim the world is already still consistent. We'll */ /* finish incrementally. */ /* TODO: Notify GC_EVENT_ABANDON */ - return(FALSE); + return FALSE; } GC_finish_collection(); # ifndef NO_CLOCK @@ -636,7 +636,7 @@ GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func stop_func) # endif if (GC_on_collection_event) GC_on_collection_event(GC_EVENT_END); - return(TRUE); + return TRUE; } /* @@ -758,7 +758,7 @@ GC_API int GC_CALL GC_collect_a_little(void) result = (int)GC_collection_in_progress(); UNLOCK(); if (!result && GC_debugging_started) GC_print_all_smashed(); - return(result); + return result; } #ifndef NO_CLOCK @@ -944,7 +944,7 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func) total_time / divisor); } # endif - return(TRUE); + return TRUE; } /* Set all mark bits for the free list whose first entry is q */ @@ -1280,7 +1280,7 @@ STATIC GC_bool GC_try_to_collect_general(GC_stop_func stop_func, if (GC_debugging_started) GC_print_all_smashed(); GC_INVOKE_FINALIZERS(); } - return(result); + return result; } /* Externally callable routines to invoke full, stop-the-world collection. */ @@ -1518,13 +1518,13 @@ GC_INNER GC_bool GC_expand_hp_inner(word n) && (GC_max_heapsize < (word)bytes || GC_heapsize > GC_max_heapsize - (word)bytes)) { /* Exceeded self-imposed limit */ - return(FALSE); + return FALSE; } space = GET_MEM(bytes); if (EXPECT(NULL == space, FALSE)) { WARN("Failed to expand heap by %" WARN_PRIdPTR " bytes\n", (word)bytes); - return(FALSE); + return FALSE; } GC_add_to_our_memory((ptr_t)space, bytes); GC_last_heap_growth_gc_no = GC_gc_no; @@ -1557,7 +1557,7 @@ GC_INNER GC_bool GC_expand_hp_inner(word n) if (GC_on_heap_resize) (*GC_on_heap_resize)(GC_heapsize); - return(TRUE); + return TRUE; } /* Really returns a bool, but it's externally visible, so that's clumsy. */ @@ -1645,7 +1645,7 @@ GC_INNER GC_bool GC_collect_or_expand(word needed_blocks, last_fo_entries = GC_fo_entries; last_bytes_finalized = GC_bytes_finalized; RESTORE_CANCEL(cancel_state); - return(TRUE); + return TRUE; } } @@ -1705,13 +1705,13 @@ GC_INNER GC_bool GC_collect_or_expand(word needed_blocks, " Returning NULL!\n", (GC_heapsize - GC_unmapped_bytes) >> 20); # endif RESTORE_CANCEL(cancel_state); - return(FALSE); + return FALSE; } } else if (GC_fail_count) { GC_COND_LOG_PRINTF("Memory available again...\n"); } RESTORE_CANCEL(cancel_state); - return(TRUE); + return TRUE; } /* @@ -1726,9 +1726,9 @@ GC_INNER ptr_t GC_allocobj(size_t gran, int kind) GC_bool retry = FALSE; GC_ASSERT(I_HOLD_LOCK()); - if (gran == 0) return(0); + if (0 == gran) return NULL; - while (*flh == 0) { + while (NULL == *flh) { ENTER_GC(); # ifndef GC_DISABLE_INCREMENTAL if (GC_incremental && GC_time_limit != GC_TIME_UNLIMITED) { @@ -1760,7 +1760,7 @@ GC_INNER ptr_t GC_allocobj(size_t gran, int kind) } else { if (!GC_collect_or_expand(1, FALSE, retry)) { EXIT_GC(); - return(0); + return NULL; } retry = TRUE; } @@ -248,7 +248,7 @@ struct hblk * GC_is_black_listed(struct hblk *h, word len) if (!GC_all_interior_pointers && (get_pht_entry_from_index(GC_old_normal_bl, index) || get_pht_entry_from_index(GC_incomplete_normal_bl, index))) { - return (h+1); + return h + 1; } nblocks = divHBLKSZ(len); @@ -260,14 +260,14 @@ struct hblk * GC_is_black_listed(struct hblk *h, word len) } else { if (get_pht_entry_from_index(GC_old_stack_bl, index) || get_pht_entry_from_index(GC_incomplete_stack_bl, index)) { - return(h+i+1); + return h + (i+1); } i++; } if (i >= nblocks) break; - index = PHT_HASH((word)(h+i)); + index = PHT_HASH((word)(h + i)); } - return(0); + return NULL; } /* Return the number of blacklisted blocks in a given range. */ @@ -284,7 +284,7 @@ STATIC word GC_number_stack_black_listed(struct hblk *start, if (get_pht_entry_from_index(GC_old_stack_bl, index)) result++; } - return(result); + return result; } /* Return the total number of (stack) black-listed bytes. */ @@ -299,5 +299,5 @@ static word total_stack_black_listed(void) total += GC_number_stack_black_listed(start, endp1); } - return(total * HBLKSIZE); + return total * HBLKSIZE; } diff --git a/checksums.c b/checksums.c index 28e40a88..7fe0e68d 100644 --- a/checksums.c +++ b/checksums.c @@ -67,7 +67,7 @@ STATIC word GC_checksum(struct hblk *h) while ((word)p < (word)lim) { result += *p++; } - return(result | 0x80000000 /* doesn't look like pointer */); + return result | 0x80000000; /* does not look like pointer */ } int GC_n_dirty_errors = 0; diff --git a/cord/cordbscs.c b/cord/cordbscs.c index 0f052a76..38325b8e 100644 --- a/cord/cordbscs.c +++ b/cord/cordbscs.c @@ -162,15 +162,15 @@ CORD CORD_cat_char_star(CORD x, const char * y, size_t leny) size_t lenx; int depth; - if (x == CORD_EMPTY) return(y); - if (leny == 0) return(x); + if (x == CORD_EMPTY) return y; + if (leny == 0) return x; if (CORD_IS_STRING(x)) { lenx = strlen(x); result_len = lenx + leny; if (result_len <= SHORT_LIMIT) { char * result = (char *)GC_MALLOC_ATOMIC(result_len + 1); - if (result == 0) OUT_OF_MEMORY; + if (NULL == result) OUT_OF_MEMORY; # ifdef LINT2 memcpy(result, x, lenx + 1); # else @@ -180,7 +180,7 @@ CORD CORD_cat_char_star(CORD x, const char * y, size_t leny) # endif memcpy(result + lenx, y, leny); result[result_len] = '\0'; - return((CORD) result); + return (CORD)result; } else { depth = 1; } @@ -241,9 +241,9 @@ CORD CORD_cat_char_star(CORD x, const char * y, size_t leny) GC_PTR_STORE_AND_DIRTY((void *)&result->right, y); GC_reachable_here(x); if (depth >= MAX_DEPTH) { - return(CORD_balance((CORD)result)); + return CORD_balance((CORD)result); } else { - return((CORD) result); + return (CORD)result; } } } @@ -255,10 +255,10 @@ CORD CORD_cat(CORD x, CORD y) int depth; size_t lenx; - if (x == CORD_EMPTY) return(y); - if (y == CORD_EMPTY) return(x); + if (x == CORD_EMPTY) return y; + if (y == CORD_EMPTY) return x; if (CORD_IS_STRING(y)) { - return(CORD_cat_char_star(x, y, strlen(y))); + return CORD_cat_char_star(x, y, strlen(y)); } else if (CORD_IS_STRING(x)) { lenx = strlen(x); depth = DEPTH(y) + 1; @@ -283,9 +283,9 @@ CORD CORD_cat(CORD x, CORD y) GC_PTR_STORE_AND_DIRTY((void *)&result->right, y); GC_reachable_here(x); if (depth >= MAX_DEPTH) { - return(CORD_balance((CORD)result)); + return CORD_balance((CORD)result); } else { - return((CORD) result); + return (CORD)result; } } } @@ -293,7 +293,7 @@ CORD CORD_cat(CORD x, CORD y) static CordRep *CORD_from_fn_inner(CORD_fn fn, void * client_data, size_t len) { - if (len == 0) return(0); + if (0 == len) return NULL; if (len <= SHORT_LIMIT) { char * result; size_t i; @@ -307,7 +307,7 @@ static CordRep *CORD_from_fn_inner(CORD_fn fn, void * client_data, size_t len) } result = (char *)GC_MALLOC_ATOMIC(len + 1); - if (result == 0) OUT_OF_MEMORY; + if (NULL == result) OUT_OF_MEMORY; memcpy(result, buf, len); result[len] = '\0'; return (CordRep *)result; @@ -333,11 +333,7 @@ CORD CORD_from_fn(CORD_fn fn, void * client_data, size_t len) size_t CORD_len(CORD x) { - if (x == 0) { - return(0); - } else { - return(GEN_LEN(x)); - } + return x == 0 ? 0 : GEN_LEN(x); } struct substr_args { @@ -349,7 +345,7 @@ char CORD_index_access_fn(size_t i, void * client_data) { struct substr_args *descr = (struct substr_args *)client_data; - return(((char *)(descr->sa_cord))[i + descr->sa_index]); + return ((char *)descr->sa_cord)[i + descr->sa_index]; } char CORD_apply_access_fn(size_t i, void * client_data) @@ -357,7 +353,7 @@ char CORD_apply_access_fn(size_t i, void * client_data) struct substr_args *descr = (struct substr_args *)client_data; struct Function * fn_cord = &(descr->sa_cord->function); - return((*(fn_cord->fn))(i + descr->sa_index, fn_cord->client_data)); + return fn_cord->fn(i + descr->sa_index, fn_cord->client_data); } /* A version of CORD_substr that simply returns a function node, thus */ @@ -388,14 +384,14 @@ CORD CORD_substr_checked(CORD x, size_t i, size_t n) { if (CORD_IS_STRING(x)) { if (n > SUBSTR_LIMIT) { - return(CORD_substr_closure(x, i, n, CORD_index_access_fn)); + return CORD_substr_closure(x, i, n, CORD_index_access_fn); } else { char * result = (char *)GC_MALLOC_ATOMIC(n + 1); - if (result == 0) OUT_OF_MEMORY; + if (NULL == result) OUT_OF_MEMORY; strncpy(result, x+i, n); result[n] = '\0'; - return(result); + return result; } } else if (IS_CONCATENATION(x)) { struct Concatenation * conc = &(((CordRep *)x) -> concatenation); @@ -403,11 +399,11 @@ CORD CORD_substr_checked(CORD x, size_t i, size_t n) size_t right_len = conc -> len - left_len; if (i >= left_len) { - if (n == right_len) return(conc -> right); - return(CORD_substr_checked(conc -> right, i - left_len, n)); + if (n == right_len) return conc -> right; + return CORD_substr_checked(conc -> right, i - left_len, n); } else if (i+n <= left_len) { - if (n == left_len) return(conc -> left); - return(CORD_substr_checked(conc -> left, i, n)); + if (n == left_len) return conc -> left; + return CORD_substr_checked(conc -> left, i, n); } else { /* Need at least one character from each side. */ CORD left_part; @@ -425,7 +421,7 @@ CORD CORD_substr_checked(CORD x, size_t i, size_t n) right_part = CORD_substr_checked(conc -> right, 0, n - left_part_len); } - return(CORD_cat(left_part, right_part)); + return CORD_cat(left_part, right_part); } } else /* function */ { if (n > SUBSTR_LIMIT) { @@ -435,11 +431,10 @@ CORD CORD_substr_checked(CORD x, size_t i, size_t n) struct substr_args *descr = (struct substr_args *)(f -> client_data); - return(CORD_substr_closure((CORD)descr->sa_cord, - i + descr->sa_index, - n, f -> fn)); + return CORD_substr_closure((CORD)descr->sa_cord, + i + descr->sa_index, n, f->fn); } else { - return(CORD_substr_closure(x, i, n, CORD_apply_access_fn)); + return CORD_substr_closure(x, i, n, CORD_apply_access_fn); } } else { char * result; @@ -453,15 +448,15 @@ CORD CORD_substr_checked(CORD x, size_t i, size_t n) char c = (*(f -> fn))(j, f -> client_data); if (c == '\0') { - return(CORD_substr_closure(x, i, n, CORD_apply_access_fn)); + return CORD_substr_closure(x, i, n, CORD_apply_access_fn); } *p++ = c; } result = (char *)GC_MALLOC_ATOMIC(n + 1); - if (result == 0) OUT_OF_MEMORY; + if (NULL == result) OUT_OF_MEMORY; memcpy(result, buf, n); result[n] = '\0'; - return(result); + return result; } } } @@ -470,28 +465,28 @@ CORD CORD_substr(CORD x, size_t i, size_t n) { size_t len = CORD_len(x); - if (i >= len || n == 0) return(0); + if (i >= len || 0 == n) return 0; if (i + n > len) n = len - i; - return(CORD_substr_checked(x, i, n)); + return CORD_substr_checked(x, i, n); } /* See cord.h for definition. We assume i is in range. */ int CORD_iter5(CORD x, size_t i, CORD_iter_fn f1, CORD_batched_iter_fn f2, void * client_data) { - if (x == 0) return(0); + if (0 == x) return 0; if (CORD_IS_STRING(x)) { const char *p = x+i; if (*p == '\0') ABORT("2nd arg to CORD_iter5 too big"); if (f2 != CORD_NO_FN) { - return((*f2)(p, client_data)); + return f2(p, client_data); } else { while (*p) { - if ((*f1)(*p, client_data)) return(1); + if (f1(*p, client_data)) return 1; p++; } - return(0); + return 0; } } else if (IS_CONCATENATION(x)) { struct Concatenation * conc = &(((CordRep *)x) -> concatenation); @@ -500,37 +495,37 @@ int CORD_iter5(CORD x, size_t i, CORD_iter_fn f1, size_t left_len = LEFT_LEN(conc); if (i >= left_len) { - return(CORD_iter5(conc -> right, i - left_len, f1, f2, - client_data)); + return CORD_iter5(conc -> right, i - left_len, f1, f2, + client_data); } } if (CORD_iter5(conc -> left, i, f1, f2, client_data)) { - return(1); + return 1; } - return(CORD_iter5(conc -> right, 0, f1, f2, client_data)); + return CORD_iter5(conc -> right, 0, f1, f2, client_data); } else /* function */ { struct Function * f = &(((CordRep *)x) -> function); size_t j; size_t lim = f -> len; for (j = i; j < lim; j++) { - if ((*f1)((*(f -> fn))(j, f -> client_data), client_data)) { - return(1); + if (f1(f->fn(j, f->client_data), client_data)) { + return 1; } } - return(0); + return 0; } } #undef CORD_iter int CORD_iter(CORD x, CORD_iter_fn f1, void * client_data) { - return(CORD_iter5(x, 0, f1, CORD_NO_FN, client_data)); + return CORD_iter5(x, 0, f1, CORD_NO_FN, client_data); } int CORD_riter4(CORD x, size_t i, CORD_iter_fn f1, void * client_data) { - if (x == 0) return(0); + if (0 == x) return 0; if (CORD_IS_STRING(x)) { const char *p = x + i; @@ -538,11 +533,10 @@ int CORD_riter4(CORD x, size_t i, CORD_iter_fn f1, void * client_data) char c = *p; if (c == '\0') ABORT("2nd arg to CORD_riter4 too big"); - if ((*f1)(c, client_data)) return(1); + if (f1(c, client_data)) return 1; if (p == x) break; p--; } - return(0); } else if (IS_CONCATENATION(x)) { struct Concatenation * conc = &(((CordRep *)x) -> concatenation); CORD left_part = conc -> left; @@ -550,30 +544,31 @@ int CORD_riter4(CORD x, size_t i, CORD_iter_fn f1, void * client_data) if (i >= left_len) { if (CORD_riter4(conc -> right, i - left_len, f1, client_data)) { - return(1); + return 1; } - return(CORD_riter4(left_part, left_len - 1, f1, client_data)); + return CORD_riter4(left_part, left_len - 1, f1, client_data); } else { - return(CORD_riter4(left_part, i, f1, client_data)); + return CORD_riter4(left_part, i, f1, client_data); } } else /* function */ { struct Function * f = &(((CordRep *)x) -> function); size_t j; for (j = i; ; j--) { - if ((*f1)((*(f -> fn))(j, f -> client_data), client_data)) { - return(1); + if (f1(f->fn(j, f->client_data), client_data)) { + return 1; } - if (j == 0) return(0); + if (0 == j) break; } } + return 0; } int CORD_riter(CORD x, CORD_iter_fn f1, void * client_data) { size_t len = CORD_len(x); - if (len == 0) return(0); - return(CORD_riter4(x, len - 1, f1, client_data)); + if (0 == len) return 0; + return CORD_riter4(x, len - 1, f1, client_data); } /* @@ -693,7 +688,7 @@ CORD CORD_concat_forest(ForestElement * forest, size_t expected_len) } i++; } - return(sum); + return sum; } /* Insert the frontier of x into forest. Balanced subtrees are */ @@ -724,13 +719,13 @@ CORD CORD_balance(CORD x) Forest forest; size_t len; - if (x == 0) return(0); - if (CORD_IS_STRING(x)) return(x); + if (0 == x) return 0; + if (CORD_IS_STRING(x)) return x; if (!min_len_init) CORD_init_min_len(); len = LEN(x); CORD_init_forest(forest, len); CORD_balance_insert(x, len, forest); - return(CORD_concat_forest(forest, len)); + return CORD_concat_forest(forest, len); } @@ -792,7 +787,7 @@ char CORD__pos_fetch(CORD_pos p) if (!IS_FUNCTION(leaf)) ABORT("CORD_pos_fetch: bad leaf"); f = &((CordRep *)leaf)->function; - return ((*(f -> fn))(p[0].cur_pos - pe -> pe_start_pos, f -> client_data)); + return f->fn(p[0].cur_pos - pe->pe_start_pos, f->client_data); } void CORD__next(CORD_pos p) @@ -890,9 +885,9 @@ void CORD__prev(CORD_pos p) char CORD_pos_fetch(CORD_pos p) { if (p[0].cur_end != 0) { - return(p[0].cur_leaf[p[0].cur_pos - p[0].cur_start]); + return p[0].cur_leaf[p[0].cur_pos - p[0].cur_start]; } else { - return(CORD__pos_fetch(p)); + return CORD__pos_fetch(p); } } @@ -916,17 +911,17 @@ void CORD_prev(CORD_pos p) size_t CORD_pos_to_index(CORD_pos p) { - return(p[0].cur_pos); + return p[0].cur_pos; } CORD CORD_pos_to_cord(CORD_pos p) { - return(p[0].path[0].pe_cord); + return p[0].path[0].pe_cord; } int CORD_pos_valid(CORD_pos p) { - return(p[0].path_len != CORD_POS_INVALID); + return p[0].path_len != CORD_POS_INVALID; } void CORD_set_pos(CORD_pos p, CORD x, size_t i) diff --git a/cord/cordprnt.c b/cord/cordprnt.c index b3ac6367..72021f8c 100644 --- a/cord/cordprnt.c +++ b/cord/cordprnt.c @@ -88,7 +88,7 @@ static int extract_conv_spec(CORD_pos source, char *buf, *width = NONE; buf[chars_so_far++] = '%'; while(CORD_pos_valid(source)) { - if (chars_so_far >= CONV_SPEC_LEN) return(-1); + if (chars_so_far >= CONV_SPEC_LEN) return -1; current = CORD_pos_fetch(source); buf[chars_so_far++] = current; switch(current) { @@ -166,11 +166,11 @@ static int extract_conv_spec(CORD_pos source, char *buf, case 'r': goto done; default: - return(-1); + return -1; } CORD_next(source); } - return(-1); + return -1; done: if (saw_number) { if (saw_period) { @@ -183,7 +183,7 @@ static int extract_conv_spec(CORD_pos source, char *buf, *prec = NONE; } buf[chars_so_far] = '\0'; - return(result); + return result; } #if defined(__DJGPP__) || defined(__STRICT_ANSI__) @@ -213,7 +213,7 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args) current = CORD_pos_fetch(pos); if (current == '%') { CORD_next(pos); - if (!CORD_pos_valid(pos)) return(-1); + if (!CORD_pos_valid(pos)) return -1; current = CORD_pos_fetch(pos); if (current == '%') { CORD_ec_append(result, current); @@ -227,7 +227,7 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args) if (extract_conv_spec(pos, conv_spec, &width, &prec, &left_adj, &long_arg) < 0) { - return(-1); + return -1; } current = CORD_pos_fetch(pos); switch(current) { @@ -257,7 +257,7 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args) arg = va_arg(args, CORD); len = CORD_len(arg); if (prec != NONE && len > (unsigned)prec) { - if (prec < 0) return(-1); + if (prec < 0) return -1; arg = CORD_substr(arg, 0, (unsigned)prec); len = (unsigned)prec; } @@ -374,7 +374,7 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args) /* old style vsprintf */ len = strlen(buf); } else if (res < 0) { - return(-1); + return -1; } if (buf != result[0].ec_bufptr) { char c; @@ -394,7 +394,7 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args) } count = ec_len(result); *out = CORD_balance(CORD_ec_to_cord(result)); - return(count); + return count; } int CORD_sprintf(CORD * out, CORD format, ...) @@ -405,7 +405,7 @@ int CORD_sprintf(CORD * out, CORD format, ...) va_start(args, format); result = CORD_vsprintf(out, format, args); va_end(args); - return(result); + return result; } int CORD_fprintf(FILE * f, CORD format, ...) @@ -418,7 +418,7 @@ int CORD_fprintf(FILE * f, CORD format, ...) result = CORD_vsprintf(&out, format, args); va_end(args); if (result > 0) CORD_put(out, f); - return(result); + return result; } int CORD_vfprintf(FILE * f, CORD format, va_list args) @@ -428,7 +428,7 @@ int CORD_vfprintf(FILE * f, CORD format, va_list args) result = CORD_vsprintf(&out, format, args); if (result > 0) CORD_put(out, f); - return(result); + return result; } int CORD_printf(CORD format, ...) @@ -441,7 +441,7 @@ int CORD_printf(CORD format, ...) result = CORD_vsprintf(&out, format, args); va_end(args); if (result > 0) CORD_put(out, stdout); - return(result); + return result; } int CORD_vprintf(CORD format, va_list args) @@ -451,5 +451,5 @@ int CORD_vprintf(CORD format, va_list args) result = CORD_vsprintf(&out, format, args); if (result > 0) CORD_put(out, stdout); - return(result); + return result; } diff --git a/cord/cordxtra.c b/cord/cordxtra.c index f7bb1ad2..7caa5d49 100644 --- a/cord/cordxtra.c +++ b/cord/cordxtra.c @@ -73,12 +73,12 @@ CORD CORD_cat_char(CORD x, char c) { char * string; - if (c == '\0') return(CORD_cat(x, CORD_nul(1))); + if ('\0' == c) return CORD_cat(x, CORD_nul(1)); string = (char *)GC_MALLOC_ATOMIC(2); - if (string == 0) OUT_OF_MEMORY; + if (NULL == string) OUT_OF_MEMORY; string[0] = c; string[1] = '\0'; - return(CORD_cat_char_star(x, string, 1)); + return CORD_cat_char_star(x, string, 1); } CORD CORD_catn(int nargs, ...) @@ -93,7 +93,7 @@ CORD CORD_catn(int nargs, ...) result = CORD_cat(result, next); } va_end(args); - return(result); + return result; } typedef struct { @@ -109,11 +109,7 @@ int CORD_fill_proc(char c, void * client_data) (d -> buf)[count] = c; d -> count = ++count; - if (count >= d -> len) { - return(1); - } else { - return(0); - } + return count >= d -> len ? 1 : 0; } int CORD_batched_fill_proc(const char * s, void * client_data) @@ -124,15 +120,15 @@ int CORD_batched_fill_proc(const char * s, void * client_data) char * buf = d -> buf; const char * t = s; - while((buf[count] = *t++) != '\0') { + while ((buf[count] = *t++) != '\0') { count++; if (count >= max) { d -> count = count; - return(1); + return 1; } } d -> count = count; - return(0); + return 0; } /* Fill buf with len characters starting at i. */ @@ -154,30 +150,24 @@ int CORD_cmp(CORD x, CORD y) CORD_pos xpos; CORD_pos ypos; - if (y == CORD_EMPTY) return(x != CORD_EMPTY); - if (x == CORD_EMPTY) return(-1); - if (CORD_IS_STRING(y) && CORD_IS_STRING(x)) return(strcmp(x,y)); + if (y == CORD_EMPTY) return x != CORD_EMPTY; + if (x == CORD_EMPTY) return -1; + if (CORD_IS_STRING(y) && CORD_IS_STRING(x)) return strcmp(x, y); CORD_set_pos(xpos, x, 0); CORD_set_pos(ypos, y, 0); for(;;) { size_t avail, yavail; if (!CORD_pos_valid(xpos)) { - if (CORD_pos_valid(ypos)) { - return(-1); - } else { - return(0); - } - } - if (!CORD_pos_valid(ypos)) { - return(1); + return CORD_pos_valid(ypos) ? -1 : 0; } + if (!CORD_pos_valid(ypos)) return 1; avail = CORD_pos_chars_left(xpos); - if (avail == 0 + if (0 == avail || (yavail = CORD_pos_chars_left(ypos)) == 0) { char xcurrent = CORD_pos_fetch(xpos); char ycurrent = CORD_pos_fetch(ypos); - if (xcurrent != ycurrent) return(xcurrent - ycurrent); + if (xcurrent != ycurrent) return xcurrent - ycurrent; CORD_next(xpos); CORD_next(ypos); } else { @@ -187,7 +177,7 @@ int CORD_cmp(CORD x, CORD y) if (avail > yavail) avail = yavail; result = strncmp(CORD_pos_cur_char_addr(xpos), CORD_pos_cur_char_addr(ypos), avail); - if (result != 0) return(result); + if (result != 0) return result; CORD_pos_advance(xpos, avail); CORD_pos_advance(ypos, avail); } @@ -206,21 +196,15 @@ int CORD_ncmp(CORD x, size_t x_start, CORD y, size_t y_start, size_t len) long avail, yavail; if (!CORD_pos_valid(xpos)) { - if (CORD_pos_valid(ypos)) { - return(-1); - } else { - return(0); - } - } - if (!CORD_pos_valid(ypos)) { - return(1); + return CORD_pos_valid(ypos) ? -1 : 0; } + if (!CORD_pos_valid(ypos)) return 1; if ((avail = CORD_pos_chars_left(xpos)) <= 0 || (yavail = CORD_pos_chars_left(ypos)) <= 0) { char xcurrent = CORD_pos_fetch(xpos); char ycurrent = CORD_pos_fetch(ypos); - if (xcurrent != ycurrent) return(xcurrent - ycurrent); + if (xcurrent != ycurrent) return xcurrent - ycurrent; CORD_next(xpos); CORD_next(ypos); count++; @@ -233,13 +217,13 @@ int CORD_ncmp(CORD x, size_t x_start, CORD y, size_t y_start, size_t len) if (count > len) avail -= (long)(count - len); result = strncmp(CORD_pos_cur_char_addr(xpos), - CORD_pos_cur_char_addr(ypos), (size_t)avail); - if (result != 0) return(result); + CORD_pos_cur_char_addr(ypos), (size_t)avail); + if (result != 0) return result; CORD_pos_advance(xpos, (size_t)avail); CORD_pos_advance(ypos, (size_t)avail); } } - return(0); + return 0; } char * CORD_to_char_star(CORD x) @@ -247,11 +231,11 @@ char * CORD_to_char_star(CORD x) size_t len = CORD_len(x); char * result = (char *)GC_MALLOC_ATOMIC(len + 1); - if (result == 0) OUT_OF_MEMORY; + if (NULL == result) OUT_OF_MEMORY; if (len > 0 && CORD_fill_buf(x, 0, len, result) != 1) ABORT("CORD_fill_buf malfunction"); result[len] = '\0'; - return(result); + return result; } CORD CORD_from_char_star(const char *s) @@ -259,18 +243,18 @@ CORD CORD_from_char_star(const char *s) char * result; size_t len = strlen(s); - if (0 == len) return(CORD_EMPTY); + if (0 == len) return CORD_EMPTY; result = (char *)GC_MALLOC_ATOMIC(len + 1); - if (result == 0) OUT_OF_MEMORY; + if (NULL == result) OUT_OF_MEMORY; memcpy(result, s, len+1); - return(result); + return result; } const char * CORD_to_const_char_star(CORD x) { - if (x == 0) return(""); - if (CORD_IS_STRING(x)) return((const char *)x); - return(CORD_to_char_star(x)); + if (0 == x) return ""; + if (CORD_IS_STRING(x)) return (const char *)x; + return CORD_to_char_star(x); } char CORD_fetch(CORD x, size_t i) @@ -279,7 +263,7 @@ char CORD_fetch(CORD x, size_t i) CORD_set_pos(xpos, x, i); if (!CORD_pos_valid(xpos)) ABORT("bad index?"); - return(CORD_pos_fetch(xpos)); + return CORD_pos_fetch(xpos); } @@ -287,24 +271,22 @@ int CORD_put_proc(char c, void * client_data) { FILE * f = (FILE *)client_data; - return(putc(c, f) == EOF); + return putc(c, f) == EOF; } int CORD_batched_put_proc(const char * s, void * client_data) { FILE * f = (FILE *)client_data; - return(fputs(s, f) == EOF); + return fputs(s, f) == EOF; } int CORD_put(CORD x, FILE * f) { - if (CORD_iter5(x, 0, CORD_put_proc, CORD_batched_put_proc, f)) { - return(EOF); - } else { - return(1); - } + if (CORD_iter5(x, 0, CORD_put_proc, CORD_batched_put_proc, f)) + return EOF; + return 1; } typedef struct { @@ -316,18 +298,18 @@ int CORD_chr_proc(char c, void * client_data) { chr_data * d = (chr_data *)client_data; - if (c == d -> target) return(1); - (d -> pos) ++; - return(0); + if (c == d -> target) return 1; + (d -> pos)++; + return 0; } int CORD_rchr_proc(char c, void * client_data) { chr_data * d = (chr_data *)client_data; - if (c == d -> target) return(1); - (d -> pos) --; - return(0); + if (c == d -> target) return 1; + (d -> pos)--; + return 0; } int CORD_batched_chr_proc(const char *s, void * client_data) @@ -337,11 +319,10 @@ int CORD_batched_chr_proc(const char *s, void * client_data) if (NULL == occ) { d -> pos += strlen(s); - return(0); - } else { - d -> pos += occ - s; - return(1); + return 0; } + d -> pos += occ - s; + return 1; } size_t CORD_chr(CORD x, size_t i, int c) @@ -351,9 +332,9 @@ size_t CORD_chr(CORD x, size_t i, int c) d.pos = i; d.target = (char)c; if (CORD_iter5(x, i, CORD_chr_proc, CORD_batched_chr_proc, &d)) { - return(d.pos); + return d.pos; } else { - return(CORD_NOT_FOUND); + return CORD_NOT_FOUND; } } @@ -364,9 +345,9 @@ size_t CORD_rchr(CORD x, size_t i, int c) d.pos = i; d.target = (char)c; if (CORD_riter4(x, i, CORD_rchr_proc, &d)) { - return(d.pos); + return d.pos; } else { - return(CORD_NOT_FOUND); + return CORD_NOT_FOUND; } } @@ -391,7 +372,7 @@ size_t CORD_str(CORD x, size_t start, CORD s) size_t i; size_t match_pos; - if (s == CORD_EMPTY) return(start); + if (s == CORD_EMPTY) return start; if (CORD_IS_STRING(s)) { s_start = s; slen = strlen(s); @@ -399,7 +380,7 @@ size_t CORD_str(CORD x, size_t start, CORD s) s_start = CORD_to_char_star(CORD_substr(s, 0, sizeof(unsigned long))); slen = CORD_len(s); } - if (xlen < start || xlen - start < slen) return(CORD_NOT_FOUND); + if (xlen < start || xlen - start < slen) return CORD_NOT_FOUND; start_len = slen; if (start_len > sizeof(unsigned long)) start_len = sizeof(unsigned long); CORD_set_pos(xpos, x, start); @@ -413,20 +394,17 @@ size_t CORD_str(CORD x, size_t start, CORD s) CORD_next(xpos); } for (match_pos = start; ; match_pos++) { - if ((x_buf & mask) == s_buf) { - if (slen == start_len || - CORD_ncmp(x, match_pos + start_len, - s, start_len, slen - start_len) == 0) { - return(match_pos); - } - } - if ( match_pos == xlen - slen ) { - return(CORD_NOT_FOUND); - } + if ((x_buf & mask) == s_buf + && (slen == start_len + || CORD_ncmp(x, match_pos + start_len, + s, start_len, slen - start_len) == 0)) + break; + if (match_pos == xlen - slen) return CORD_NOT_FOUND; x_buf <<= 8; x_buf |= (unsigned char)CORD_pos_fetch(xpos); CORD_next(xpos); } + return match_pos; } void CORD_ec_flush_buf(CORD_ec x) @@ -481,7 +459,7 @@ CORD CORD_from_file_eager(FILE * f) CORD_ec_append(ecord, (char)c); } (void) fclose(f); - return(CORD_balance(CORD_ec_to_cord(ecord))); + return CORD_balance(CORD_ec_to_cord(ecord)); } /* The state maintained for a lazily read file consists primarily */ @@ -567,18 +545,17 @@ char CORD_lf_func(size_t i, void * client_data) rd.state = state; rd.file_pos = i; rd.new_cache = GC_NEW_ATOMIC(cache_line); - if (rd.new_cache == 0) OUT_OF_MEMORY; + if (NULL == rd.new_cache) OUT_OF_MEMORY; return (char)((GC_word)GC_call_with_alloc_lock(refill_cache, &rd)); } - return(cl -> data[MOD_LINE_SZ(i)]); + return cl -> data[MOD_LINE_SZ(i)]; } #ifndef GC_NO_FINALIZATION void CORD_lf_close_proc(void * obj, void * client_data CORD_ATTR_UNUSED) { - if (fclose(((lf_state *)obj) -> lf_file) != 0) { + if (fclose(((lf_state *)obj) -> lf_file) != 0) ABORT("CORD_lf_close_proc: fclose failed"); - } } #endif @@ -587,7 +564,7 @@ CORD CORD_from_file_lazy_inner(FILE * f, size_t len) lf_state * state = GC_NEW(lf_state); int i; - if (state == 0) OUT_OF_MEMORY; + if (NULL == state) OUT_OF_MEMORY; if (len != 0) { /* Dummy read to force buffer allocation. */ /* This greatly increases the probability */ @@ -609,7 +586,7 @@ CORD CORD_from_file_lazy_inner(FILE * f, size_t len) # ifndef GC_NO_FINALIZATION GC_REGISTER_FINALIZER(state, CORD_lf_close_proc, 0, 0, 0); # endif - return(CORD_from_fn(CORD_lf_func, state, len)); + return CORD_from_fn(CORD_lf_func, state, len); } CORD CORD_from_file_lazy(FILE * f) @@ -621,7 +598,7 @@ CORD CORD_from_file_lazy(FILE * f) || fseek(f, 0l, SEEK_SET) != 0) { ABORT("Bad f argument or I/O failure"); } - return(CORD_from_file_lazy_inner(f, (size_t)len)); + return CORD_from_file_lazy_inner(f, (size_t)len); } # define LAZY_THRESHOLD (128*1024 + 1) @@ -636,8 +613,7 @@ CORD CORD_from_file(FILE * f) ABORT("Bad f argument or I/O failure"); } if (len < LAZY_THRESHOLD) { - return(CORD_from_file_eager(f)); - } else { - return(CORD_from_file_lazy_inner(f, (size_t)len)); + return CORD_from_file_eager(f); } + return CORD_from_file_lazy_inner(f, (size_t)len); } diff --git a/cord/tests/cordtest.c b/cord/tests/cordtest.c index 670aa7aa..8a8e6e17 100644 --- a/cord/tests/cordtest.c +++ b/cord/tests/cordtest.c @@ -49,18 +49,18 @@ int test_fn(char c, void * client_data) if (c != 'a') ABORT("bad char"); } count++; - return(0); + return 0; } else { if (c != 'c') ABORT("bad char"); count++; - return(1); + return 1; } } char id_cord_fn(size_t i, void * client_data) { if (client_data != 0) ABORT("id_cord_fn: bad client data"); - return((char)i); + return (char)i; } void test_basics(void) @@ -345,5 +345,5 @@ int main(void) test_extras(); test_printf(); CORD_fprintf(stdout, "SUCCEEDED\n"); - return(0); + return 0; } diff --git a/cord/tests/de.c b/cord/tests/de.c index 6ad38b47..4a61aa6b 100644 --- a/cord/tests/de.c +++ b/cord/tests/de.c @@ -187,7 +187,7 @@ size_t line_pos(int i, int *c) if (map -> line < i - 2) /* rebuild */ invalidate_map(i); for (j = map -> line, cur = map -> pos; j < i;) { cur = CORD_chr(current, cur, '\n'); - if (cur == current_len-1) return(CORD_NOT_FOUND); + if (cur == current_len-1) return CORD_NOT_FOUND; cur++; if (++j > current_map -> line) add_map(j, cur); } @@ -200,7 +200,7 @@ size_t line_pos(int i, int *c) } cur += *c; } - return(cur); + return cur; } void add_hist(CORD s) @@ -284,7 +284,7 @@ CORD retrieve_line(CORD s, size_t pos, unsigned column) if (eol == CORD_NOT_FOUND) eol = CORD_len(candidate); len = (int)eol - (int)column; if (len < 0) len = 0; - return(CORD_substr(s, pos + column, len)); + return CORD_substr(s, pos + column, len); } # ifdef WIN32 @@ -296,8 +296,8 @@ CORD retrieve_line(CORD s, size_t pos, unsigned column) invalidate_map(dis_line + LINES); /* Prune search */ pos = line_pos(dis_line + i, 0); - if (pos == CORD_NOT_FOUND) return(CORD_EMPTY); - return(retrieve_line(current, pos, dis_col)); + if (pos == CORD_NOT_FOUND) return CORD_EMPTY; + return retrieve_line(current, pos, dis_col); } # endif @@ -394,7 +394,7 @@ void fix_pos(void) int beep(void) { putc('\007', stderr); - return(0); + return 0; } #endif /* !WIN32 && !MACINTOSH */ diff --git a/cord/tests/de_win.c b/cord/tests/de_win.c index 9ba4c462..d7978b33 100644 --- a/cord/tests/de_win.c +++ b/cord/tests/de_win.c @@ -77,7 +77,7 @@ int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, if (RegisterClass (&wndclass) == 0) { de_error("RegisterClass error"); - return(0); + return 0; } } @@ -90,7 +90,7 @@ int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, if (command_line == 0 || *command_line == 0) { de_error("File name argument required"); - return( 0 ); + return 0; } else { char *p = command_line; @@ -110,7 +110,7 @@ int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, hInstance, NULL); if (hwnd == NULL) { de_error("CreateWindow error"); - return(0); + return 0; } ShowWindow (hwnd, nCmdShow); @@ -143,7 +143,7 @@ char * plain_chars(char * text, size_t len) } } result[len] = '\0'; - return(result); + return result; } /* Return the argument with all non-control-characters replaced by */ @@ -162,7 +162,7 @@ char * control_chars(char * text, size_t len) } } result[len] = '\0'; - return(result); + return result; } int char_width; @@ -236,7 +236,7 @@ LRESULT CALLBACK WndProc (HWND hwnd_arg, UINT message, COLS = (client_area.right - client_area.left)/char_width; LINES = (client_area.bottom - client_area.top)/char_height; generic_init(); - return(0); + return 0; case WM_CHAR: if (wParam == QUIT) { @@ -244,20 +244,20 @@ LRESULT CALLBACK WndProc (HWND hwnd_arg, UINT message, } else { do_command((int)wParam); } - return(0); + return 0; case WM_SETFOCUS: CreateCaret(hwnd_arg, NULL, char_width, char_height); ShowCaret(hwnd_arg); caret_visible = 1; update_cursor(); - return(0); + return 0; case WM_KILLFOCUS: HideCaret(hwnd_arg); DestroyCaret(); caret_visible = 0; - return(0); + return 0; case WM_LBUTTONUP: { @@ -266,7 +266,7 @@ LRESULT CALLBACK WndProc (HWND hwnd_arg, UINT message, set_position(xpos / (unsigned)char_width, ypos / (unsigned)char_height); - return(0); + return 0; } case WM_COMMAND: @@ -274,24 +274,24 @@ LRESULT CALLBACK WndProc (HWND hwnd_arg, UINT message, if (id & EDIT_CMD_FLAG) { if (id & REPEAT_FLAG) do_command(REPEAT); do_command(CHAR_CMD(id)); - return( 0 ); + return 0; } else { switch(id) { case IDM_FILEEXIT: SendMessage(hwnd_arg, WM_CLOSE, 0, 0L); - return( 0 ); + return 0; case IDM_HELPABOUT: if( DialogBox( hInstance, TEXT("ABOUTBOX"), hwnd_arg, AboutBoxCallback ) ) InvalidateRect(hwnd_arg, NULL, TRUE); - return( 0 ); + return 0; case IDM_HELPCONTENTS: de_error( "Cursor keys: ^B(left) ^F(right) ^P(up) ^N(down)\n" "Undo: ^U Write: ^W Quit:^D Repeat count: ^R[n]\n" "Top: ^T Locate (search, find): ^L text ^L\n"); - return( 0 ); + return 0; } } break; @@ -327,10 +327,10 @@ static void *store_debug_info(void *p, size_t lb, ptr_t body = (ptr_t)(ohdr + 1); word gc_sz = GC_size((ptr_t)ohdr); if (ohdr -> oh_sz + DEBUG_BYTES > gc_sz) { - return((ptr_t)(&(ohdr -> oh_sz))); + return (ptr_t)(&(ohdr -> oh_sz)); } if (ohdr -> oh_sf != (START_FLAG ^ (word)body)) { - return((ptr_t)(&(ohdr -> oh_sf))); + return (ptr_t)(&(ohdr -> oh_sf)); } if (((word *)ohdr)[BYTES_TO_WORDS(gc_sz)-1] != (END_FLAG ^ (word)body)) { return (ptr_t)(&((word *)ohdr)[BYTES_TO_WORDS(gc_sz)-1]); @@ -339,7 +339,7 @@ static void *store_debug_info(void *p, size_t lb, != (END_FLAG ^ (word)body)) { return (ptr_t)(&((word *)body)[SIMPLE_ROUNDED_UP_WORDS(ohdr->oh_sz)]); } - return(0); + return NULL; } #endif /* !SHORT_DBG_HDRS */ @@ -594,13 +594,13 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) if (NULL == result) { GC_err_printf("GC internal allocation (%lu bytes) returning NULL\n", (unsigned long) lb); - return(0); + return NULL; } if (!GC_debugging_started) { GC_start_debugging_inner(); } ADD_CALL_CHAIN(result, GC_RETURN_ADDR); - return (GC_store_debug_info_inner(result, (word)lb, "INTERNAL", 0)); + return GC_store_debug_info_inner(result, (word)lb, "INTERNAL", 0); } GC_INNER void * GC_debug_generic_malloc_inner_ignore_off_page(size_t lb, @@ -614,13 +614,13 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) if (NULL == result) { GC_err_printf("GC internal allocation (%lu bytes) returning NULL\n", (unsigned long) lb); - return(0); + return NULL; } if (!GC_debugging_started) { GC_start_debugging_inner(); } ADD_CALL_CHAIN(result, GC_RETURN_ADDR); - return (GC_store_debug_info_inner(result, (word)lb, "INTERNAL", 0)); + return GC_store_debug_info_inner(result, (word)lb, "INTERNAL", 0); } #endif /* DBG_HDRS_ALL */ @@ -879,7 +879,7 @@ GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS) if ((ptr_t)p - (ptr_t)base != sizeof(oh)) { GC_err_printf( "GC_debug_realloc called on pointer %p w/o debugging info\n", p); - return(GC_realloc(p, lb)); + return GC_realloc(p, lb); } hhdr = HDR(base); switch (hhdr -> hb_obj_kind) { @@ -913,7 +913,7 @@ GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS) BCOPY(p, result, old_sz < lb ? old_sz : lb); GC_debug_free(p); } - return(result); + return result; } GC_API GC_ATTR_MALLOC void * GC_CALL @@ -1064,7 +1064,7 @@ STATIC void * GC_make_closure(GC_finalization_proc fn, void * data) result -> cl_fn = fn; result -> cl_data = data; } - return((void *)result); + return (void *)result; } /* An auxiliary fns to make finalization work correctly with displaced */ @@ -193,7 +193,7 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0; if (0 == COVERT_DATAFLOW(dynStructureAddr)) { /* _DYNAMIC symbol not resolved. */ - return(0); + return NULL; } if (cachedResult == 0) { int tag; @@ -719,9 +719,9 @@ GC_FirstDLOpenedLinkMap(void) if (0 == COVERT_DATAFLOW(_DYNAMIC)) { /* _DYNAMIC symbol not resolved. */ - return(0); + return NULL; } - if( cachedResult == 0 ) { + if (NULL == cachedResult) { # if defined(NETBSD) && defined(RTLD_DI_LINKMAP) # if defined(CPPCHECK) # define GC_RTLD_DI_LINKMAP 2 diff --git a/extra/real_malloc.c b/extra/real_malloc.c index 145e73f3..1fd21250 100644 --- a/extra/real_malloc.c +++ b/extra/real_malloc.c @@ -27,7 +27,7 @@ void * real_malloc(size_t size) { - return(malloc(size)); + return malloc(size); } # else @@ -155,7 +155,7 @@ GC_API int GC_CALL GC_register_disappearing_link(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)); + return GC_general_register_disappearing_link(link, base); } STATIC int GC_register_disappearing_link_inner( @@ -280,7 +280,7 @@ GC_API int GC_CALL GC_unregister_disappearing_link(void * * link) struct disappearing_link *curr_dl; DCL_LOCK_STATE; - if (((word)link & (ALIGNMENT-1)) != 0) return(0); /* Nothing to do. */ + if (((word)link & (ALIGNMENT-1)) != 0) return 0; /* Nothing to do. */ LOCK(); curr_dl = GC_unregister_disappearing_link_inner(&GC_dl_hashtbl, link); @@ -510,7 +510,7 @@ GC_API GC_await_finalize_proc GC_CALL GC_get_await_finalize_proc(void) struct disappearing_link *curr_dl; DCL_LOCK_STATE; - if (((word)link & (ALIGNMENT-1)) != 0) return(0); /* Nothing to do. */ + if (((word)link & (ALIGNMENT-1)) != 0) return 0; /* Nothing to do. */ LOCK(); curr_dl = GC_unregister_disappearing_link_inner(&GC_ll_hashtbl, link); diff --git a/gc_dlopen.c b/gc_dlopen.c index 13991bae..4e8e3308 100644 --- a/gc_dlopen.c +++ b/gc_dlopen.c @@ -82,7 +82,7 @@ GC_API void * WRAP_DLFUNC(dlopen)(const char *path, int mode) # ifndef USE_PROC_FOR_LIBRARIES GC_enable(); /* undoes disable_gc_for_dlopen */ # endif - return(result); + return result; } #ifdef GC_USE_LD_WRAP @@ -165,7 +165,7 @@ static void maybe_finalize(void) if (0 == op) { GC_oom_func oom_fn = GC_oom_fn; UNLOCK(); - return((*oom_fn)(lb)); + return (*oom_fn)(lb); } } else { GC_gcjobjfreelist[lg] = (ptr_t)obj_link(op); @@ -179,7 +179,7 @@ static void maybe_finalize(void) if (0 == op) { GC_oom_func oom_fn = GC_oom_fn; UNLOCK(); - return((*oom_fn)(lb)); + return (*oom_fn)(lb); } } *(void **)op = ptr_to_struct_containing_descr; @@ -203,12 +203,12 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_gcj_malloc(size_t lb, maybe_finalize(); result = GC_generic_malloc_inner(SIZET_SAT_ADD(lb, DEBUG_BYTES), GC_gcj_debug_kind); - if (result == 0) { + if (NULL == result) { GC_oom_func oom_fn = GC_oom_fn; UNLOCK(); GC_err_printf("GC_debug_gcj_malloc(%lu, %p) returning NULL (%s:%d)\n", (unsigned long)lb, ptr_to_struct_containing_descr, s, i); - return((*oom_fn)(lb)); + return (*oom_fn)(lb); } *((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr; if (!GC_debugging_started) { @@ -242,7 +242,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_gcj_malloc_ignore_off_page(size_t lb, if (0 == op) { GC_oom_func oom_fn = GC_oom_fn; UNLOCK(); - return((*oom_fn)(lb)); + return (*oom_fn)(lb); } } else { GC_gcjobjfreelist[lg] = (ptr_t)obj_link(op); @@ -255,7 +255,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_gcj_malloc_ignore_off_page(size_t lb, if (0 == op) { GC_oom_func oom_fn = GC_oom_fn; UNLOCK(); - return((*oom_fn)(lb)); + return (*oom_fn)(lb); } } *(void **)op = ptr_to_struct_containing_descr; @@ -30,9 +30,9 @@ GC_INNER hdr * GC_find_header(ptr_t h) # ifdef HASH_TL hdr * result; GET_HDR(h, result); - return(result); + return result; # else - return(HDR_INNER(h)); + return HDR_INNER(h); # endif } @@ -174,7 +174,7 @@ static hdr * alloc_hdr(void) result = GC_hdr_free_list; GC_hdr_free_list = (hdr *) result -> hb_next; } - return(result); + return result; } GC_INLINE void free_hdr(hdr * hhdr) @@ -221,10 +221,9 @@ static GC_bool get_index(word addr) # ifdef HASH_TL i = TL_HASH(hi); - pi = p = GC_top_index[i]; - while(p != GC_all_nils) { - if (p -> key == hi) return(TRUE); - p = p -> hash_link; + pi = GC_top_index[i]; + for (p = pi; p != GC_all_nils; p = p -> hash_link) { + if (p -> key == hi) return TRUE; } # else if (GC_top_index[hi] != GC_all_nils) @@ -257,7 +256,7 @@ static GC_bool get_index(word addr) *prev = r; GC_top_index[i] = r; - return(TRUE); + return TRUE; } /* Install a header for block h. */ @@ -277,7 +276,7 @@ GC_INNER struct hblkhdr * GC_install_header(struct hblk *h) result -> hb_last_reclaimed = (unsigned short)GC_gc_no; # endif } - return(result); + return result; } /* Set up forwarding counts for block h of size sz */ @@ -380,9 +379,8 @@ GC_INNER struct hblk * GC_next_block(struct hblk *h, GC_bool allow_free) j++; } else { if (allow_free || !HBLK_IS_FREE(hhdr)) { - return ((struct hblk *) - (((bi -> key << LOG_BOTTOM_SZ) + j) - << LOG_HBLKSIZE)); + return (struct hblk *)(((bi -> key << LOG_BOTTOM_SZ) + + j) << LOG_HBLKSIZE); } else { j += divHBLKSZ(hhdr -> hb_sz); } @@ -391,7 +389,7 @@ GC_INNER struct hblk * GC_next_block(struct hblk *h, GC_bool allow_free) j = 0; bi = bi -> asc_link; } - return(0); + return NULL; } GC_INNER struct hblk * GC_prev_block(struct hblk *h) @@ -403,25 +401,26 @@ GC_INNER struct hblk * GC_prev_block(struct hblk *h) GET_BI(h, bi); if (bi == GC_all_nils) { word hi = (word)h >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE); + bi = GC_all_bottom_indices_end; - while (bi != 0 && bi -> key > hi) bi = bi -> desc_link; + while (bi != NULL && bi -> key > hi) + bi = bi -> desc_link; j = BOTTOM_SZ - 1; } - while(bi != 0) { + for (; bi != NULL; bi = bi -> desc_link) { while (j >= 0) { hdr * hhdr = bi -> index[j]; - if (0 == hhdr) { + + if (NULL == hhdr) { --j; } else if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { j -= (signed_word)hhdr; } else { - return((struct hblk *) - (((bi -> key << LOG_BOTTOM_SZ) + j) - << LOG_HBLKSIZE)); + return (struct hblk *)(((bi -> key << LOG_BOTTOM_SZ) + j) + << LOG_HBLKSIZE); } } j = BOTTOM_SZ - 1; - bi = bi -> desc_link; } - return(0); + return NULL; } diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 4f75be72..f7686dca 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -863,7 +863,7 @@ EXTERN_C_BEGIN * volatile int dummy; * * GC_stackbottom = (ptr_t)(&dummy); - * return(real_main(argc, argv, envp)); + * return real_main(argc, argv, envp); * } * * @@ -287,11 +287,8 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc(size_t lb, int k) BZERO(result, n_blocks * HBLKSIZE); } } - if (0 == result) { - return((*GC_get_oom_fn())(lb)); - } else { - return(result); - } + if (NULL == result) return (*GC_get_oom_fn())(lb); + return result; } GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_kind_global(size_t lb, int k) @@ -520,9 +517,10 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_uncollectable(size_t lb) { size_t lb = strlen(s) + 1; char *result = (char *)REDIRECT_MALLOC_F(lb); - if (result == 0) { + + if (NULL == result) { errno = ENOMEM; - return 0; + return NULL; } BCOPY(s, result, lb); return result; @@ -89,7 +89,7 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb) size_t orig_sz; /* Original sz in bytes */ int obj_kind; - if (p == 0) return(GC_malloc(lb)); /* Required by ANSI */ + if (NULL == p) return GC_malloc(lb); /* Required by ANSI */ if (0 == lb) /* and p != NULL */ { # ifndef IGNORE_FREE GC_free(p); @@ -154,7 +154,7 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb) /* tracing. */ BZERO((ptr_t)cleared_p + lb, orig_sz - lb); } - return(p); + return p; } /* shrink */ sz = lb; @@ -184,7 +184,7 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb) # if !defined(REDIRECT_MALLOC_IN_HEADER) void * realloc(void * p, size_t lb) { - return(REDIRECT_REALLOC(p, lb)); + return REDIRECT_REALLOC(p, lb); } # endif @@ -240,7 +240,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL if (init && !GC_debugging_started) { BZERO(result, n_blocks * HBLKSIZE); } - return(result); + return result; } GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_ignore_off_page(size_t lb) @@ -116,7 +116,7 @@ GC_INNER struct obj_kind GC_obj_kinds[MAXOBJKINDS] = { /* mark state is now MS_INVALID. */ GC_INNER GC_bool GC_collection_in_progress(void) { - return(GC_mark_state != MS_NONE); + return GC_mark_state != MS_NONE; } /* Clear all mark bits in the header. */ @@ -364,7 +364,7 @@ static void alloc_mark_stack(size_t); } if (GC_mark_state == MS_ROOTS_PUSHED) { GC_mark_state = MS_NONE; - return(TRUE); + return TRUE; } break; } @@ -377,7 +377,7 @@ static void alloc_mark_stack(size_t); if (GC_mark_stack_too_small) { alloc_mark_stack(2*GC_mark_stack_size); } - return(TRUE); + return TRUE; } case MS_INVALID: @@ -411,7 +411,7 @@ static void alloc_mark_stack(size_t); default: ABORT("GC_mark_some: bad state"); } - return(FALSE); + return FALSE; } #ifdef WRAP_MARK_SOME @@ -606,7 +606,7 @@ GC_INNER mse * GC_signal_mark_stack_overflow(mse *msp) # endif GC_COND_LOG_PRINTF("Mark stack overflow; current size: %lu entries\n", (unsigned long)GC_mark_stack_size); - return(msp - GC_MARK_STACK_DISCARDS); + return msp - GC_MARK_STACK_DISCARDS; } /* @@ -1952,17 +1952,16 @@ STATIC void GC_push_marked(struct hblk *h, hdr *hhdr) STATIC GC_bool GC_block_was_dirty(struct hblk *h, hdr *hhdr) { word sz = hhdr -> hb_sz; + ptr_t p; if (sz <= MAXOBJBYTES) { - return(GC_page_was_dirty(h)); - } else { - ptr_t p = (ptr_t)h; - while ((word)p < (word)h + sz) { - if (GC_page_was_dirty((struct hblk *)p)) return(TRUE); - p += HBLKSIZE; - } - return(FALSE); + return GC_page_was_dirty(h); + } + + for (p = (ptr_t)h; (word)p < (word)h + sz; p += HBLKSIZE) { + if (GC_page_was_dirty((struct hblk *)p)) return TRUE; } + return FALSE; } #endif /* GC_DISABLE_INCREMENTAL */ @@ -1982,7 +1981,7 @@ STATIC struct hblk * GC_push_next_marked(struct hblk *h) # endif } GC_push_marked(h, hhdr); - return(h + OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz)); + return h + OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz); } #ifndef GC_DISABLE_INCREMENTAL @@ -2023,7 +2022,7 @@ STATIC struct hblk * GC_push_next_marked(struct hblk *h) /* else */ { GC_push_marked(h, hhdr); } - return(h + OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz)); + return h + OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz); } #endif /* !GC_DISABLE_INCREMENTAL */ @@ -2057,5 +2056,5 @@ STATIC struct hblk * GC_push_next_marked_uncollectable(struct hblk *h) h += OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz); hhdr = HDR(h); } - return(h + OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz)); + return h + OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz); } @@ -83,15 +83,15 @@ int GC_no_dls = 0; /* Register dynamic library data segments. */ if (last_root_set < n_root_sets && (word)p >= (word)GC_static_roots[last_root_set].r_start && (word)p < (word)GC_static_roots[last_root_set].r_end) - return(TRUE); + return TRUE; for (i = 0; i < n_root_sets; i++) { if ((word)p >= (word)GC_static_roots[i].r_start && (word)p < (word)GC_static_roots[i].r_end) { last_root_set = i; - return(TRUE); + return TRUE; } } - return(FALSE); + return FALSE; } #endif /* !THREADS */ @@ -109,6 +109,7 @@ int GC_no_dls = 0; /* Register dynamic library data segments. */ GC_INLINE int rt_hash(ptr_t addr) { word result = (word) addr; + # if CPP_WORDSZ > 8*LOG_RT_SIZE result ^= result >> 8*LOG_RT_SIZE; # endif @@ -117,8 +118,7 @@ int GC_no_dls = 0; /* Register dynamic library data segments. */ # endif result ^= result >> 2*LOG_RT_SIZE; result ^= result >> LOG_RT_SIZE; - result &= (RT_SIZE-1); - return(result); + return result & (RT_SIZE-1); } /* Is a range starting at b already in the table? If so return a */ @@ -126,13 +126,12 @@ int GC_no_dls = 0; /* Register dynamic library data segments. */ GC_INNER void * GC_roots_present(ptr_t b) { int h = rt_hash(b); - struct roots *p = GC_root_index[h]; + struct roots *p; - while (p != 0) { - if (p -> r_start == (ptr_t)b) return(p); - p = p -> r_next; + for (p = GC_root_index[h]; p != NULL; p = p -> r_next) { + if (p -> r_start == (ptr_t)b) break; } - return NULL; + return p; } /* Add the given root structure to the index. */ @@ -493,7 +492,7 @@ STATIC void GC_remove_tmp_roots(void) return GC_static_roots[i].r_tmp; } } - return(FALSE); + return FALSE; } #endif /* !NO_DEBUGGING */ @@ -516,7 +515,7 @@ GC_INNER ptr_t GC_approx_sp(void) /* Also force stack to grow if necessary. Otherwise the */ /* later accesses might cause the kernel to think we're */ /* doing something wrong. */ - return((ptr_t)sp); + return (ptr_t)sp; } /* @@ -175,7 +175,7 @@ GC_INNER long GC_large_alloc_warn_interval = GC_LARGE_ALLOC_WARN_INTERVAL; STATIC void * GC_CALLBACK GC_default_oom_fn( size_t bytes_requested GC_ATTR_UNUSED) { - return(0); + return NULL; } /* All accesses to it should be synchronized to avoid data races. */ @@ -318,7 +318,7 @@ STATIC void GC_init_size_map(void) # else GC_noop1(COVERT_DATAFLOW(dummy)); # endif - return(arg); + return arg; } # endif /* !ASM_CLEAR_CODE */ @@ -426,11 +426,11 @@ GC_API void * GC_CALL GC_base(void * p) hdr *candidate_hdr; r = (ptr_t)p; - if (!EXPECT(GC_is_initialized, TRUE)) return 0; + if (!EXPECT(GC_is_initialized, TRUE)) return NULL; h = HBLKPTR(r); GET_BI(r, bi); candidate_hdr = HDR_FROM_BI(bi, r); - if (candidate_hdr == 0) return(0); + if (NULL == candidate_hdr) return NULL; /* If it's a pointer to the middle of a large object, move it */ /* to the beginning. */ while (IS_FORWARDING_ADDR_OR_NIL(candidate_hdr)) { @@ -438,23 +438,20 @@ GC_API void * GC_CALL GC_base(void * p) r = (ptr_t)h; candidate_hdr = HDR(h); } - if (HBLK_IS_FREE(candidate_hdr)) return(0); + if (HBLK_IS_FREE(candidate_hdr)) return NULL; /* Make sure r points to the beginning of the object */ r = (ptr_t)((word)r & ~(WORDS_TO_BYTES(1) - 1)); { - size_t offset = HBLKDISPL(r); word sz = candidate_hdr -> hb_sz; - size_t obj_displ = offset % sz; ptr_t limit; - r -= obj_displ; + r -= HBLKDISPL(r) % sz; limit = r + sz; - if ((word)limit > (word)(h + 1) && sz <= HBLKSIZE) { - return(0); - } - if ((word)p >= (word)limit) return(0); + if (((word)limit > (word)(h + 1) && sz <= HBLKSIZE) + || (word)p >= (word)limit) + return NULL; } - return((void *)r); + return (void *)r; } /* Return TRUE if and only if p points to somewhere in GC heap. */ @@ -1800,12 +1797,12 @@ GC_API void GC_CALL GC_enable_incremental(void) if (EAGAIN == errno) /* Resource temporarily unavailable */ continue; RESTORE_CANCEL(cancel_state); - return(result); + return result; } bytes_written += result; } RESTORE_CANCEL(cancel_state); - return(bytes_written); + return bytes_written; # endif } @@ -1969,7 +1966,7 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void) LOCK(); result = GC_current_warn_proc; UNLOCK(); - return(result); + return result; } #if !defined(PCR) && !defined(SMALL_CONFIG) @@ -2163,11 +2160,11 @@ GC_API void * GC_CALL GC_call_with_alloc_lock(GC_fn_type fn, void *client_data) # ifdef THREADS LOCK(); # endif - result = (*fn)(client_data); + result = fn(client_data); # ifdef THREADS UNLOCK(); # endif - return(result); + return result; } GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func fn, void *arg) @@ -43,7 +43,7 @@ p[2] = (word)p; p[3] = 0; } - return((ptr_t)(p-2)); + return (ptr_t)(p-2); } /* The same for size 4 cleared objects. */ @@ -63,7 +63,7 @@ p[1] = 0; CLEAR_DOUBLE(p+2); } - return((ptr_t)(p-4)); + return (ptr_t)(p-4); } /* The same for size 2 uncleared objects. */ @@ -79,7 +79,7 @@ p[0] = (word)(p-2); p[2] = (word)p; } - return((ptr_t)(p-2)); + return (ptr_t)(p-2); } /* The same for size 4 uncleared objects. */ @@ -96,7 +96,7 @@ p[0] = (word)(p-4); p[4] = (word)p; } - return((ptr_t)(p-4)); + return (ptr_t)(p-4); } #endif /* !SMALL_CONFIG */ @@ -161,7 +161,7 @@ GC_INNER ptr_t GC_build_fl(struct hblk *h, size_t sz, GC_bool clear, /* Put p (which is now head of list of objects in *h) as first */ /* pointer in the appropriate free list for this size. */ *(ptr_t *)h = list; - return ((ptr_t)p); + return (ptr_t)p; } /* Allocate a new heapblock for small objects of size gran granules. */ @@ -55,9 +55,7 @@ GC_INNER void GC_register_displacement_inner(size_t offset) GC_ASSERT(I_HOLD_LOCK()); if (granules > BYTES_TO_GRANULES(MAXOBJBYTES)) granules = 0; - if (GC_obj_map[granules] != 0) { - return(TRUE); - } + if (GC_obj_map[granules] != 0) return TRUE; new_map = (unsigned short *)GC_scratch_alloc(OBJ_MAP_LEN * sizeof(short)); if (EXPECT(NULL == new_map, FALSE)) return FALSE; @@ -75,7 +73,7 @@ GC_INNER void GC_register_displacement_inner(size_t offset) } } GC_obj_map[granules] = new_map; - return(TRUE); + return TRUE; } #endif /* MARK_BIT_PER_GRANULE */ @@ -580,7 +580,7 @@ GC_INNER const char * GC_get_maps(void) # endif sigaction(SIGSEGV, &old_segv_act, 0); - return(result); + return result; } # endif /* GC_OPENBSD_UTHREADS */ @@ -618,7 +618,7 @@ GC_INNER const char * GC_get_maps(void) } sigaction(SIGSEGV, &old_segv_act, 0); - return(result); + return result; } #endif /* OPENBSD */ @@ -779,11 +779,8 @@ GC_INNER size_t GC_page_size = 0; if (result != sizeof(buf)) ABORT("Weird VirtualQuery result"); if (base != 0) *base = (ptr_t)(buf.AllocationBase); protect = (buf.Protect & ~(PAGE_GUARD | PAGE_NOCACHE)); - if (!is_writable(protect)) { - return(0); - } - if (buf.State != MEM_COMMIT) return(0); - return(buf.RegionSize); + if (!is_writable(protect) || buf.State != MEM_COMMIT) return 0; + return buf.RegionSize; } GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *sb) @@ -1027,7 +1024,7 @@ GC_INNER size_t GC_page_size = 0; if (!up) { result += MIN_PAGE_SIZE; } - return(result); + return result; } void * GC_find_limit(void * p, int up) @@ -1349,14 +1346,14 @@ GC_INNER size_t GC_page_size = 0; # error None of HEURISTIC* and *STACKBOTTOM defined! # endif # if defined(STACK_GROWS_DOWN) && !defined(CPPCHECK) - if (result == 0) + if (NULL == result) result = (ptr_t)(signed_word)(-sizeof(ptr_t)); # endif # endif # if !defined(CPPCHECK) GC_ASSERT((word)GC_approx_sp() HOTTER_THAN (word)result); # endif - return(result); + return result; } # define GET_MAIN_STACKBASE_SPECIAL #endif /* !AMIGA, !HAIKU, !OPENBSD, !OS2, !Windows */ @@ -2054,7 +2051,7 @@ void GC_register_data_segments(void) /* As above, we go to plan B */ result = (ptr_t)GC_find_limit(DATAEND, FALSE); } - return(result); + return result; } #endif /* DATASTART_USES_BSDGETDATASTART */ @@ -2271,7 +2268,7 @@ void GC_register_data_segments(void) if (((word)result % HBLKSIZE) != 0) ABORT( "GC_unix_get_mem: Memory returned by mmap is not aligned to HBLKSIZE."); - return((ptr_t)result); + return (ptr_t)result; } # endif /* !MSWIN_XBOX1 */ @@ -2323,7 +2320,7 @@ STATIC ptr_t GC_unix_sbrk_get_mem(size_t bytes) # ifdef IRIX5 __UNLOCK_MALLOC(); # endif - return(result); + return result; } ptr_t GC_unix_get_mem(size_t bytes) @@ -2366,12 +2363,12 @@ void * os2_alloc(size_t bytes) if (DosAllocMem(&result, bytes, (PAG_READ | PAG_WRITE | PAG_COMMIT) | (GC_pages_executable ? PAG_EXECUTE : 0)) != NO_ERROR) { - return(0); + return NULL; } /* FIXME: What's the purpose of this recursion? (Probably, if */ /* DosAllocMem returns memory at 0 address then just retry once.) */ - if (result == 0) return(os2_alloc(bytes)); - return(result); + if (NULL == result) return os2_alloc(bytes); + return result; } # endif /* OS2 */ @@ -2435,8 +2432,7 @@ void * os2_alloc(size_t bytes) if (HBLKDISPL(result) != 0) ABORT("Bad VirtualAlloc result"); GC_heap_lengths[i] += bytes; } - - return(result); + return result; } #elif (defined(USE_WINALLOC) && !defined(MSWIN_XBOX1)) || defined(CYGWIN32) @@ -2515,8 +2511,8 @@ void * os2_alloc(size_t bytes) /* If I read the documentation correctly, this can */ /* only happen if HBLKSIZE > 64 KB or not a power of 2. */ if (GC_n_heap_bases >= MAX_HEAP_SECTS) ABORT("Too many heap sections"); - if (0 != result) GC_heap_bases[GC_n_heap_bases++] = result; - return(result); + if (result != NULL) GC_heap_bases[GC_n_heap_bases++] = result; + return result; } #endif /* USE_WINALLOC || CYGWIN32 */ @@ -2827,7 +2823,7 @@ PCR_ERes GC_push_thread_stack(PCR_Th_T *t, PCR_Any dummy) info.ti_stkLow = info.ti_stkHi = 0; result = PCR_ThCtl_GetInfo(t, &info); GC_push_all_stack((ptr_t)(info.ti_stkLow), (ptr_t)(info.ti_stkHi)); - return(result); + return result; } /* Push the contents of an old object. We treat this as stack */ @@ -2836,7 +2832,7 @@ PCR_ERes GC_push_thread_stack(PCR_Th_T *t, PCR_Any dummy) PCR_ERes GC_push_old_obj(void *p, size_t size, PCR_Any data) { GC_push_all_stack((ptr_t)p, (ptr_t)p + size); - return(PCR_ERes_okay); + return PCR_ERes_okay; } extern struct PCR_MM_ProcsRep * GC_old_allocator; @@ -3354,7 +3350,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void) ABORT_ARG1("Unexpected segmentation fault outside heap", " at %p", (void *)addr); # else - return(EXCEPTION_CONTINUE_SEARCH); + return EXCEPTION_CONTINUE_SEARCH; # endif } else { /* @@ -3363,10 +3359,10 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void) * if so call it using that style. */ # if defined(MSWIN32) || defined(MSWINCE) - return((*old_handler)(exc_info)); + return (*old_handler)(exc_info); # else if (used_si) - ((SIG_HNDLR_PTR)old_handler) (sig, si, raw_sc); + ((SIG_HNDLR_PTR)old_handler)(sig, si, raw_sc); else /* FIXME: should pass nonstandard args as well. */ ((PLAIN_HNDLR_PTR)(signed_word)old_handler)(sig); @@ -3394,7 +3390,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void) /* The write may not take place before dirty bits are read. */ /* But then we'll fault again ... */ # if defined(MSWIN32) || defined(MSWINCE) - return(EXCEPTION_CONTINUE_EXECUTION); + return EXCEPTION_CONTINUE_EXECUTION; # else return; # endif @@ -4414,7 +4410,7 @@ catch_exception_raise_state(mach_port_name_t exception_port GC_ATTR_UNUSED, thread_state_t new_state GC_ATTR_UNUSED, int new_stateCnt GC_ATTR_UNUSED) { ABORT_RET("Unexpected catch_exception_raise_state invocation"); - return(KERN_INVALID_ARGUMENT); + return KERN_INVALID_ARGUMENT; } GC_API_OSCALL kern_return_t @@ -4427,7 +4423,7 @@ catch_exception_raise_state_identity( thread_state_t new_state GC_ATTR_UNUSED, int new_stateCnt GC_ATTR_UNUSED) { ABORT_RET("Unexpected catch_exception_raise_state_identity invocation"); - return(KERN_INVALID_ARGUMENT); + return KERN_INVALID_ARGUMENT; } #define MAX_EXCEPTION_PORTS 16 diff --git a/pthread_support.c b/pthread_support.c index 2ae5c208..9b3cb171 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -615,7 +615,7 @@ STATIC GC_thread GC_new_thread(pthread_t id) } else { result = (struct GC_Thread_Rep *) GC_INTERNAL_MALLOC(sizeof(struct GC_Thread_Rep), NORMAL); - if (result == 0) return(0); + if (NULL == result) return NULL; } result -> id = id; # ifdef USE_TKILL_ON_ANDROID @@ -630,7 +630,7 @@ STATIC GC_thread GC_new_thread(pthread_t id) GC_ASSERT(0 == result -> flags); if (EXPECT(result != &first_thread, TRUE)) GC_dirty(result); - return(result); + return result; } /* Delete a thread from GC_threads. We assume it is there. */ @@ -716,8 +716,9 @@ GC_INNER GC_thread GC_lookup_thread(pthread_t id) { GC_thread p = GC_threads[THREAD_TABLE_INDEX(id)]; - while (p != 0 && !THREAD_EQUAL(p -> id, id)) p = p -> next; - return(p); + while (p != NULL && !THREAD_EQUAL(p -> id, id)) + p = p -> next; + return p; } #ifndef GC_NO_FINALIZATION @@ -1036,13 +1037,14 @@ STATIC void GC_remove_all_threads_but_me(void) status = dg_sys_info((long int *) &pm_sysinfo, DG_SYS_INFO_PM_INFO_TYPE, DG_SYS_INFO_PM_CURRENT_VERSION); - if (status < 0) + if (status < 0) { /* set -1 for error */ numCpus = -1; - else + } else { /* Active CPUs */ numCpus = pm_sysinfo.idle_vp_count; - return(numCpus); + } + return numCpus; } #elif defined(GC_DARWIN_THREADS) || defined(GC_FREEBSD_THREADS) \ @@ -1519,7 +1521,7 @@ GC_INNER void GC_init_parallel(void) ABORT("sigdelset failed"); set = &fudged_set; } - return(REAL_FUNC(pthread_sigmask)(how, set, oset)); + return REAL_FUNC(pthread_sigmask)(how, set, oset); } #endif /* !GC_NO_PTHREAD_SIGMASK */ @@ -2264,7 +2266,7 @@ GC_INNER_PTHRSTART GC_thread GC_start_rtn_prepare_thread( RESTORE_CANCEL(cancel_state); } sem_destroy(&si.registered); - return(result); + return result; } #endif /* !SN_TARGET_ORBIS && !SN_TARGET_PSP2 */ @@ -45,12 +45,12 @@ GC_API void * GC_CALL GC_same_obj(void *p, void *q) if (!EXPECT(GC_is_initialized, TRUE)) GC_init(); hhdr = HDR((word)p); - if (hhdr == 0) { + if (NULL == hhdr) { if (divHBLKSZ((word)p) != divHBLKSZ((word)q) - && HDR((word)q) != 0) { + && HDR((word)q) != NULL) { goto fail; } - return(p); + return p; } /* If it's a pointer to the middle of a large object, move it */ /* to the beginning. */ @@ -66,7 +66,7 @@ GC_API void * GC_CALL GC_same_obj(void *p, void *q) || (word)q < (word)h) { goto fail; } - return(p); + return p; } sz = hhdr -> hb_sz; if (sz > MAXOBJBYTES) { @@ -94,10 +94,10 @@ GC_API void * GC_CALL GC_same_obj(void *p, void *q) if ((word)q >= (word)limit || (word)q < (word)base) { goto fail; } - return(p); + return p; fail: (*GC_same_obj_print_proc)((ptr_t)p, (ptr_t)q); - return(p); + return p; } STATIC void GC_CALLBACK GC_default_is_valid_displacement_print_proc (void *p) @@ -125,7 +125,7 @@ GC_API void * GC_CALL GC_is_valid_displacement(void *p) if (!EXPECT(GC_is_initialized, TRUE)) GC_init(); if (NULL == p) return NULL; hhdr = HDR((word)p); - if (hhdr == 0) return(p); + if (NULL == hhdr) return p; h = HBLKPTR(p); if (GC_all_interior_pointers) { while (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { @@ -144,10 +144,10 @@ GC_API void * GC_CALL GC_is_valid_displacement(void *p) && !IS_FORWARDING_ADDR_OR_NIL(HDR(h + 1)))) { goto fail; } - return(p); + return p; fail: (*GC_is_valid_displacement_print_proc)((ptr_t)p); - return(p); + return p; } STATIC void GC_CALLBACK GC_default_is_visible_print_proc(void * p) @@ -165,15 +165,15 @@ void (GC_CALLBACK *GC_is_visible_print_proc)(void * p) = # ifdef STACK_GROWS_DOWN if ((word)p >= (word)GC_approx_sp() && (word)p < (word)GC_stackbottom) { - return(TRUE); + return TRUE; } # else if ((word)p <= (word)GC_approx_sp() && (word)p > (word)GC_stackbottom) { - return(TRUE); + return TRUE; } # endif - return(FALSE); + return FALSE; } #endif /* !THREADS */ @@ -193,24 +193,23 @@ GC_API void * GC_CALL GC_is_visible(void *p) if (!EXPECT(GC_is_initialized, TRUE)) GC_init(); # ifdef THREADS hhdr = HDR((word)p); - if (hhdr != 0 && GC_base(p) == 0) { + if (hhdr != NULL && NULL == GC_base(p)) { goto fail; } else { /* May be inside thread stack. We can't do much. */ - return(p); + return p; } # else /* Check stack first: */ - if (GC_on_stack(p)) return(p); + if (GC_on_stack(p)) return p; hhdr = HDR((word)p); - if (hhdr == 0) { - if (GC_is_static_root(p)) return(p); + if (NULL == hhdr) { + if (GC_is_static_root(p)) return p; /* Else do it again correctly: */ # if defined(DYNAMIC_LOADING) || defined(MSWIN32) \ || defined(MSWINCE) || defined(CYGWIN32) || defined(PCR) GC_register_dynamic_libraries(); - if (GC_is_static_root(p)) - return(p); + if (GC_is_static_root(p)) return p; # endif goto fail; } else { @@ -249,33 +248,34 @@ GC_API void * GC_CALL GC_is_visible(void *p) } goto retry; } - return(p); + return p; } # endif fail: (*GC_is_visible_print_proc)((ptr_t)p); - return(p); + return p; } -GC_API void * GC_CALL GC_pre_incr (void **p, ptrdiff_t how_much) +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); if (!GC_all_interior_pointers) { - (void) GC_is_valid_displacement(result); + (void)GC_is_valid_displacement(result); } - return (*p = result); + *p = result; + return result; /* updated pointer */ } -GC_API void * GC_CALL GC_post_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); if (!GC_all_interior_pointers) { - (void) GC_is_valid_displacement(result); + (void)GC_is_valid_displacement(result); } *p = result; - return(initial); + return initial; /* original *p */ } @@ -138,7 +138,7 @@ GC_INNER void GC_print_all_errors(void) /* objects. This does not require the block to be in physical memory. */ GC_INNER GC_bool GC_block_empty(hdr *hhdr) { - return (hhdr -> hb_n_marks == 0); + return 0 == hhdr -> hb_n_marks; } STATIC GC_bool GC_block_nearly_full(hdr *hhdr, word sz) @@ -236,7 +236,7 @@ STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, hdr *hhdr, word sz, bit_no += MARK_BIT_OFFSET(sz); } *count += n_bytes_found; - return(list); + return list; } #ifdef ENABLE_DISCLAIM @@ -509,7 +509,7 @@ unsigned GC_n_set_marks(hdr *hhdr) result += hhdr -> hb_marks[i]; } GC_ASSERT(hhdr -> hb_marks[limit]); /* the one set past the end */ - return(result); + return result; } #else @@ -747,7 +747,7 @@ GC_INNER GC_bool GC_reclaim_all(GC_stop_func stop_func, GC_bool ignore_old) for (sz = 1; sz <= MAXOBJGRANULES; sz++) { for (rlh = rlp + sz; (hbp = *rlh) != NULL; ) { if (stop_func != (GC_stop_func)0 && (*stop_func)()) { - return(FALSE); + return FALSE; } hhdr = HDR(hbp); *rlh = hhdr -> hb_next; @@ -772,7 +772,7 @@ GC_INNER GC_bool GC_reclaim_all(GC_stop_func stop_func, GC_bool ignore_old) NS_FRAC_TIME_DIFF(done_time, start_time)); } # endif - return(TRUE); + return TRUE; } #if !defined(EAGER_SWEEP) && defined(ENABLE_DISCLAIM) diff --git a/tests/cpp.cc b/tests/cpp.cc index 8db43a10..5c152513 100644 --- a/tests/cpp.cc +++ b/tests/cpp.cc @@ -412,7 +412,7 @@ void* Undisguise( GC_word i ) { F::Test();} x = *xptr; - my_assert (29 == x[0]); - GC_printf( "The test appears to have succeeded.\n" ); - return( 0 ); + my_assert(29 == x[0]); + GC_printf("The test appears to have succeeded.\n"); + return 0; } diff --git a/tests/gctest.c b/tests/gctest.c index b394ce2a..a6a91c68 100644 --- a/tests/gctest.c +++ b/tests/gctest.c @@ -380,7 +380,7 @@ struct GC_ms_entry * fake_gcj_mark_proc(word * addr, mark_stack_ptr = GC_MARK_AND_PUSH( (void *)(x -> sexpr_car), mark_stack_ptr, mark_stack_limit, (void * *)&(x -> sexpr_car)); - return(mark_stack_ptr); + return mark_stack_ptr; } #endif /* GC_GCJ_SUPPORT */ @@ -447,9 +447,9 @@ sexpr small_cons_uncollectable (sexpr x, sexpr y) sexpr reverse1(sexpr x, sexpr y) { if (is_nil(x)) { - return(y); + return y; } else { - return( reverse1(cdr(x), cons(car(x), y)) ); + return reverse1(cdr(x), cons(car(x), y)); } } @@ -458,13 +458,13 @@ sexpr reverse(sexpr x) # ifdef TEST_WITH_SYSTEM_MALLOC GC_noop1(GC_HIDE_POINTER(malloc(100000))); # endif - return( reverse1(x, nil) ); + return reverse1(x, nil); } sexpr ints(int low, int up) { if (low > up) { - return(nil); + return nil; } else { return small_cons(small_cons_leaf(low), ints(low + 1, up)); } @@ -475,23 +475,23 @@ sexpr ints(int low, int up) sexpr gcj_reverse1(sexpr x, sexpr y) { if (is_nil(x)) { - return(y); + return y; } else { - return( gcj_reverse1(cdr(x), gcj_cons(car(x), y)) ); + return gcj_reverse1(cdr(x), gcj_cons(car(x), y)); } } sexpr gcj_reverse(sexpr x) { - return( gcj_reverse1(x, nil) ); + return gcj_reverse1(x, nil); } sexpr gcj_ints(int low, int up) { if (low > up) { - return(nil); + return nil; } else { - return(gcj_cons(gcj_cons(INT_TO_SEXPR(low), nil), gcj_ints(low+1, up))); + return gcj_cons(gcj_cons(INT_TO_SEXPR(low), nil), gcj_ints(low+1, up)); } } #endif /* GC_GCJ_SUPPORT */ @@ -501,10 +501,10 @@ sexpr gcj_ints(int low, int up) sexpr uncollectable_ints(int low, int up) { if (low > up) { - return(nil); + return nil; } else { - return(small_cons_uncollectable(small_cons_leaf(low), - uncollectable_ints(low+1, up))); + return small_cons_uncollectable(small_cons_leaf(low), + uncollectable_ints(low+1, up)); } } @@ -956,7 +956,7 @@ tn * mktree(int n) CHECK_OUT_OF_MEMORY(live_indicators); } # endif - if (n == 0) return(0); + if (0 == n) return NULL; CHECK_OUT_OF_MEMORY(result); result -> level = n; result -> lchild = left = mktree(n - 1); @@ -1069,7 +1069,7 @@ tn * mktree(int n) GC_END_STUBBORN_CHANGE(result); GC_reachable_here(left); GC_reachable_here(right); - return(result); + return result; } void chktree(tn *t, int n) @@ -1104,7 +1104,7 @@ void * alloc8bytes(void) { # if defined(SMALL_CONFIG) || defined(GC_DEBUG) AO_fetch_and_add1(&collectable_count); - return(GC_MALLOC(8)); + return GC_MALLOC(8); # else void ** my_free_list_ptr; void * my_free_list; @@ -1129,7 +1129,7 @@ void * alloc8bytes(void) GC_PTR_STORE_AND_DIRTY(my_free_list_ptr, next); GC_NEXT(my_free_list) = 0; AO_fetch_and_add1(&collectable_count); - return(my_free_list); + return my_free_list; # endif } @@ -2153,7 +2153,7 @@ void enable_incremental_mode(void) # ifdef RTEMS exit(0); # else - return(0); + return 0; # endif } # endif /* !GC_WIN32_THREADS && !GC_PTHREADS */ @@ -2321,7 +2321,7 @@ DWORD __stdcall thr_window(void * arg GC_ATTR_UNUSED) UNTESTED(GC_endthreadex); # endif # endif - return(0); + return 0; } #endif /* GC_WIN32_THREADS */ @@ -2356,7 +2356,7 @@ int test(void) } run_single_threaded_test(); check_heap_stats(); - return(0); + return 0; } #endif @@ -2366,7 +2366,7 @@ int test(void) void * thr_run_one_test(void * arg GC_ATTR_UNUSED) { run_one_test(); - return(0); + return 0; } #ifdef GC_DEBUG @@ -2529,6 +2529,6 @@ int main(void) pthread_win32_thread_detach_np (); pthread_win32_process_detach_np (); # endif - return(0); + return 0; } #endif /* GC_PTHREADS */ diff --git a/tools/if_mach.c b/tools/if_mach.c index 2ddad6f2..662c058f 100644 --- a/tools/if_mach.c +++ b/tools/if_mach.c @@ -16,9 +16,9 @@ int main(int argc, char **argv) { if (argc < 4) goto Usage; - if (strcmp(MACH_TYPE, argv[1]) != 0) return(0); + if (strcmp(MACH_TYPE, argv[1]) != 0) return 0; if (strlen(OS_TYPE) > 0 && strlen(argv[2]) > 0 - && strcmp(OS_TYPE, argv[2]) != 0) return(0); + && strcmp(OS_TYPE, argv[2]) != 0) return 0; fprintf(stderr, "^^^^Starting command^^^^\n"); fflush(stdout); execvp(TRUSTED_STRING(argv[3]), (EXECV_ARGV_T)(argv + 3)); @@ -28,5 +28,5 @@ Usage: fprintf(stderr, "Usage: %s mach_type os_type command\n", argv[0]); fprintf(stderr, "Currently mach_type = %s, os_type = %s\n", MACH_TYPE, OS_TYPE); - return(1); + return 1; } diff --git a/tools/if_not_there.c b/tools/if_not_there.c index d388d04b..ab51d5cb 100644 --- a/tools/if_not_there.c +++ b/tools/if_not_there.c @@ -31,28 +31,28 @@ int main(int argc, char **argv) f = fopen(fname, "rb"); if (f != NULL) { fclose(f); - return(0); + return 0; } f = fopen(fname, "r"); if (f != NULL) { fclose(f); - return(0); + return 0; } #ifdef __DJGPP__ if ((d = opendir(fname)) != 0) { closedir(d); - return(0); + return 0; } #endif printf("^^^^Starting command^^^^\n"); fflush(stdout); if (argc == 2) - return(2); /* the file does not exist but no command is given */ + return 2; /* the file does not exist but no command is given */ execvp(TRUSTED_STRING(argv[2]), (EXECV_ARGV_T)(argv + 2)); exit(1); Usage: fprintf(stderr, "Usage: %s file_name [command]\n", argv[0]); - return(1); + return 1; } diff --git a/tools/setjmp_t.c b/tools/setjmp_t.c index 419bbb32..6ca089de 100644 --- a/tools/setjmp_t.c +++ b/tools/setjmp_t.c @@ -43,7 +43,7 @@ int getpagesize(void) fprintf(stderr, "DosQuerySysInfo failed\n"); result[0] = 4096; } - return((int)(result[0])); + return (int)result[0]; } #elif defined(MSWIN32) || defined(MSWINCE) || defined(CYGWIN32) @@ -155,10 +155,10 @@ int main(void) printf("Parallel marking enabled.\n"); # endif (void)g(x); - return(0); + return 0; } int g(int x) { - return(x); + return x; } @@ -123,7 +123,7 @@ STATIC signed_word GC_add_ext_descriptor(const word * bm, word nbits) } else { UNLOCK(); new_size = 2 * ed_size; - if (new_size > MAX_ENV) return(-1); + if (new_size > MAX_ENV) return -1; } newExtD = (typed_ext_descr_t*)GC_malloc_atomic(new_size * sizeof(typed_ext_descr_t)); @@ -153,7 +153,7 @@ STATIC signed_word GC_add_ext_descriptor(const word * bm, word nbits) GC_ext_descriptors[result + i].ed_continued = FALSE; GC_avail_descr += nwords; UNLOCK(); - return(result); + return result; } /* Table of bitmap descriptors for n word long all pointer objects. */ @@ -170,7 +170,7 @@ STATIC GC_descr GC_double_descr(GC_descr descriptor, word nwords) descriptor = GC_bm_table[BYTES_TO_WORDS((word)descriptor)]; } descriptor |= (descriptor & ~GC_DS_TAGS) >> nwords; - return(descriptor); + return descriptor; } STATIC complex_descriptor * @@ -208,20 +208,20 @@ STATIC int GC_make_array_descriptor(size_t nelements, size_t size, if ((descriptor & GC_DS_TAGS) == GC_DS_LENGTH) { if (descriptor == (GC_descr)size) { *simple_d = nelements * descriptor; - return(SIMPLE); + return SIMPLE; } else if ((word)descriptor == 0) { *simple_d = (GC_descr)0; - return(SIMPLE); + return SIMPLE; } } if (nelements <= OPT_THRESHOLD) { if (nelements <= 1) { if (nelements == 1) { *simple_d = descriptor; - return(SIMPLE); + return SIMPLE; } else { *simple_d = (GC_descr)0; - return(SIMPLE); + return SIMPLE; } } } else if (size <= BITMAP_BITS/2 @@ -233,13 +233,13 @@ STATIC int GC_make_array_descriptor(size_t nelements, size_t size, BYTES_TO_WORDS(size)), simple_d, complex_d, leaf); if ((nelements & 1) == 0) { - return(result); + return result; } else { struct LeafDescriptor * one_element = (struct LeafDescriptor *) GC_malloc_atomic(sizeof(struct LeafDescriptor)); - if (result == NO_MEM || one_element == 0) return(NO_MEM); + if (NO_MEM == result || NULL == one_element) return NO_MEM; one_element -> ld_tag = LEAF_TAG; one_element -> ld_size = size; one_element -> ld_nelements = 1; @@ -250,7 +250,7 @@ STATIC int GC_make_array_descriptor(size_t nelements, size_t size, struct LeafDescriptor * beginning = (struct LeafDescriptor *) GC_malloc_atomic(sizeof(struct LeafDescriptor)); - if (beginning == 0) return(NO_MEM); + if (NULL == beginning) return NO_MEM; beginning -> ld_tag = LEAF_TAG; beginning -> ld_size = size; beginning -> ld_nelements = 1; @@ -265,7 +265,7 @@ STATIC int GC_make_array_descriptor(size_t nelements, size_t size, struct LeafDescriptor * beginning = (struct LeafDescriptor *) GC_malloc_atomic(sizeof(struct LeafDescriptor)); - if (beginning == 0) return(NO_MEM); + if (NULL == beginning) return NO_MEM; beginning -> ld_tag = LEAF_TAG; beginning -> ld_size = leaf -> ld_size; beginning -> ld_nelements = leaf -> ld_nelements; @@ -281,14 +281,14 @@ STATIC int GC_make_array_descriptor(size_t nelements, size_t size, (complex_descriptor *)one_element); break; } - return(COMPLEX); + return COMPLEX; } } leaf -> ld_size = size; leaf -> ld_nelements = nelements; leaf -> ld_descriptor = descriptor; - return(LEAF); + return LEAF; } STATIC complex_descriptor * @@ -309,7 +309,7 @@ GC_make_sequence_descriptor(complex_descriptor *first, REACHABLE_AFTER_DIRTY(first); REACHABLE_AFTER_DIRTY(second); } - return((complex_descriptor *)result); + return (complex_descriptor *)result; } STATIC mse * GC_typed_mark_proc(word * addr, mse * mark_stack_ptr, @@ -375,7 +375,7 @@ STATIC mse * GC_typed_mark_proc(word * addr, mse * mark_stack_ptr, mark_stack_ptr -> mse_descr.w = GC_MAKE_PROC(GC_typed_mark_proc_index, env + 1); } - return(mark_stack_ptr); + return mark_stack_ptr; } /* Return the size of the object described by d. It would be faster to */ @@ -385,13 +385,13 @@ STATIC word GC_descr_obj_size(complex_descriptor *d) { switch(d -> TAG) { case LEAF_TAG: - return(d -> ld.ld_nelements * d -> ld.ld_size); + return d -> ld.ld_nelements * d -> ld.ld_size; case ARRAY_TAG: - return(d -> ad.ad_nelements - * GC_descr_obj_size(d -> ad.ad_element_descr)); + return d -> ad.ad_nelements + * GC_descr_obj_size(d -> ad.ad_element_descr); case SEQUENCE_TAG: - return(GC_descr_obj_size(d -> sd.sd_first) - + GC_descr_obj_size(d -> sd.sd_second)); + return GC_descr_obj_size(d -> sd.sd_first) + + GC_descr_obj_size(d -> sd.sd_second); default: ABORT_RET("Bad complex descriptor"); return 0; @@ -414,7 +414,7 @@ STATIC mse * GC_push_complex_descriptor(word *addr, complex_descriptor *d, GC_descr descr = d -> ld.ld_descriptor; nelements = d -> ld.ld_nelements; - if (msl - msp <= (ptrdiff_t)nelements) return(0); + if (msl - msp <= (ptrdiff_t)nelements) return NULL; sz = d -> ld.ld_size; for (i = 0; i < nelements; i++) { msp++; @@ -422,7 +422,7 @@ STATIC mse * GC_push_complex_descriptor(word *addr, complex_descriptor *d, msp -> mse_descr.w = descr; current += sz; } - return(msp); + return msp; } case ARRAY_TAG: { @@ -433,25 +433,25 @@ STATIC mse * GC_push_complex_descriptor(word *addr, complex_descriptor *d, for (i = 0; i < nelements; i++) { msp = GC_push_complex_descriptor((word *)current, descr, msp, msl); - if (msp == 0) return(0); + if (NULL == msp) return NULL; current += sz; } - return(msp); + return msp; } case SEQUENCE_TAG: { sz = GC_descr_obj_size(d -> sd.sd_first); msp = GC_push_complex_descriptor((word *)current, d -> sd.sd_first, msp, msl); - if (msp == 0) return(0); + if (NULL == msp) return NULL; current += sz; msp = GC_push_complex_descriptor((word *)current, d -> sd.sd_second, msp, msl); - return(msp); + return msp; } default: ABORT_RET("Bad complex descriptor"); - return 0; + return NULL; } } @@ -466,9 +466,9 @@ STATIC mse * GC_array_mark_proc(word * addr, mse * mark_stack_ptr, mse * orig_mark_stack_ptr = mark_stack_ptr; mse * new_mark_stack_ptr; - if (descr == 0) { + if (NULL == descr) { /* Found a reference to a free list entry. Ignore it. */ - return(orig_mark_stack_ptr); + return orig_mark_stack_ptr; } /* In use counts were already updated when array descriptor was */ /* pushed. Here we only replace it by subobject descriptors, so */ @@ -529,7 +529,7 @@ GC_API GC_descr GC_CALL GC_make_descriptor(const GC_word * bm, size_t len) while (last_set_bit >= 0 && !GC_get_bit(bm, last_set_bit)) last_set_bit--; - if (last_set_bit < 0) return(0 /* no pointers */); + if (last_set_bit < 0) return 0; /* no pointers */ # if ALIGNMENT == CPP_WORDSZ/8 { @@ -542,7 +542,7 @@ GC_API GC_descr GC_CALL GC_make_descriptor(const GC_word * bm, size_t len) } if (i == last_set_bit) { /* An initial section contains all pointers. Use length descriptor. */ - return (WORDS_TO_BYTES(last_set_bit+1) | GC_DS_LENGTH); + return WORDS_TO_BYTES(last_set_bit + 1) | GC_DS_LENGTH; } } # endif @@ -559,7 +559,7 @@ GC_API GC_descr GC_CALL GC_make_descriptor(const GC_word * bm, size_t len) result |= GC_DS_BITMAP; } else { signed_word index = GC_add_ext_descriptor(bm, (word)last_set_bit + 1); - if (index == -1) return(WORDS_TO_BYTES(last_set_bit+1) | GC_DS_LENGTH); + if (index == -1) return WORDS_TO_BYTES(last_set_bit+1) | GC_DS_LENGTH; /* Out of memory: use conservative */ /* approximation. */ result = GC_MAKE_PROC(GC_typed_mark_proc_index, (word)index); @@ -650,7 +650,8 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_calloc_explicitly_typed(size_t n, return (*GC_get_oom_fn())(GC_SIZE_MAX); /* n*lb overflow */ lb *= n; switch(descr_type) { - case NO_MEM: return(0); + case NO_MEM: + return NULL; case SIMPLE: return GC_malloc_explicitly_typed(lb, simple_descr); case LEAF: diff --git a/win32_threads.c b/win32_threads.c index ea40c3a1..2c838fa1 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -381,7 +381,7 @@ STATIC GC_thread GC_new_thread(DWORD id) GC_ASSERT(!GC_win32_dll_threads); result = (struct GC_Thread_Rep *) GC_INTERNAL_MALLOC(sizeof(struct GC_Thread_Rep), NORMAL); - if (result == 0) return(0); + if (NULL == result) return NULL; } /* result -> id = id; Done by caller. */ result -> tm.next = GC_threads[hv]; @@ -392,7 +392,7 @@ STATIC GC_thread GC_new_thread(DWORD id) GC_ASSERT(result -> thread_blocked_sp == NULL); if (EXPECT(result != &first_thread, TRUE)) GC_dirty(result); - return(result); + return result; } GC_INNER GC_bool GC_in_thread_creation = FALSE; @@ -567,8 +567,9 @@ STATIC GC_thread GC_lookup_thread_inner(DWORD thread_id) GC_thread p = GC_threads[THREAD_TABLE_INDEX(thread_id)]; GC_ASSERT(I_HOLD_LOCK()); - while (p != 0 && p -> id != thread_id) p = p -> tm.next; - return(p); + while (p != NULL && p -> id != thread_id) + p = p -> tm.next; + return p; } } @@ -1532,7 +1533,7 @@ STATIC ptr_t GC_get_stack_min(ptr_t s) last_address = bottom - 1; } while ((last_info.Protect & PAGE_READWRITE) && !(last_info.Protect & PAGE_GUARD)); - return(bottom); + return bottom; } /* Return true if the page at s has protections appropriate */ @@ -2998,7 +2999,7 @@ GC_INNER void GC_thr_init(void) if (result) { /* failure */ GC_free(si); } - return(result); + return result; } STATIC void * GC_CALLBACK GC_pthread_start_inner(struct GC_stack_base *sb, @@ -3048,7 +3049,7 @@ GC_INNER void GC_thr_init(void) GC_log_printf("thread %p(0x%x) returned from start routine\n", (void *)GC_PTHREAD_PTRVAL(pthread_id), (int)thread_id); # endif - return(result); + return result; } STATIC void * GC_pthread_start(void * arg) |