rustr/protect/
mod.rs

1//! R Memory Protection Functions
2//!
3//!
4
5use ::rdll::*;
6
7#[inline]
8pub unsafe fn rustr_release_object(x: SEXP) -> SEXP {
9    if x != R_NilValue {
10        R_ReleaseObject(x);
11    }
12    x
13}
14
15
16#[inline]
17pub unsafe fn rustr_preserve_object(x: SEXP) -> SEXP {
18    if x != R_NilValue {
19        R_PreserveObject(x);
20    }
21    x
22}
23
24#[inline]
25pub unsafe fn rustr_replace_object(x: SEXP, y: SEXP) -> SEXP {
26    if Rf_isNull(x) == Rboolean::TRUE {
27        rustr_preserve_object(y);
28    } else if Rf_isNull(y) == Rboolean::TRUE {
29        rustr_release_object(x);
30    } else if x != y {
31        // if we are setting to the same SEXP as we already have, do nothing
32
33
34        // the previous SEXP was not NULL, so release it
35        rustr_release_object(x);
36
37        // the new SEXP is not NULL, so preserve it
38        rustr_preserve_object(y);
39
40
41    }
42    y
43}
44
45pub mod stackp;
46pub mod indexp;
47pub mod countp;