Skip to content

Commit 578b036

Browse files
author
Elliott Slaughter
committed
gc: Don't expect sentinel when core is compiled without GC.
1 parent 7823ad8 commit 578b036

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/libcore/gc.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,33 @@ fn RootSet() -> RootSet {
167167
LinearMap()
168168
}
169169

170+
#[cfg(gc)]
171+
fn expect_sentinel() -> bool { true }
172+
173+
#[cfg(nogc)]
174+
fn expect_sentinel() -> bool { false }
175+
170176
// This should only be called from fail, as it will drop the roots
171177
// which are *live* on the stack, rather than dropping those that are
172178
// dead.
173179
fn cleanup_stack_for_failure() {
174180
unsafe {
175-
// Leave a sentinel on the stack to mark the current
176-
// frame. The stack walker will ignore any frames above the
177-
// sentinel, thus avoiding collecting any memory being used by
178-
// the stack walker itself.
181+
// Leave a sentinel on the stack to mark the current frame. The
182+
// stack walker will ignore any frames above the sentinel, thus
183+
// avoiding collecting any memory being used by the stack walker
184+
// itself.
185+
//
186+
// However, when core itself is not compiled with GC, then none of
187+
// the functions in core will have GC metadata, which means we
188+
// won't be able to find the sentinel root on the stack. In this
189+
// case, we can safely skip the sentinel since we won't find our
190+
// own stack roots on the stack anyway.
179191
let sentinel_box = ~0;
180-
let sentinel: **Word =
181-
unsafe::reinterpret_cast(&ptr::addr_of(sentinel_box));
192+
let sentinel: **Word = if expect_sentinel() {
193+
unsafe::reinterpret_cast(&ptr::addr_of(sentinel_box))
194+
} else {
195+
ptr::null()
196+
};
182197

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

0 commit comments

Comments
 (0)