Skip to content

Commit

Permalink
build.rs: Added a feature for using OBJSXP vs S4SXP
Browse files Browse the repository at this point in the history
  • Loading branch information
CGMossa committed Apr 30, 2024
1 parent e1c742b commit 88632f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions extendr-api/build.rs
Expand Up @@ -30,4 +30,8 @@ fn main() {
if &*major >= "4" && &*minor >= "3" {
println!("cargo:rustc-cfg=use_r_altlist");
}

if &*major >= "4" && &*minor >= "4" {
println!("cargo:rustc-cfg=use_objsxp");
}
}
6 changes: 6 additions & 0 deletions extendr-api/src/lib.rs
Expand Up @@ -583,7 +583,10 @@ pub fn rtype_to_sxp(rtype: Rtype) -> SEXPTYPE {
ExternalPtr => EXTPTRSXP,
WeakRef => WEAKREFSXP,
Raw => RAWSXP,
#[cfg(not(use_objsxp))]
S4 => S4SXP,
#[cfg(use_objsxp)]
S4 => OBJSXP,
Unknown => panic!("attempt to use Unknown Rtype"),
}
}
Expand Down Expand Up @@ -616,7 +619,10 @@ pub fn sxp_to_rtype(sxptype: SEXPTYPE) -> Rtype {
EXTPTRSXP => ExternalPtr,
WEAKREFSXP => WeakRef,
RAWSXP => Raw,
#[cfg(not(use_objsxp))]
S4SXP => S4,
#[cfg(use_objsxp)]
OBJSXP => S4,
_ => Unknown,
}
}
Expand Down
6 changes: 6 additions & 0 deletions extendr-api/src/robj/mod.rs
Expand Up @@ -288,7 +288,10 @@ pub trait Types: GetSexp {
EXTPTRSXP => Rtype::ExternalPtr,
WEAKREFSXP => Rtype::WeakRef,
RAWSXP => Rtype::Raw,
#[cfg(not(use_objsxp))]
S4SXP => Rtype::S4,
#[cfg(use_objsxp)]
OBJSXP => Rtype::S4,
_ => Rtype::Unknown,
}
}
Expand Down Expand Up @@ -320,7 +323,10 @@ pub trait Types: GetSexp {
EXTPTRSXP => Rany::ExternalPtr(std::mem::transmute(self.as_robj())),
WEAKREFSXP => Rany::WeakRef(std::mem::transmute(self.as_robj())),
RAWSXP => Rany::Raw(std::mem::transmute(self.as_robj())),
#[cfg(not(use_objsxp))]
S4SXP => Rany::S4(std::mem::transmute(self.as_robj())),
#[cfg(use_objsxp)]
OBJSXP => Rany::S4(std::mem::transmute(self.as_robj())),
_ => Rany::Unknown(std::mem::transmute(self.as_robj())),
}
}
Expand Down

0 comments on commit 88632f3

Please sign in to comment.