pub struct NativeScope<'c> { /* private fields */ }Expand description
A RAII claim on the tail of NativeRootStore: records the store’s length
on construction and truncates back to it on Drop.
Create one in any runtime wrapper that holds a GcRef across something that
may allocate, and root every such reference through it; abi.rs, the parser
interpreter and the debugger’s p EXPR all do. The type is a pointer, a
usize and a PhantomData, constructed by an unsafe fn new(ctx) returning
by value; root takes &self so several Rooted values can be live at
once, and Rooted<'s> borrows from the scope.
The watermark is a usize index and it must stay one. The store grows —
see NATIVE_ROOT_RESERVATION for why it has to — so a *mut GcRef
watermark saved by an outer scope would dangle the moment an inner scope’s
root() reallocs, and Drop would then publish that dangling pointer as the
store’s new end. Only a scope that roots past the reservation while another
is live exercises this: a_scope_survives_the_growth_its_own_roots_force
and its sibling.
Implementations§
Source§impl<'c> NativeScope<'c>
impl<'c> NativeScope<'c>
Sourcepub unsafe fn new(ctx: *mut RuntimeContext) -> NativeScope<'c>
pub unsafe fn new(ctx: *mut RuntimeContext) -> NativeScope<'c>
Open a scope on ctx’s native root store.
A null or unwired context is accepted: the scope has no store to claim
from, so root records nothing, but it still hands back a Rooted, so
the proof keeps its meaning on the defensive null-context paths. The
references are unreachable from a collection that cannot happen, because
a context with no store has no heap either.
§Safety
ctx must be null, or point at a live RuntimeContext that outlives
this scope.
Sourcepub fn root(&self, r: GcRef) -> Rooted<'_>
pub fn root(&self, r: GcRef) -> Rooted<'_>
Root r for the rest of this scope and return the proof.
One bounds-checked store and one increment past the null test.
Sourcepub fn root_count(&self) -> usize
pub fn root_count(&self) -> usize
The number of references this scope and everything nested inside it currently root.