summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Bernstein <[email protected]>2025-03-13 12:16:58 -0400
committerTakashi Kokubun <[email protected]>2025-04-18 21:53:00 +0900
commit97f022b5e75f124f08fa44794f65fe1b112818eb (patch)
treeba682aabeb31bb62307cc4b885a1d86e45086c76
parentc39a150787d77dc706f8af65ad46710b3d879190 (diff)
Print Ruby exception in test utils
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13131
-rw-r--r--yjit/bindgen/src/main.rs1
-rw-r--r--zjit.c9
-rw-r--r--zjit/src/cruby.rs6
-rw-r--r--zjit/src/cruby_bindings.inc.rs1
4 files changed, 15 insertions, 2 deletions
diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs
index df675304e8..b9f3651e0e 100644
--- a/yjit/bindgen/src/main.rs
+++ b/yjit/bindgen/src/main.rs
@@ -359,6 +359,7 @@ fn main() {
.allowlist_function("rb_yjit_invokeblock_sp_pops")
.allowlist_function("rb_yjit_set_exception_return")
.allowlist_function("rb_yjit_str_concat_codepoint")
+ .allowlist_function("rb_zjit_print_exception")
.allowlist_type("robject_offsets")
.allowlist_type("rstring_offsets")
diff --git a/zjit.c b/zjit.c
index af11ac2949..21c257cd32 100644
--- a/zjit.c
+++ b/zjit.c
@@ -681,5 +681,14 @@ rb_iseq_set_zjit_payload(const rb_iseq_t *iseq, void *payload)
// Primitives used by zjit.rb
VALUE rb_zjit_assert_compiles(rb_execution_context_t *ec, VALUE self);
+void
+rb_zjit_print_exception(void)
+{
+ VALUE exception = rb_errinfo();
+ rb_set_errinfo(Qnil);
+ assert(RTEST(exception));
+ rb_warn("Ruby error: %"PRIsVALUE"", rb_funcall(exception, rb_intern("full_message"), 0));
+}
+
// Preprocessed zjit.rb generated during build
#include "zjit.rbinc"
diff --git a/zjit/src/cruby.rs b/zjit/src/cruby.rs
index dff8d301d6..c0093dd284 100644
--- a/zjit/src/cruby.rs
+++ b/zjit/src/cruby.rs
@@ -939,8 +939,10 @@ pub mod test_utils {
let mut state: c_int = 0;
unsafe { super::rb_protect(Some(callback_wrapper), VALUE((&mut data) as *mut _ as usize), &mut state) };
- // TODO(alan): there should be a way to print the exception instead of swallowing it
- assert_eq!(0, state, "Exceptional unwind in callback. Ruby exception?");
+ if state != 0 {
+ unsafe { rb_zjit_print_exception(); }
+ assert_eq!(0, state, "Exceptional unwind in callback. Ruby exception?");
+ }
result.expect("Callback did not set result")
}
diff --git a/zjit/src/cruby_bindings.inc.rs b/zjit/src/cruby_bindings.inc.rs
index 6c5a7c82bf..01da0bff47 100644
--- a/zjit/src/cruby_bindings.inc.rs
+++ b/zjit/src/cruby_bindings.inc.rs
@@ -1023,4 +1023,5 @@ unsafe extern "C" {
pub fn rb_RCLASS_ORIGIN(c: VALUE) -> VALUE;
pub fn rb_iseq_get_zjit_payload(iseq: *const rb_iseq_t) -> *mut ::std::os::raw::c_void;
pub fn rb_iseq_set_zjit_payload(iseq: *const rb_iseq_t, payload: *mut ::std::os::raw::c_void);
+ pub fn rb_zjit_print_exception();
}