Skip to content

Commit

Permalink
gc: Don't expect sentinel when core is compiled without GC.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliott Slaughter committed Sep 7, 2012
1 parent 7823ad8 commit 578b036
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/libcore/gc.rs
Expand Up @@ -167,18 +167,33 @@ fn RootSet() -> RootSet {
LinearMap()
}

#[cfg(gc)]
fn expect_sentinel() -> bool { true }

#[cfg(nogc)]
fn expect_sentinel() -> bool { false }

// This should only be called from fail, as it will drop the roots
// which are *live* on the stack, rather than dropping those that are
// dead.
fn cleanup_stack_for_failure() {
unsafe {
// Leave a sentinel on the stack to mark the current
// frame. The stack walker will ignore any frames above the
// sentinel, thus avoiding collecting any memory being used by
// the stack walker itself.
// Leave a sentinel on the stack to mark the current frame. The
// stack walker will ignore any frames above the sentinel, thus
// avoiding collecting any memory being used by the stack walker
// itself.
//
// However, when core itself is not compiled with GC, then none of
// the functions in core will have GC metadata, which means we
// won't be able to find the sentinel root on the stack. In this
// case, we can safely skip the sentinel since we won't find our
// own stack roots on the stack anyway.
let sentinel_box = ~0;
let sentinel: **Word =
unsafe::reinterpret_cast(&ptr::addr_of(sentinel_box));
let sentinel: **Word = if expect_sentinel() {
unsafe::reinterpret_cast(&ptr::addr_of(sentinel_box))
} else {
ptr::null()
};

let mut roots = ~RootSet();
for walk_gc_roots(need_cleanup, sentinel) |root, tydesc| {
Expand Down

0 comments on commit 578b036

Please sign in to comment.