Expand description
TLS-backed convenience API for GC protection.
Provides an optional convenience layer that maintains a thread-local
stack of scope pointers, allowing tls::protect(x) without passing
&ProtectScope explicitly.
Explicit &ProtectScope is recommended for most use cases. It’s simpler,
clearer about lifetimes, and doesn’t rely on runtime state. Use this TLS
convenience only when threading scope references through deep call stacks
would be excessively verbose.
§Example
ⓘ
use miniextendr_api::gc_protect::tls;
unsafe fn deep_helper(x: SEXP) -> SEXP {
let y = tls::protect(allocate_something());
combine(x, y.get())
}
unsafe fn call_body(x: SEXP) -> SEXP {
tls::with_protect_scope(|| {
let x = tls::protect(x);
deep_helper(x.get())
})
}Structs§
- TlsRoot
- A rooted SEXP from TLS protection.
- TlsScope
Guard 🔒 - Execute a closure with a new protection scope as the current TLS scope.
Constants§
- SCOPE_
STACK 🔒 - Stack of active protection scopes on this thread.
Functions§
- current_
count - Get the current scope’s protection count.
- has_
active_ scope - Check if there is an active TLS scope.
- protect⚠
- Protect a value using the current TLS scope.
- protect_
raw ⚠ - Protect a value, returning the raw SEXP.
- scope_
depth - Get the nesting depth of TLS scopes.
- with_
protect_ ⚠scope - Execute a closure with a protect scope that is accessible via TLS.