diff --git a/Cargo.toml b/Cargo.toml index a10cf12e..2aabd3b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,13 @@ links = "R" documentation = "https://docs.rs/libR-sys/latest/libR_sys/" repository = "https://github.com/extendr/libR-sys" +[features] +default = [] +# Expose a small set of R "non-API" entry points (promise/environment/closure +# accessors) in the `non_api` module. Off by default: these are not part of R's +# stable C API and may not be available on every R version. +non-api = [] + [lib] # Some code comments on R's source code might be accidentally treated as Rust's # doc test. See https://github.com/extendr/libR-sys/issues/194 for the details. diff --git a/src/lib.rs b/src/lib.rs index 273f76e4..eadbfb2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,6 +66,9 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +#[cfg(feature = "non-api")] +pub mod non_api; + #[non_exhaustive] #[repr(transparent)] #[derive(Debug)] diff --git a/src/non_api.rs b/src/non_api.rs new file mode 100644 index 00000000..7740e406 --- /dev/null +++ b/src/non_api.rs @@ -0,0 +1,32 @@ +//! R "non-API" entry points, gated behind the off-by-default `non-api` feature. +//! +//! These are not part of R's stable C API; some are not exported by every R +//! version (e.g. `SET_FORMALS`, `SET_BODY`, `SET_CLOENV`, `PRSEEN`, +//! `Rf_isValidStringF` are not exported by R 4.6), so calling them may fail to +//! link depending on the R you build against. Use with care. +//! +//! Ported from `extendr-ffi` (`src/non_api.rs`). +use crate::{Rboolean, SEXP, SEXPTYPE}; +extern "C" { + pub fn Rf_isValidString(arg1: SEXP) -> Rboolean; + pub fn Rf_isValidStringF(arg1: SEXP) -> Rboolean; + pub fn SYMVALUE(x: SEXP) -> SEXP; + pub fn PRSEEN(x: SEXP) -> ::std::os::raw::c_int; + pub fn SET_ENCLOS(x: SEXP, v: SEXP); + pub fn ENVFLAGS(x: SEXP) -> ::std::os::raw::c_int; + pub fn SET_ENVFLAGS(x: SEXP, v: ::std::os::raw::c_int); + pub fn ENCLOS(x: SEXP) -> SEXP; + pub fn HASHTAB(x: SEXP) -> SEXP; + pub fn FRAME(x: SEXP) -> SEXP; + pub fn Rf_allocSExp(arg1: SEXPTYPE) -> SEXP; + pub fn SET_FORMALS(x: SEXP, v: SEXP); + pub fn SET_BODY(x: SEXP, v: SEXP); + pub fn SET_CLOENV(x: SEXP, v: SEXP); + pub fn SET_PRCODE(x: SEXP, v: SEXP); + pub fn SET_PRENV(x: SEXP, v: SEXP); + pub fn SET_PRVALUE(x: SEXP, v: SEXP); + #[doc = "Promise Access Functions"] + pub fn PRCODE(x: SEXP) -> SEXP; + pub fn PRENV(x: SEXP) -> SEXP; + pub fn PRVALUE(x: SEXP) -> SEXP; +}