Skip to main content

with_r_unwind_protect_sourced

Function with_r_unwind_protect_sourced 

Source
pub(crate) fn with_r_unwind_protect_sourced<F, R>(
    f: F,
    call: Option<SEXP>,
    source: PanicSource,
) -> R
where F: FnOnce() -> R,
Expand description

Like with_r_unwind_protect_or_raise, but reports panics with a custom PanicSource.

Used by guarded_altrep_call so that panics inside ALTREP callbacks with AltrepGuard::RUnwind are still attributed to PanicSource::Altrep.

Every outcome is raised through raise_rust_condition_via_stop, which hands the tagged value with_r_unwind_protect would return to the R helper the generated wrappers call, so the condition is the wrapper’s, with its kind (#1768). This works even in ALTREP callback context, where there is no R wrapper to inspect a tagged SEXP (Approach 3 from the issue-345 plan):

  • RCondition::Error (error!()) — kind = "error", its classes ahead of the rust_* layering, its data = fields.

  • RCondition::Conversion (arg_error!) — kind = "conversion", with the crate-class marker replaced in Rust by the classes miniextendr_init! registered: no generated R is there to resolve it.

  • A generic panic — kind = "panic", with the (at file:line) suffix.

  • Warning, Message, Condition — a plain R error with a diagnostic message and kind = "panic". warning!()/message!() from ALTREP context cannot suspend execution for non-fatal signals; documented limitation.