Expand description
Safe API for R’s R_UnwindProtect
This module provides with_r_unwind_protect for handling R errors with Rust cleanup.
It automatically runs Rust destructors when R errors occur.
Important: R uses longjmp for error handling, which normally bypasses Rust destructors.
Use this API to ensure cleanup happens even when R errors occur.
§Log drain
Every call to with_r_unwind_protect (and its variants) drains the
cross-thread log queue via drain_log_queue_if_available before
returning or re-raising an R error. This ensures that records buffered by
worker threads are flushed to R’s console on every FFI exit — including
error paths.
Statics§
- R_
CONTINUATION_ 🔒TOKEN - Global continuation token for R_UnwindProtect.
Functions§
- drain_
log_ 🔒queue_ if_ available - Drain the cross-thread log queue if the
logfeature is enabled. - get_
continuation_ 🔒token - Get or create the global continuation token.
- panic_
payload_ to_ string - Extract a message from a panic payload.
- raise_
rust_ 🔒 ⚠condition_ via_ stop - Raise an R condition with
rust_*class layering by evaluatingstop(structure(list(message = msg, call = call), class = c(...))). - run_
r_ 🔒unwind_ protect - Core R_UnwindProtect wrapper. Returns
Ok(result)on success,Err(payload)on Rust panic, or diverges viaR_ContinueUnwindon R longjmp. - stop_
sym 🔒 - Cached
stopsymbol (permanently interned viaRf_install). - with_
r_ unwind_ protect - Execute a closure with R unwind protection (non-
error_in_rpath). - with_
r_ unwind_ protect_ error_ in_ r - Like
with_r_unwind_protect, but returns a tagged error SEXP on Rust panics instead of raising an R error viaRf_errorcall. - with_
r_ unwind_ protect_ shim - Like
with_r_unwind_protect, but returns a tagged error SEXP on Rust panics instead of raising an R error viaRf_errorcall. - with_
r_ 🔒unwind_ protect_ sourced - Like
with_r_unwind_protect, but reports panics with a custom [PanicSource].