From 883de6c78ab94c9c638e9cbceb8ddf2fe2e943b9 Mon Sep 17 00:00:00 2001 From: Jose Narvaez Date: Thu, 5 Dec 2024 21:47:49 +0000 Subject: [PATCH] Renamed rbasic_frozen_p to frozen_p and implemented it using bit masking instead of fcalls --- crates/rb-sys-build/src/bindings.rs | 4 +--- crates/rb-sys-tests/src/stable_api_test.rs | 4 ++-- crates/rb-sys/src/stable_api.rs | 2 +- crates/rb-sys/src/stable_api/compiled.c | 2 +- crates/rb-sys/src/stable_api/compiled.rs | 8 ++++---- crates/rb-sys/src/stable_api/ruby_2_6.rs | 17 +++++++---------- crates/rb-sys/src/stable_api/ruby_2_7.rs | 17 +++++++---------- crates/rb-sys/src/stable_api/ruby_3_0.rs | 17 +++++++---------- crates/rb-sys/src/stable_api/ruby_3_1.rs | 17 +++++++---------- crates/rb-sys/src/stable_api/ruby_3_2.rs | 17 +++++++---------- crates/rb-sys/src/stable_api/ruby_3_3.rs | 17 +++++++---------- crates/rb-sys/src/stable_api/ruby_3_4.rs | 17 +++++++---------- 12 files changed, 58 insertions(+), 81 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-tests/src/stable_api_test.rs b/crates/rb-sys-tests/src/stable_api_test.rs index 8e66360f..9ac97fba 100644 --- a/crates/rb-sys-tests/src/stable_api_test.rs +++ b/crates/rb-sys-tests/src/stable_api_test.rs @@ -203,7 +203,7 @@ parity_test!( parity_test!( name: test_rbasic_frozen_p_not_frozen_obj, - func: rbasic_frozen_p, + func: frozen_p, data_factory: { ruby_eval!("[1]") }, @@ -212,7 +212,7 @@ parity_test!( parity_test!( name: test_rbasic_frozen_p_frozen_obj, - func: rbasic_frozen_p, + func: frozen_p, data_factory: { ruby_eval!("[1].freeze") }, diff --git a/crates/rb-sys/src/stable_api.rs b/crates/rb-sys/src/stable_api.rs index 5df1f4f5..418061bb 100644 --- a/crates/rb-sys/src/stable_api.rs +++ b/crates/rb-sys/src/stable_api.rs @@ -68,7 +68,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 non-immediate object. - unsafe fn rbasic_frozen_p(&self, obj: VALUE) -> bool; + unsafe fn frozen_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 84ba2471..da050104 100644 --- a/crates/rb-sys/src/stable_api/compiled.c +++ b/crates/rb-sys/src/stable_api/compiled.c @@ -26,7 +26,7 @@ impl_rbasic_class(VALUE obj) { } int -impl_rbasic_frozen_p(VALUE obj) { +impl_frozen_p(VALUE obj) { return RB_OBJ_FROZEN(obj); } diff --git a/crates/rb-sys/src/stable_api/compiled.rs b/crates/rb-sys/src/stable_api/compiled.rs index 241f1980..5e43b539 100644 --- a/crates/rb-sys/src/stable_api/compiled.rs +++ b/crates/rb-sys/src/stable_api/compiled.rs @@ -19,8 +19,8 @@ extern "C" { #[link_name = "impl_rbasic_class"] fn impl_rbasic_class(obj: VALUE) -> VALUE; - #[link_name = "impl_rbasic_frozen_p"] - fn impl_rbasic_frozen_p(obj: VALUE) -> bool; + #[link_name = "impl_frozen_p"] + fn impl_frozen_p(obj: VALUE) -> bool; #[link_name = "impl_special_const_p"] fn impl_special_const_p(value: VALUE) -> bool; @@ -95,8 +95,8 @@ impl StableApiDefinition for Definition { impl_rbasic_class(obj) } - unsafe fn rbasic_frozen_p(&self, obj: VALUE) -> bool { - impl_rbasic_frozen_p(obj) + unsafe fn frozen_p(&self, obj: VALUE) -> bool { + impl_frozen_p(obj) } #[inline] 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 2f47fd75..7c6ec52c 100644 --- a/crates/rb-sys/src/stable_api/ruby_2_6.rs +++ b/crates/rb-sys/src/stable_api/ruby_2_6.rs @@ -96,16 +96,13 @@ impl StableApiDefinition for Definition { } #[inline] - unsafe fn rbasic_frozen_p(&self, obj: VALUE) -> bool { - // FIXME: Why this does not work? - // if self.special_const_p(obj) { - // true - // } else { - // let rbasic = obj as *const crate::RBasic; - // ((*rbasic).flags & crate::ruby_value_type::FL_FREEZE as VALUE) != 0 - // } - - !(crate::rb_obj_frozen_p(obj) == 0) + unsafe fn frozen_p(&self, obj: VALUE) -> bool { + if self.special_const_p(obj) { + true + } else { + let rbasic = obj as *const crate::Rbasic; + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_FREEZE as VALUE) != 0 + } } #[inline] 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 92f378e6..30c56431 100644 --- a/crates/rb-sys/src/stable_api/ruby_2_7.rs +++ b/crates/rb-sys/src/stable_api/ruby_2_7.rs @@ -96,16 +96,13 @@ impl StableApiDefinition for Definition { } #[inline] - unsafe fn rbasic_frozen_p(&self, obj: VALUE) -> bool { - // FIXME: Why this does not work? - // if self.special_const_p(obj) { - // true - // } else { - // let rbasic = obj as *const crate::RBasic; - // ((*rbasic).flags & crate::ruby_value_type::FL_FREEZE as VALUE) != 0 - // } - - !(crate::rb_obj_frozen_p(obj) == 0) + unsafe fn frozen_p(&self, obj: VALUE) -> bool { + if self.special_const_p(obj) { + true + } else { + let rbasic = obj as *const crate::RBasic; + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_FREEZE as VALUE) != 0 + } } #[inline] 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 61fbe6c2..25c25fe3 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_0.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_0.rs @@ -104,16 +104,13 @@ impl StableApiDefinition for Definition { } #[inline] - unsafe fn rbasic_frozen_p(&self, obj: VALUE) -> bool { - // FIXME: Why this does not work? - // if self.special_const_p(obj) { - // true - // } else { - // let rbasic = obj as *const crate::RBasic; - // ((*rbasic).flags & crate::ruby_value_type::FL_FREEZE as VALUE) != 0 - // } - - !(crate::rb_obj_frozen_p(obj) == 0) + unsafe fn frozen_p(&self, obj: VALUE) -> bool { + if self.special_const_p(obj) { + true + } else { + let rbasic = obj as *const crate::RBasic; + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_FREEZE as VALUE) != 0 + } } #[inline] 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 30688798..2ba86629 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_1.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_1.rs @@ -97,16 +97,13 @@ impl StableApiDefinition for Definition { } #[inline] - unsafe fn rbasic_frozen_p(&self, obj: VALUE) -> bool { - // FIXME: Why this does not work? - // if self.special_const_p(obj) { - // true - // } else { - // let rbasic = obj as *const crate::RBasic; - // ((*rbasic).flags & crate::ruby_value_type::FL_FREEZE as VALUE) != 0 - // } - - !(crate::rb_obj_frozen_p(obj) == 0) + unsafe fn frozen_p(&self, obj: VALUE) -> bool { + if self.special_const_p(obj) { + true + } else { + let rbasic = obj as *const crate::RBasic; + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_FREEZE as VALUE) != 0 + } } #[inline] 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 061f1592..83dbddff 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_2.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_2.rs @@ -91,16 +91,13 @@ impl StableApiDefinition for Definition { } #[inline] - unsafe fn rbasic_frozen_p(&self, obj: VALUE) -> bool { - // FIXME: Why this does not work? - // if self.special_const_p(obj) { - // true - // } else { - // let rbasic = obj as *const crate::RBasic; - // ((*rbasic).flags & crate::ruby_value_type::FL_FREEZE as VALUE) != 0 - // } - - !(crate::rb_obj_frozen_p(obj) == 0) + unsafe fn frozen_p(&self, obj: VALUE) -> bool { + if self.special_const_p(obj) { + true + } else { + let rbasic = obj as *const crate::RBasic; + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_FREEZE as VALUE) != 0 + } } #[inline] 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 63181459..4d718988 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_3.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_3.rs @@ -84,16 +84,13 @@ impl StableApiDefinition for Definition { } #[inline] - unsafe fn rbasic_frozen_p(&self, obj: VALUE) -> bool { - // FIXME: Why this does not work? - // if self.special_const_p(obj) { - // true - // } else { - // let rbasic = obj as *const crate::RBasic; - // ((*rbasic).flags & crate::ruby_value_type::FL_FREEZE as VALUE) != 0 - // } - - !(crate::rb_obj_frozen_p(obj) == 0) + unsafe fn frozen_p(&self, obj: VALUE) -> bool { + if self.special_const_p(obj) { + true + } else { + let rbasic = obj as *const crate::RBasic; + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_FREEZE as VALUE) != 0 + } } #[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 1467a9d0..d67732e0 100644 --- a/crates/rb-sys/src/stable_api/ruby_3_4.rs +++ b/crates/rb-sys/src/stable_api/ruby_3_4.rs @@ -48,16 +48,13 @@ impl StableApiDefinition for Definition { } #[inline] - unsafe fn rbasic_frozen_p(&self, obj: VALUE) -> bool { - // FIXME: Why this does not work? - // if self.special_const_p(obj) { - // true - // } else { - // let rbasic = obj as *const crate::RBasic; - // ((*rbasic).flags & crate::ruby_value_type::FL_FREEZE as VALUE) != 0 - // } - - !(crate::rb_obj_frozen_p(obj) == 0) + unsafe fn frozen_p(&self, obj: VALUE) -> bool { + if self.special_const_p(obj) { + true + } else { + let rbasic = obj as *const crate::RBasic; + ((*rbasic).flags & crate::ruby_fl_type::RUBY_FL_FREEZE as VALUE) != 0 + } } #[inline]