summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2025-03-14 17:12:26 -0400
committerTakashi Kokubun <[email protected]>2025-04-18 21:53:00 +0900
commit19e8e45f69027b485484e4afdffbe17a9bf211ba ()
treea05258eb96e8a4d373472c7450daf496aa271cbf
parentfa7c3e6c9c0e7b6b0d0b1611c696ba74a6f45165 (diff)
Rust tests: Load builtins (core library written in ruby)
Key here is calling rb_call_builtin_inits(), which sticking to public API for robustness is done by calling ruby_options(). Fixes: https://.com/Shopify/zjit/issues/61
Notes: Merged: https://.com/ruby/ruby/pull/13131
-rw-r--r--yjit/bindgen/src/main.rs2
-rw-r--r--zjit/src/cruby.rs33
-rw-r--r--zjit/src/cruby_bindings.inc.rs8
-rw-r--r--zjit/src/hir.rs7
4 files changed, 43 insertions, 7 deletions
@@ -96,6 +96,8 @@ fn main() {
// For testing
.allowlist_function("ruby_init")
.allowlist_function("ruby_init_stack")
.allowlist_function("rb_funcallv")
.allowlist_function("rb_protect")
@@ -904,9 +904,29 @@ pub mod test_utils {
fn boot_rubyvm() {
// Boot the VM
unsafe {
let mut var: VALUE = Qnil;
ruby_init_stack(&mut var as *mut VALUE as *mut _);
ruby_init();
crate::cruby::ids::init(); // for ID! usages in tests
}
@@ -1041,6 +1061,19 @@ pub mod test_utils {
rb_funcallv(rb_cISeq, ID!(compile), 1, &program_str)
}
}
}
#[cfg(test)]
pub use test_utils::*;
@@ -791,6 +791,14 @@ unsafe extern "C" {
pub static mut rb_cThread: VALUE;
pub static mut rb_cTrueClass: VALUE;
pub fn ruby_init();
pub fn ruby_init_stack(addr: *mut ::std::os::raw::c_void);
pub fn rb_define_class(name: *const ::std::os::raw::c_char, super_: VALUE) -> VALUE;
pub fn rb_obj_class(obj: VALUE) -> VALUE;
@@ -1519,13 +1519,6 @@ mod tests {
}
#[test]
- fn boot_vm() {
- let program = "nil.itself";
- let iseq = compile_to_iseq(program);
- assert!(iseq_to_hir(iseq).is_ok());
- }
-
- #[test]
fn test_putobject() {
eval("def test = 123");
assert_method_hir("test", "