Skip to main content

generate_getter_body

Function generate_getter_body 

Source
fn generate_getter_body(struct_name: &Ident, slot: &SidecarSlot) -> TokenStream
Expand description

Generate the token stream for a sidecar getter function body.

Reads the slot and returns it as an R SEXP. The strategy depends on the slot kind:

  • Sidecar: returns the value from the external pointer’s protection list, after flushing a live struct’s pending value for the field. It needs no live address, so without require_live it also reads a pointer that readRDS brought back; with it (the field methods of r_data_accessors, #1891) a restored pointer is refused.
  • Scalar kinds: reads the struct field (accessed via the external pointer address) and wraps it with Rf_Scalar*.
  • Conversion: clones the struct field and calls IntoR::into_sexp.
  • Computed: calls the get function on the live struct and converts its value with IntoR::into_sexp.

The body runs inside with_r_unwind_protect (see the emission site in generate_sidecar_accessors). The receiver is the pointer or an object carrying it in .ptr, as for an instance method; an argument carrying no pointer, a null pointer address, or a wrong stored type panics with the same expected ExternalPtr<T> message the main class-method path uses. The panic is transported as a tagged condition and re-raised by the R wrapper.