Skip to main content

Module c_wrapper_builder

Module c_wrapper_builder 

Source
Expand description

Unified C wrapper generation for standalone functions and impl methods.

This module provides shared infrastructure for generating C wrappers that:

  • Run on R’s main thread inside with_r_unwind_protect
  • Perform parameter conversion from SEXP to Rust types
  • Convert Rust return values back to SEXP
  • Properly handle panics and R errors

The same infrastructure is used by both #[miniextendr] on standalone functions and #[miniextendr(env|r6|s3|s4|s7)] on impl blocks.

Re-exportsΒ§

use proc_macro2::TokenStream; πŸ”’
use quote::format_ident; πŸ”’
use quote::quote; πŸ”’

StructsΒ§

CWrapperContext
All information needed to generate a C wrapper function for an R-exported Rust item.
CWrapperContextBuilder
Builder for CWrapperContext.

EnumsΒ§

ErrPartsMode
How the generated Err arm turns an error value into condition parts (message, class vector, structured data).
ReturnHandling
Strategy for converting a Rust return value into an R SEXP.

FunctionsΒ§

detect_return_handling
Detects the ReturnHandling strategy from a return type: the one rule for standalone functions, inherent methods and trait methods.
detect_return_handling_from_type πŸ”’
Determines the ReturnHandling variant for a concrete syn::Type.
first_type_argument πŸ”’
Extracts the first generic type argument from a path segment’s angle-bracketed arguments.
into_r_err_value πŸ”’
The tagged condition value of a failed return conversion, the error bound to __mx_error (return_conversion).
return_conversion πŸ”’
The conversion of a returned value to the SEXP a generated entry point returns (#2272): IntoR::try_into_sexp(value), and a failed conversion becomes the tagged condition value of a Result error (kind = "result_err"): the error’s message, classes and fields, read through RConditionData, which every IntoR::Error implements (condition::into_r_err_parts). No panic, so no framework file location in the message.
return_conversion_at πŸ”’
return_conversion with the try_into_sexp path spanned at span, so a value without IntoR is reported there.
return_conversion_result πŸ”’
return_conversion as a Result<SEXP, SEXP>: Ok the converted value, Err the tagged condition value of a failed conversion, for a getter that keeps a converted value and must not keep a condition (a cached field, #2271).