Skip to content

Commit

Permalink
Make stable-api-compiled-fallback the default, cleanup some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ianks committed Dec 14, 2024
1 parent 4da4f97 commit df0e6f4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/rb-sys-build/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ macro_rules! memoize {
($type:ty: $val:expr) => {{
static INIT: std::sync::Once = std::sync::Once::new();
static mut VALUE: Option<$type> = None;
#[allow(static_mut_refs)]
unsafe {
INIT.call_once(|| {
VALUE = Some($val);
Expand Down
9 changes: 3 additions & 6 deletions crates/rb-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ rust-version = "1.65"
rb-sys-build = { version = "0.9.103", path = "../rb-sys-build" }

[dev-dependencies]
rb-sys = { path = ".", features = [
"link-ruby",
"stable-api-compiled-fallback",
] }
rb-sys = { path = ".", features = ["link-ruby"] }
rusty-fork = "0.3.0"

[features]
default = []
default = ["stable-api-compiled-fallback"]
link-ruby = []
fuzz = []
no-link-ruby = []
Expand Down Expand Up @@ -57,4 +54,4 @@ unexpected_cfgs = { level = "warn", check-cfg = [
"cfg(rb_sys_gem)",
"cfg(rb_sys_use_stable_api_compiled_fallback)",
"cfg(rb_sys_force_stable_api_compiled)",
] }
] }
11 changes: 11 additions & 0 deletions crates/rb-sys/src/stable_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,21 @@ pub trait StableApiDefinition {
/// Get the class from a VALUE which contains an RBasic struct.
///
/// `VALUE` is a valid pointer to a non-immediate object.
///
/// # Safety
/// This function is unsafe because it dereferences a raw pointer to get
/// access to underlying RBasic struct. The caller must ensure that the
/// `VALUE` is a valid pointer to an RBasic struct.
unsafe fn rbasic_class(&self, obj: VALUE) -> Option<NonNull<VALUE>>;

/// Checks if the given object is frozen.
///
/// `VALUE` is a valid pointer to a non-immediate object.
///
/// # Safety
/// This function is unsafe because it may dereference a raw pointer to get
/// access to underlying RBasic struct. The caller must ensure that the
/// `VALUE` is a valid pointer to an RBasic struct.
unsafe fn frozen_p(&self, obj: VALUE) -> bool;

/// Tests if a bignum is positive.
Expand All @@ -82,6 +92,7 @@ pub trait StableApiDefinition {
/// This function is unsafe because it dereferences a raw pointer to get
/// access to underlying RBasic struct. The caller must ensure that the
/// `VALUE` is a valid pointer to a bignum.
#[inline]
unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool {
!self.bignum_positive_p(obj)
}
Expand Down
2 changes: 2 additions & 0 deletions examples/rust_reverse/ext/rust_reverse/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::manual_c_str_literals)]

use rb_sys::tracking_allocator::ManuallyTracked;
use rb_sys::*;
use std::os::raw::c_long;
Expand Down

0 comments on commit df0e6f4

Please sign in to comment.