extendr_ffi/
backports.rs
1use crate::SEXP;
13extern "C" {
15 #[cfg(not(r_4_5))]
16 fn ENCLOS(x: SEXP) -> SEXP;
17
18 #[cfg(r_4_5)]
19 fn R_ParentEnv(x: SEXP) -> SEXP;
20
21 #[cfg(not(r_4_5))]
22 fn Rf_findVar(arg1: SEXP, arg2: SEXP) -> SEXP;
23
24 #[cfg(r_4_5)]
25 fn R_getVar(arg1: SEXP, arg2: SEXP) -> SEXP;
26
27 #[cfg(not(r_4_5))]
28 fn Rf_findVarInFrame(arg1: SEXP, arg2: SEXP) -> SEXP;
29
30 #[cfg(r_4_5)]
31 fn R_getVarEx(arg1: SEXP, arg2: SEXP) -> SEXP;
32
33 #[cfg(not(r_4_5))]
34 fn CLOENV(x: SEXP) -> SEXP;
35
36 #[cfg(r_4_5)]
37 fn R_ClosureEnv(x: SEXP) -> SEXP;
38
39 #[cfg(not(r_4_5))]
40 fn BODY(x: SEXP) -> SEXP;
41
42 #[cfg(r_4_5)]
43 fn R_ClosureBody(x: SEXP) -> SEXP;
44
45 #[cfg(not(r_4_5))]
46 fn FORMALS(x: SEXP) -> SEXP;
47
48 #[cfg(r_4_5)]
49 fn R_ClosureFormals(x: SEXP) -> SEXP;
50
51 #[cfg(not(r_4_5))]
52 fn DATAPTR(x: SEXP) -> *mut ::std::os::raw::c_void;
53
54 #[cfg(r_4_5)]
55 fn DATAPTR_RO(x: SEXP) -> *const ::std::os::raw::c_void;
56}
57
58#[inline]
60pub unsafe fn get_parent_env(x: SEXP) -> SEXP {
61 #[cfg(not(r_4_5))]
62 {
63 ENCLOS(x)
64 }
65 #[cfg(r_4_5)]
66 {
67 R_ParentEnv(x)
68 }
69}
70
71#[inline]
73pub unsafe fn get_var(symbol: SEXP, env: SEXP) -> SEXP {
74 #[cfg(not(r_4_5))]
75 {
76 Rf_findVar(symbol, env)
77 }
78 #[cfg(r_4_5)]
79 {
80 R_getVar(symbol, env)
81 }
82}
83
84#[inline]
86pub unsafe fn get_var_in_frame(symbol: SEXP, env: SEXP) -> SEXP {
87 #[cfg(not(r_4_5))]
88 {
89 Rf_findVarInFrame(symbol, env)
90 }
91 #[cfg(r_4_5)]
92 {
93 R_getVarEx(env, symbol)
94 }
95}
96
97#[inline]
99pub unsafe fn get_closure_env(x: SEXP) -> SEXP {
100 #[cfg(not(r_4_5))]
101 {
102 CLOENV(x)
103 }
104 #[cfg(r_4_5)]
105 {
106 R_ClosureEnv(x)
107 }
108}
109
110#[inline]
112pub unsafe fn get_closure_body(x: SEXP) -> SEXP {
113 #[cfg(not(r_4_5))]
114 {
115 BODY(x)
116 }
117 #[cfg(r_4_5)]
118 {
119 R_ClosureBody(x)
120 }
121}
122
123#[inline]
125pub unsafe fn get_closure_formals(x: SEXP) -> SEXP {
126 #[cfg(not(r_4_5))]
127 {
128 FORMALS(x)
129 }
130 #[cfg(r_4_5)]
131 {
132 R_ClosureFormals(x)
133 }
134}
135
136#[inline]
138pub unsafe fn dataptr(x: SEXP) -> *const ::std::os::raw::c_void {
139 #[cfg(not(r_4_5))]
140 {
141 DATAPTR(x) as *const _
142 }
143 #[cfg(r_4_5)]
144 {
145 DATAPTR_RO(x)
146 }
147}