Skip to main content

Module altrep_bridge

Module altrep_bridge 

Source
Expand description

Unsafe ALTREP trampolines and installers bridging safe traits to R’s C ABI.

This module is the seam between R’s C method tables and the safe traits in crate::altrep_traits. It provides:

  • Generic extern "C-unwind" trampolines (t_length, t_dataptr, t_elt_*, …) that call into safe trait methods on T: Altrep.
  • Installer functions (install_*) that register the trampolines with R based on the HAS_* const gates declared by the safe traits.

Non-allocating callbacks select T::GUARD at monomorphization time. Callbacks returning SEXP, Dataptr and string/list setters always use R_UnwindProtect: their generated bridges can allocate even when the underlying data provider is pure Rust.

§Why a separate bridge module

R installs methods via raw extern "C-unwind" function pointers. To make impl Altrep for MyType ergonomic, we generate one trampoline per method once, generic over T: Altrep, that:

  1. Recovers T’s monomorphization at the call site (no vtables).
  2. Wraps the user callback in the per-type guard.
  3. Hands the result back to R.

Users (and the #[derive(Altrep*)] macros) never call into this module directly — RegisterAltrep::get_or_init_class does.

§Design

Trampolines are only installed when HAS_* is true. When false, the method is NOT installed with R, so R uses its own default behavior.

Macros§

def_installer 🔒
Generate a family-specific installer function from a declarative spec.

Functions§

guarded_altrep_call 🔒
Dispatch an ALTREP callback through the guard mode selected by T::GUARD.
guarded_altrep_r_call 🔒
Protect callbacks whose framework bridge may allocate in R, independently of the data provider’s guard choice for native reads.
guarded_altrep_sexp_call 🔒
Root an SEXP result before the guard allocates to signal deferred conditions.
install_base⚠
Install base ALTREP methods (always installs length, conditionally installs optional).
install_cplx⚠
Install complex-specific methods.
install_int⚠
Install integer-specific methods.
install_lgl⚠
Install logical-specific methods.
install_list⚠
Install list-specific methods.
install_raw⚠
Install raw-specific methods.
install_real⚠
Install real-specific methods.
install_str⚠
Install string-specific methods.
install_vec⚠
Install vector-level methods.
t_coerce⚠
Trampoline for Coerce method.
t_cplx_elt⚠
Trampoline for complex Elt method.
t_cplx_get_region⚠
Trampoline for complex Get_region method.
t_dataptr⚠
Trampoline for Dataptr method.
t_dataptr_or_null⚠
Trampoline for Dataptr_or_null method.
t_duplicate⚠
Trampoline for Duplicate method.
t_duplicate_ex⚠
Trampoline for DuplicateEX method (extended duplication).
t_extract_subset⚠
Trampoline for Extract_subset method.
t_inspect⚠
Trampoline for Inspect method.
t_int_elt⚠
Trampoline for integer Elt method.
t_int_get_region⚠
Trampoline for integer Get_region method.
t_int_is_sorted⚠
Trampoline for integer Is_sorted method.
t_int_max⚠
Trampoline for integer Max method.
t_int_min⚠
Trampoline for integer Min method.
t_int_no_na⚠
Trampoline for integer No_NA method.
t_int_sum⚠
Trampoline for integer Sum method.
t_length⚠
Trampoline for Length method.
t_lgl_elt⚠
Trampoline for logical Elt method.
t_lgl_get_region⚠
Trampoline for logical Get_region method.
t_lgl_is_sorted⚠
Trampoline for logical Is_sorted method.
t_lgl_no_na⚠
Trampoline for logical No_NA method.
t_lgl_sum⚠
Trampoline for logical Sum method.
t_list_elt⚠
Trampoline for list Elt method (REQUIRED for ALTLIST).
t_list_set_elt⚠
Trampoline for list Set_elt method.
t_raw_elt⚠
Trampoline for raw Elt method.
t_raw_get_region⚠
Trampoline for raw Get_region method.
t_real_elt⚠
Trampoline for real Elt method.
t_real_get_region⚠
Trampoline for real Get_region method.
t_real_is_sorted⚠
Trampoline for real Is_sorted method.
t_real_max⚠
Trampoline for real Max method.
t_real_min⚠
Trampoline for real Min method.
t_real_no_na⚠
Trampoline for real No_NA method.
t_real_sum⚠
Trampoline for real Sum method.
t_serialized_state⚠
Trampoline for Serialized_state method.
t_str_elt⚠
Trampoline for string Elt method (REQUIRED for ALTSTRING).
t_str_is_sorted⚠
Trampoline for string Is_sorted method.
t_str_no_na⚠
Trampoline for string No_NA method.
t_str_set_elt⚠
Trampoline for string Set_elt method.
t_unserialize⚠
Trampoline for Unserialize method.
t_unserialize_ex⚠
Trampoline for UnserializeEX method (extended unserialization with attributes).