@@ -167,18 +167,33 @@ fn RootSet() -> RootSet {
167
167
LinearMap( )
168
168
}
169
169
170
+ #[ cfg( gc) ]
171
+ fn expect_sentinel( ) -> bool { true }
172
+
173
+ #[ cfg( nogc) ]
174
+ fn expect_sentinel( ) -> bool { false }
175
+
170
176
// This should only be called from fail, as it will drop the roots
171
177
// which are *live* on the stack, rather than dropping those that are
172
178
// dead.
173
179
fn cleanup_stack_for_failure ( ) {
174
180
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.
179
191
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
+ } ;
182
197
183
198
let mut roots = ~RootSet ( ) ;
184
199
for walk_gc_roots( need_cleanup, sentinel) |root, tydesc| {
0 commit comments