|
8 | 8 | use std::ffi::CStr; |
9 | 9 | use std::ffi::CString; |
10 | 10 |
|
11 | | -use c2rust_bitfields::BitfieldStruct; |
12 | 11 | use itertools::Itertools; |
13 | 12 | use libr::*; |
14 | 13 | use once_cell::sync::Lazy; |
@@ -50,55 +49,6 @@ pub fn init_utils() {} |
50 | 49 | static RE_SYNTACTIC_IDENTIFIER: Lazy<Regex> = |
51 | 50 | Lazy::new(|| Regex::new(r"^[\p{L}\p{Nl}.][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}.]*$").unwrap()); |
52 | 51 |
|
53 | | -#[derive(Copy, Clone, BitfieldStruct)] |
54 | | -#[repr(C)] |
55 | | -pub struct Sxpinfo { |
56 | | - #[bitfield(name = "rtype", ty = "libc::c_uint", bits = "0..=4")] |
57 | | - #[bitfield(name = "scalar", ty = "libc::c_uint", bits = "5..=5")] |
58 | | - #[bitfield(name = "obj", ty = "libc::c_uint", bits = "6..=6")] |
59 | | - #[bitfield(name = "alt", ty = "libc::c_uint", bits = "7..=7")] |
60 | | - #[bitfield(name = "gp", ty = "libc::c_uint", bits = "8..=23")] |
61 | | - #[bitfield(name = "mark", ty = "libc::c_uint", bits = "24..=24")] |
62 | | - #[bitfield(name = "debug", ty = "libc::c_uint", bits = "25..=25")] |
63 | | - #[bitfield(name = "trace", ty = "libc::c_uint", bits = "26..=26")] |
64 | | - #[bitfield(name = "spare", ty = "libc::c_uint", bits = "27..=27")] |
65 | | - #[bitfield(name = "gcgen", ty = "libc::c_uint", bits = "28..=28")] |
66 | | - #[bitfield(name = "gccls", ty = "libc::c_uint", bits = "29..=31")] |
67 | | - #[bitfield(name = "named", ty = "libc::c_uint", bits = "32..=47")] |
68 | | - #[bitfield(name = "extra", ty = "libc::c_uint", bits = "48..=63")] |
69 | | - pub rtype_scalar_obj_alt_gp_mark_debug_trace_spare_gcgen_gccls_named_extra: [u8; 8], |
70 | | -} |
71 | | - |
72 | | -pub static mut ACTIVE_BINDING_MASK: libc::c_uint = 1 << 15; |
73 | | -pub static mut S4_OBJECT_MASK: libc::c_uint = 1 << 4; |
74 | | -pub static mut HASHASH_MASK: libc::c_uint = 1; |
75 | | - |
76 | | -impl Sxpinfo { |
77 | | - pub fn interpret(x: &SEXP) -> &Self { |
78 | | - unsafe { (*x as *mut Sxpinfo).as_ref().unwrap() } |
79 | | - } |
80 | | - |
81 | | - pub fn is_active(&self) -> bool { |
82 | | - self.gp() & unsafe { ACTIVE_BINDING_MASK } != 0 |
83 | | - } |
84 | | - |
85 | | - pub fn is_immediate(&self) -> bool { |
86 | | - self.extra() != 0 |
87 | | - } |
88 | | - |
89 | | - pub fn is_s4(&self) -> bool { |
90 | | - self.gp() & unsafe { S4_OBJECT_MASK } != 0 |
91 | | - } |
92 | | - |
93 | | - pub fn is_altrep(&self) -> bool { |
94 | | - self.alt() != 0 |
95 | | - } |
96 | | - |
97 | | - pub fn is_object(&self) -> bool { |
98 | | - self.obj() != 0 |
99 | | - } |
100 | | -} |
101 | | - |
102 | 52 | #[harp::register] |
103 | 53 | pub extern "C" fn harp_log_trace(msg: SEXP) -> crate::error::Result<SEXP> { |
104 | 54 | let msg = String::try_from(RObject::view(msg))?; |
@@ -176,15 +126,15 @@ pub fn r_is_null(object: SEXP) -> bool { |
176 | 126 | } |
177 | 127 |
|
178 | 128 | pub fn r_is_altrep(object: SEXP) -> bool { |
179 | | - Sxpinfo::interpret(&object).is_altrep() |
| 129 | + unsafe { libr::ALTREP(object) != 0 } |
180 | 130 | } |
181 | 131 |
|
182 | 132 | pub fn r_is_object(object: SEXP) -> bool { |
183 | | - Sxpinfo::interpret(&object).is_object() |
| 133 | + unsafe { libr::OBJECT(object) != 0 } |
184 | 134 | } |
185 | 135 |
|
186 | 136 | pub fn r_is_s4(object: SEXP) -> bool { |
187 | | - Sxpinfo::interpret(&object).is_s4() |
| 137 | + unsafe { libr::IS_S4_OBJECT(object) != 0 } |
188 | 138 | } |
189 | 139 |
|
190 | 140 | pub fn r_is_unbound(object: SEXP) -> bool { |
|
0 commit comments