Skip to content

Commit

Permalink
Renamed rbasic_frozen_p to frozen_p and implemented it using bit mask…
Browse files Browse the repository at this point in the history
…ing instead of fcalls
  • Loading branch information
goyox86 committed Dec 5, 2024
1 parent d33e43a commit 883de6c
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 81 deletions.
4 changes: 1 addition & 3 deletions crates/rb-sys-build/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions crates/rb-sys-tests/src/stable_api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
},
Expand All @@ -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")
},
Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys/src/stable_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys/src/stable_api/compiled.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions crates/rb-sys/src/stable_api/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand Down
17 changes: 7 additions & 10 deletions crates/rb-sys/src/stable_api/ruby_2_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 7 additions & 10 deletions crates/rb-sys/src/stable_api/ruby_2_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 7 additions & 10 deletions crates/rb-sys/src/stable_api/ruby_3_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 7 additions & 10 deletions crates/rb-sys/src/stable_api/ruby_3_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 7 additions & 10 deletions crates/rb-sys/src/stable_api/ruby_3_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 7 additions & 10 deletions crates/rb-sys/src/stable_api/ruby_3_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 7 additions & 10 deletions crates/rb-sys/src/stable_api/ruby_3_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 883de6c

Please sign in to comment.