Skip to main content

make_rust_condition_value

Function make_rust_condition_value 

Source
pub fn make_rust_condition_value(
    message: &str,
    kind: &str,
    class: Option<&str>,
    call: Option<SEXP>,
) -> SEXP
Expand description

Build a tagged condition-value SEXP for transport across the Rust→R boundary.

Used for all Rust-origin failures and user-facing conditions. The R-side switch in condition_check_lines reads .val$kind to select the condition type and .val$class to prepend optional user classes before the standard rust_* layering.

§Safety

Must be called from R’s main thread (standard R API constraint). The returned SEXP is unprotected — caller must protect if needed.

§PROTECT discipline

Every fresh allocation (msg, kind, optional class, true-marker) is protected before the next allocation that might trigger a GC barrier. The prot counter is incremented on each Rf_protect and balanced by Rf_unprotect(prot) at exit on all branches. This pattern was established by PR #344 commit af6b4875 to fix a recursive gc invocation segfault on R-devel.

§Arguments

  • message - Human-readable condition message
  • kind - Condition kind — one of the constants in kind.
  • class - Optional user-supplied class name to prepend to the layered vector
  • call - Optional R call SEXP for error context. When None, uses R_NilValue.