GC_API void * GC_CALL GC_generate_random_heap_address(void)
{
size_t i;
+ size_t size;
word heap_offset = RANDOM();
+
if (GC_heapsize > RAND_MAX) {
heap_offset *= RAND_MAX;
heap_offset += RANDOM();
/* This doesn't yield a uniform distribution, especially if */
/* e.g. RAND_MAX = 1.5* GC_heapsize. But for typical cases, */
/* it's not too bad. */
- for (i = 0; i < GC_n_heap_sects; ++ i) {
- size_t size = GC_heap_sects[i].hs_bytes;
+ for (i = 0;; ++i) {
+ if (i >= GC_n_heap_sects)
+ ABORT("GC_generate_random_heap_address: size inconsistency");
+
+ size = GC_heap_sects[i].hs_bytes;
if (heap_offset < size) {
- return GC_heap_sects[i].hs_start + heap_offset;
+ break;
} else {
heap_offset -= size;
}
}
- ABORT("GC_generate_random_heap_address: size inconsistency");
- /*NOTREACHED*/
- return 0;
+ return GC_heap_sects[i].hs_start + heap_offset;
}
/* Generate a random address inside a valid marked heap object. */
{
switch(GC_mark_state) {
case MS_NONE:
- return(FALSE);
+ break;
case MS_PUSH_RESCUERS:
if (GC_mark_stack_top
/* in the future. */
GC_mark_stack_too_small = TRUE;
MARK_FROM_MARK_STACK();
- return(FALSE);
+ break;
} else {
scan_ptr = GC_push_next_marked_dirty(scan_ptr);
if (scan_ptr == 0) {
}
}
}
- return(FALSE);
+ break;
case MS_PUSH_UNCOLLECTABLE:
if (GC_mark_stack_top
if (GC_parallel) GC_mark_stack_too_small = TRUE;
# endif
MARK_FROM_MARK_STACK();
- return(FALSE);
+ break;
} else {
scan_ptr = GC_push_next_marked_uncollectable(scan_ptr);
if (scan_ptr == 0) {
}
}
}
- return(FALSE);
+ break;
case MS_ROOTS_PUSHED:
# ifdef PARALLEL_MARK
if (GC_mark_state == MS_ROOTS_PUSHED) {
GC_mark_state = MS_NONE;
return(TRUE);
- } else {
- return(FALSE);
}
+ break;
}
# endif
if (GC_mark_stack_top >= GC_mark_stack) {
MARK_FROM_MARK_STACK();
- return(FALSE);
+ break;
} else {
GC_mark_state = MS_NONE;
if (GC_mark_stack_too_small) {
case MS_PARTIALLY_INVALID:
if (!GC_objects_are_marked) {
GC_mark_state = MS_PUSH_UNCOLLECTABLE;
- return(FALSE);
+ break;
}
if (GC_mark_stack_top >= GC_mark_stack) {
MARK_FROM_MARK_STACK();
- return(FALSE);
+ break;
}
if (scan_ptr == 0 && GC_mark_state == MS_INVALID) {
/* About to start a heap scan for marked objects. */
GC_mark_state = MS_ROOTS_PUSHED;
}
}
- return(FALSE);
+ break;
+
default:
ABORT("GC_mark_some: bad state");
- return(FALSE);
}
+ return(FALSE);
}
#ifdef WRAP_MARK_SOME
} msg;
mach_msg_id_t id;
+ if ((word)arg == (word)-1) return 0; /* to make compiler happy */
+
# if defined(THREADS) && !defined(GC_NO_THREADS_DISCOVERY)
GC_darwin_register_mach_handler_thread(mach_thread_self());
# endif
}
} /* switch */
} /* for(;;) */
- /* NOT REACHED */
- return NULL;
}
/* All this SIGBUS code shouldn't be necessary. All protection faults should
/* This may run with the collector uninitialized. */
thread_id = GetCurrentThreadId();
if (parallel_initialized && GC_main_thread != thread_id) {
- /* Don't lock here. */
-# ifdef GC_ASSERTIONS
- sb_result =
-# endif
- GC_get_stack_base(&sb);
- GC_ASSERT(sb_result == GC_SUCCESS);
# if defined(THREAD_LOCAL_ALLOC) || defined(PARALLEL_MARK)
ABORT("Cannot initialize thread local cache from DllMain");
+# else
+ /* Don't lock here. */
+# ifdef GC_ASSERTIONS
+ sb_result =
+# endif
+ GC_get_stack_base(&sb);
+ GC_ASSERT(sb_result == GC_SUCCESS);
+ GC_register_my_thread_inner(&sb, thread_id);
# endif
- GC_register_my_thread_inner(&sb, thread_id);
} /* o.w. we already did it during GC_thr_init, called by GC_init */
break;