#[doc(hidden)]pub fn drop_catching_panic<F: FnOnce()>(f: F)Expand description
Run a destructor closure, aborting the process if the closure panics.
A panic inside a GC finalizer cannot be safely propagated: the finalizer runs at an arbitrary point in R’s garbage collector, and unwinding across the C-ABI boundary into R’s runtime is undefined behaviour. Aborting is the only safe recovery strategy — the destructor has already left the value in an indeterminate state, so continuing is not an option.
§Implementation note
This function deliberately avoids std::panic::catch_unwind. On the first
call from within R’s GC finalizer, catch_unwind may lazily initialise
LLVM exception-handling state, which can allocate. Any allocation during a
GC finalizer re-enters the GC and triggers the fatal “recursive gc
invocation” crash. Instead, this function uses a drop-guard that compares
std::thread::panicking() — a cheap, allocation-free TLS read — on entry
and on exit.
Called from a Drop that an unrelated panic’s unwind is running, it runs
f() and returns: the unwind continues and reaches its catch_unwind
boundary (for a #[miniextendr] fn, the R error it becomes).
Deferred conditions queued by this destructor (including nested guards) are suppressed on this thread. Finalization has no caller handlers to receive them, and retaining them would strand or misattribute diagnostics.
This helper is #[doc(hidden)] because it is called from macro-generated
code and is not part of the public API.