Skip to main content

guarded_ffi_call

Function guarded_ffi_call 

Source
pub fn guarded_ffi_call<F, R>(f: F, mode: GuardMode, source: PanicSource) -> R
where F: FnOnce() -> R,
Expand description

Execute f inside an FFI guard selected by mode.

On panic:

Deferred conditions signal on R’s main thread before return (or panic conversion). Use this boundary on the main thread. Any SEXP held in the generic result must be rooted, e.g. by returning OwnedProtect.

§Parameters

  • f: The closure to execute.
  • mode: Which guard strategy to use.
  • source: Attribution for telemetry if a panic occurs.

§Note on fallback

GuardMode::CatchUnwind diverges on panic (Rf_error never returns), so no fallback value is needed. If you need a fallback (e.g. connection trampolines that must return a value on panic without calling R), use guarded_ffi_call_with_fallback instead.