From 093a6eaa2eb0a8976268a7b395622837df32c357 Mon Sep 17 00:00:00 2001 From: Jose Narvaez Date: Mon, 2 Dec 2024 20:16:43 +0000 Subject: [PATCH 1/4] Implemented StableApiDefinition::[bignum_positive_p|bignum_negative_p]. --- crates/rb-sys-tests/src/stable_api_test.rs | 54 ++++++++++++++++++++++ crates/rb-sys/src/stable_api.rs | 16 +++++++ crates/rb-sys/src/stable_api/compiled.c | 11 +++++ crates/rb-sys/src/stable_api/compiled.rs | 16 +++++++ crates/rb-sys/src/stable_api/ruby_2_6.rs | 10 ++++ crates/rb-sys/src/stable_api/ruby_2_7.rs | 10 ++++ crates/rb-sys/src/stable_api/ruby_3_0.rs | 10 ++++ crates/rb-sys/src/stable_api/ruby_3_1.rs | 10 ++++ crates/rb-sys/src/stable_api/ruby_3_2.rs | 10 ++++ crates/rb-sys/src/stable_api/ruby_3_3.rs | 10 ++++ crates/rb-sys/src/stable_api/ruby_3_4.rs | 10 ++++ 11 files changed, 167 insertions(+) diff --git a/crates/rb-sys-tests/src/stable_api_test.rs b/crates/rb-sys-tests/src/stable_api_test.rs index 93cb078d..f639f88e 100644 --- a/crates/rb-sys-tests/src/stable_api_test.rs +++ b/crates/rb-sys-tests/src/stable_api_test.rs @@ -213,6 +213,60 @@ parity_test!( } ); +parity_test!( + name: test_bignum_positive_p_evaled, + func: bignum_positive_p, + data_factory: { + ruby_eval!("2 ** 64") + }, + expected: true +); + +parity_test!( + name: test_bignum_negative_p_evaled, + func: bignum_negative_p, + data_factory: { + ruby_eval!("-(2 ** 64)") + }, + expected: true +); + +parity_test!( + name: test_bignum_positive_p_for_zero, + func: bignum_positive_p, + data_factory: { + unsafe { rb_sys::rb_int2big(0) } + }, + expected: true +); + +parity_test!( + name: test_bignum_negative_p_for_zero, + func: bignum_negative_p, + data_factory: { + unsafe { rb_sys::rb_int2big(0) } + }, + expected: false +); + +parity_test!( + name: test_bignum_positive_p, + func: bignum_positive_p, + data_factory: { + unsafe { rb_sys::rb_int2big(64) } + }, + expected: true +); + +parity_test!( + name: test_bignum_negative_p, + func: bignum_negative_p, + data_factory: { + unsafe { rb_sys::rb_int2big(-1) } + }, + expected: true +); + parity_test!( name: test_builtin_type_for_string, func: builtin_type, diff --git a/crates/rb-sys/src/stable_api.rs b/crates/rb-sys/src/stable_api.rs index d97204da..c7a99793 100644 --- a/crates/rb-sys/src/stable_api.rs +++ b/crates/rb-sys/src/stable_api.rs @@ -54,6 +54,22 @@ pub trait StableApiDefinition { /// is valid. unsafe fn rarray_const_ptr(&self, obj: VALUE) -> *const VALUE; + /// Tests if a bignum is positive. + /// + /// # 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 a bignum. + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool; + + /// Tests if a bignum is negative. + /// + /// # 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 a bignum. + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool; + /// Tests if the given value is a special constant. fn special_const_p(&self, value: VALUE) -> bool; diff --git a/crates/rb-sys/src/stable_api/compiled.c b/crates/rb-sys/src/stable_api/compiled.c index a877f7cd..739f6634 100644 --- a/crates/rb-sys/src/stable_api/compiled.c +++ b/crates/rb-sys/src/stable_api/compiled.c @@ -25,6 +25,17 @@ impl_special_const_p(VALUE obj) { return SPECIAL_CONST_P(obj); } +int +impl_bignum_positive_p(VALUE obj) { + return RBIGNUM_POSITIVE_P(obj); +} + +int +impl_bignum_negative_p(VALUE obj) { + return RBIGNUM_NEGATIVE_P(obj); +} + + enum ruby_value_type impl_builtin_type(VALUE obj) { return RB_BUILTIN_TYPE(obj); diff --git a/crates/rb-sys/src/stable_api/compiled.rs b/crates/rb-sys/src/stable_api/compiled.rs index 418cb836..c142e7c2 100644 --- a/crates/rb-sys/src/stable_api/compiled.rs +++ b/crates/rb-sys/src/stable_api/compiled.rs @@ -19,6 +19,12 @@ extern "C" { #[link_name = "impl_special_const_p"] fn impl_special_const_p(value: VALUE) -> bool; + #[link_name = "impl_bignum_positive_p"] + fn impl_bignum_positive_p(obj: VALUE) -> bool; + + #[link_name = "impl_bignum_negative_p"] + fn impl_bignum_negative_p(obj: VALUE) -> bool; + #[link_name = "impl_builtin_type"] fn impl_builtin_type(obj: VALUE) -> ruby_value_type; @@ -93,6 +99,16 @@ impl StableApiDefinition for Definition { unsafe { impl_special_const_p(value) } } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + impl_bignum_positive_p(obj) + } + + #[inline] + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { + impl_bignum_negative_p(obj) + } + #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> ruby_value_type { impl_builtin_type(obj) diff --git a/crates/rb-sys/src/stable_api/ruby_2_6.rs b/crates/rb-sys/src/stable_api/ruby_2_6.rs index 408f096a..df6ad043 100644 --- a/crates/rb-sys/src/stable_api/ruby_2_6.rs +++ b/crates/rb-sys/src/stable_api/ruby_2_6.rs @@ -96,6 +96,16 @@ impl StableApiDefinition for Definition { is_immediate || !test } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 1 + } + + #[inline] + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 0 + } + #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_2_7.rs b/crates/rb-sys/src/stable_api/ruby_2_7.rs index b9ef5225..1e7488d2 100644 --- a/crates/rb-sys/src/stable_api/ruby_2_7.rs +++ b/crates/rb-sys/src/stable_api/ruby_2_7.rs @@ -96,6 +96,16 @@ impl StableApiDefinition for Definition { is_immediate || !test } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 1 + } + + #[inline] + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 0 + } + #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_0.rs b/crates/rb-sys/src/stable_api/ruby_3_0.rs index c2eb0bf0..bed16cb9 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_0.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_0.rs @@ -104,6 +104,16 @@ impl StableApiDefinition for Definition { is_immediate || !test } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 1 + } + + #[inline] + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 0 + } + #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_1.rs b/crates/rb-sys/src/stable_api/ruby_3_1.rs index 646fa5a3..0a7a3961 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_1.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_1.rs @@ -97,6 +97,16 @@ impl StableApiDefinition for Definition { is_immediate || !test } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 1 + } + + #[inline] + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 0 + } + #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_2.rs b/crates/rb-sys/src/stable_api/ruby_3_2.rs index 763158ae..8bc155f6 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_2.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_2.rs @@ -91,6 +91,16 @@ impl StableApiDefinition for Definition { is_immediate || !test } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 1 + } + + #[inline] + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 0 + } + #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_3.rs b/crates/rb-sys/src/stable_api/ruby_3_3.rs index 11afd1cd..c9c94241 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_3.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_3.rs @@ -84,6 +84,16 @@ impl StableApiDefinition for Definition { is_immediate || !test } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 1 + } + + #[inline] + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 0 + } + #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_4.rs b/crates/rb-sys/src/stable_api/ruby_3_4.rs index 9cd51405..91b2d460 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_4.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_4.rs @@ -84,6 +84,16 @@ impl StableApiDefinition for Definition { is_immediate || !test } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 1 + } + + #[inline] + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { + crate::rb_big_sign(obj) == 0 + } + #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; From aa851102bfc7535f7dcac8cb28f996b79907df5e Mon Sep 17 00:00:00 2001 From: Jose Narvaez Date: Thu, 5 Dec 2024 18:53:43 +0000 Subject: [PATCH 2/4] Avoiding function calls to be on par with macros. --- crates/rb-sys-build/src/bindings.rs | 4 +--- crates/rb-sys/src/stable_api/ruby_3_3.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/rb-sys-build/src/bindings.rs b/crates/rb-sys-build/src/bindings.rs index 59e785f4..cd48e6e3 100644 --- a/crates/rb-sys-build/src/bindings.rs +++ b/crates/rb-sys-build/src/bindings.rs @@ -68,9 +68,7 @@ pub fn generate( let bindings = if cfg!(feature = "bindgen-deprecated-types") { bindings } else { - bindings - .blocklist_item("^ruby_fl_type.*") - .blocklist_item("^_bindgen_ty_9.*") + bindings.blocklist_item("^_bindgen_ty_9.*") }; let bindings = opaqueify_bindings(rbconfig, bindings, &mut wrapper_h); diff --git a/crates/rb-sys/src/stable_api/ruby_3_3.rs b/crates/rb-sys/src/stable_api/ruby_3_3.rs index c9c94241..2a7d096a 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_3.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_3.rs @@ -1,7 +1,7 @@ use super::StableApiDefinition; use crate::{ internal::{RArray, RString}, - value_type, VALUE, + value_type, RBasic, VALUE, }; use std::os::raw::{c_char, c_long}; @@ -86,12 +86,16 @@ impl StableApiDefinition for Definition { #[inline] unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 1 + let rbasic = obj as *const crate::RBasic; + + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 } #[inline] unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 0 + let rbasic = obj as *const crate::RBasic; + + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) == 0 } #[inline] From 22fd02081cfd0da1fd0d3c4ad0cf4c7b286035fc Mon Sep 17 00:00:00 2001 From: Jose Narvaez Date: Thu, 5 Dec 2024 18:58:51 +0000 Subject: [PATCH 3/4] Review suggestion: Lets implement bignum_negative_p by default using bignum_positive_p. --- crates/rb-sys/src/stable_api.rs | 4 +++- crates/rb-sys/src/stable_api/ruby_2_6.rs | 5 ----- crates/rb-sys/src/stable_api/ruby_2_7.rs | 5 ----- crates/rb-sys/src/stable_api/ruby_3_0.rs | 5 ----- crates/rb-sys/src/stable_api/ruby_3_1.rs | 5 ----- crates/rb-sys/src/stable_api/ruby_3_2.rs | 5 ----- crates/rb-sys/src/stable_api/ruby_3_3.rs | 9 +-------- crates/rb-sys/src/stable_api/ruby_3_4.rs | 5 ----- 8 files changed, 4 insertions(+), 39 deletions(-) diff --git a/crates/rb-sys/src/stable_api.rs b/crates/rb-sys/src/stable_api.rs index c7a99793..fe3b0cb8 100644 --- a/crates/rb-sys/src/stable_api.rs +++ b/crates/rb-sys/src/stable_api.rs @@ -68,7 +68,9 @@ 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. - unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool; + unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { + !self.bignum_positive_p(obj) + } /// Tests if the given value is a special constant. fn special_const_p(&self, value: VALUE) -> bool; diff --git a/crates/rb-sys/src/stable_api/ruby_2_6.rs b/crates/rb-sys/src/stable_api/ruby_2_6.rs index df6ad043..6a6cfee4 100644 --- a/crates/rb-sys/src/stable_api/ruby_2_6.rs +++ b/crates/rb-sys/src/stable_api/ruby_2_6.rs @@ -101,11 +101,6 @@ impl StableApiDefinition for Definition { crate::rb_big_sign(obj) == 1 } - #[inline] - unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 0 - } - #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_2_7.rs b/crates/rb-sys/src/stable_api/ruby_2_7.rs index 1e7488d2..f03b2dc6 100644 --- a/crates/rb-sys/src/stable_api/ruby_2_7.rs +++ b/crates/rb-sys/src/stable_api/ruby_2_7.rs @@ -101,11 +101,6 @@ impl StableApiDefinition for Definition { crate::rb_big_sign(obj) == 1 } - #[inline] - unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 0 - } - #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_0.rs b/crates/rb-sys/src/stable_api/ruby_3_0.rs index bed16cb9..43f9f33c 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_0.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_0.rs @@ -104,11 +104,6 @@ impl StableApiDefinition for Definition { is_immediate || !test } - #[inline] - unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 1 - } - #[inline] unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { crate::rb_big_sign(obj) == 0 diff --git a/crates/rb-sys/src/stable_api/ruby_3_1.rs b/crates/rb-sys/src/stable_api/ruby_3_1.rs index 0a7a3961..da8f5c3e 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_1.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_1.rs @@ -97,11 +97,6 @@ impl StableApiDefinition for Definition { is_immediate || !test } - #[inline] - unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 1 - } - #[inline] unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { crate::rb_big_sign(obj) == 0 diff --git a/crates/rb-sys/src/stable_api/ruby_3_2.rs b/crates/rb-sys/src/stable_api/ruby_3_2.rs index 8bc155f6..5580f711 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_2.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_2.rs @@ -91,11 +91,6 @@ impl StableApiDefinition for Definition { is_immediate || !test } - #[inline] - unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 1 - } - #[inline] unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { crate::rb_big_sign(obj) == 0 diff --git a/crates/rb-sys/src/stable_api/ruby_3_3.rs b/crates/rb-sys/src/stable_api/ruby_3_3.rs index 2a7d096a..18c9d4b0 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_3.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_3.rs @@ -1,7 +1,7 @@ use super::StableApiDefinition; use crate::{ internal::{RArray, RString}, - value_type, RBasic, VALUE, + value_type, VALUE, }; use std::os::raw::{c_char, c_long}; @@ -91,13 +91,6 @@ impl StableApiDefinition for Definition { ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 } - #[inline] - unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { - let rbasic = obj as *const crate::RBasic; - - ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) == 0 - } - #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_4.rs b/crates/rb-sys/src/stable_api/ruby_3_4.rs index 91b2d460..0f4c2f31 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_4.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_4.rs @@ -89,11 +89,6 @@ impl StableApiDefinition for Definition { crate::rb_big_sign(obj) == 1 } - #[inline] - unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 0 - } - #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; From 9b820887898398c3a932ebf82bb27b244c01f62d Mon Sep 17 00:00:00 2001 From: Jose Narvaez Date: Thu, 5 Dec 2024 19:19:32 +0000 Subject: [PATCH 4/4] Fixing copy/pasta errors. --- crates/rb-sys/src/stable_api/ruby_2_6.rs | 12 +++++++----- crates/rb-sys/src/stable_api/ruby_2_7.rs | 12 +++++++----- crates/rb-sys/src/stable_api/ruby_3_0.rs | 12 +++++++----- crates/rb-sys/src/stable_api/ruby_3_1.rs | 12 +++++++----- crates/rb-sys/src/stable_api/ruby_3_2.rs | 12 +++++++----- crates/rb-sys/src/stable_api/ruby_3_3.rs | 14 +++++++------- crates/rb-sys/src/stable_api/ruby_3_4.rs | 4 +++- 7 files changed, 45 insertions(+), 33 deletions(-) diff --git a/crates/rb-sys/src/stable_api/ruby_2_6.rs b/crates/rb-sys/src/stable_api/ruby_2_6.rs index 6a6cfee4..a36e85be 100644 --- a/crates/rb-sys/src/stable_api/ruby_2_6.rs +++ b/crates/rb-sys/src/stable_api/ruby_2_6.rs @@ -88,6 +88,13 @@ impl StableApiDefinition for Definition { ptr } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + let rbasic = obj as *const crate::RBasic; + + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 + } + #[inline] fn special_const_p(&self, value: VALUE) -> bool { let is_immediate = value & (crate::special_consts::IMMEDIATE_MASK as VALUE) != 0; @@ -96,11 +103,6 @@ impl StableApiDefinition for Definition { is_immediate || !test } - #[inline] - unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 1 - } - #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_2_7.rs b/crates/rb-sys/src/stable_api/ruby_2_7.rs index f03b2dc6..f228c7c3 100644 --- a/crates/rb-sys/src/stable_api/ruby_2_7.rs +++ b/crates/rb-sys/src/stable_api/ruby_2_7.rs @@ -88,6 +88,13 @@ impl StableApiDefinition for Definition { ptr } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + let rbasic = obj as *const crate::RBasic; + + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 + } + #[inline] fn special_const_p(&self, value: VALUE) -> bool { let is_immediate = value & (crate::special_consts::IMMEDIATE_MASK as VALUE) != 0; @@ -96,11 +103,6 @@ impl StableApiDefinition for Definition { is_immediate || !test } - #[inline] - unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 1 - } - #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_0.rs b/crates/rb-sys/src/stable_api/ruby_3_0.rs index 43f9f33c..cc059f91 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_0.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_0.rs @@ -96,6 +96,13 @@ impl StableApiDefinition for Definition { } } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + let rbasic = obj as *const crate::RBasic; + + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 + } + #[inline] fn special_const_p(&self, value: VALUE) -> bool { let is_immediate = value & (crate::special_consts::IMMEDIATE_MASK as VALUE) != 0; @@ -104,11 +111,6 @@ impl StableApiDefinition for Definition { is_immediate || !test } - #[inline] - unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 0 - } - #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_1.rs b/crates/rb-sys/src/stable_api/ruby_3_1.rs index da8f5c3e..e6b747e0 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_1.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_1.rs @@ -89,6 +89,13 @@ impl StableApiDefinition for Definition { ret } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + let rbasic = obj as *const crate::RBasic; + + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 + } + #[inline] fn special_const_p(&self, value: VALUE) -> bool { let is_immediate = value & (crate::special_consts::IMMEDIATE_MASK as VALUE) != 0; @@ -97,11 +104,6 @@ impl StableApiDefinition for Definition { is_immediate || !test } - #[inline] - unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 0 - } - #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_2.rs b/crates/rb-sys/src/stable_api/ruby_3_2.rs index 5580f711..c6f66e5f 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_2.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_2.rs @@ -83,6 +83,13 @@ impl StableApiDefinition for Definition { ptr } + #[inline] + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + let rbasic = obj as *const crate::RBasic; + + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 + } + #[inline] fn special_const_p(&self, value: VALUE) -> bool { let is_immediate = (value) & (crate::special_consts::IMMEDIATE_MASK as VALUE) != 0; @@ -91,11 +98,6 @@ impl StableApiDefinition for Definition { is_immediate || !test } - #[inline] - unsafe fn bignum_negative_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 0 - } - #[inline] unsafe fn builtin_type(&self, obj: VALUE) -> crate::ruby_value_type { let rbasic = obj as *const crate::RBasic; diff --git a/crates/rb-sys/src/stable_api/ruby_3_3.rs b/crates/rb-sys/src/stable_api/ruby_3_3.rs index 18c9d4b0..d4bd09fa 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_3.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_3.rs @@ -77,18 +77,18 @@ impl StableApiDefinition for Definition { } #[inline] - fn special_const_p(&self, value: VALUE) -> bool { - let is_immediate = (value) & (crate::special_consts::IMMEDIATE_MASK as VALUE) != 0; - let test = (value & !(crate::Qnil as VALUE)) != 0; + unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { + let rbasic = obj as *const crate::RBasic; - is_immediate || !test + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 } #[inline] - unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { - let rbasic = obj as *const crate::RBasic; + fn special_const_p(&self, value: VALUE) -> bool { + let is_immediate = (value) & (crate::special_consts::IMMEDIATE_MASK as VALUE) != 0; + let test = (value & !(crate::Qnil as VALUE)) != 0; - ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 + is_immediate || !test } #[inline] diff --git a/crates/rb-sys/src/stable_api/ruby_3_4.rs b/crates/rb-sys/src/stable_api/ruby_3_4.rs index 0f4c2f31..a4a9f7dc 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_4.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_4.rs @@ -86,7 +86,9 @@ impl StableApiDefinition for Definition { #[inline] unsafe fn bignum_positive_p(&self, obj: VALUE) -> bool { - crate::rb_big_sign(obj) == 1 + let rbasic = obj as *const crate::RBasic; + + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_USER1 as VALUE) != 0 } #[inline]