Skip to content

Commit c6cd4e4

Browse files
aardvark179eregon
authored andcommitted
Populate rb_errinfo when rb_protect captures a ruby exception.
(cherry picked from commit 6a1aaa7)
1 parent 1b4bf00 commit c6cd4e4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/truffle/truffle/cext.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ def rb_protect(function, arg, write_status, status)
992992
unless Primitive.object_equal(nil, e)
993993
store = (Thread.current[:__stored_exceptions__] ||= [])
994994
pos = store.push(e).size
995+
Primitive.thread_set_exception(extract_ruby_exception(e))
995996
end
996997

997998
Truffle::Interop.execute_without_conversion(write_status, status, pos)

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,23 @@ protected Object executeWithProtect(RubyProc block,
11851185
}
11861186
}
11871187

1188+
@CoreMethod(names = "extract_ruby_exception", onSingleton = true, required = 1)
1189+
public abstract static class ExtractRubyException extends CoreMethodArrayArgumentsNode {
1190+
1191+
/** Profiled version of {@link ExceptionOperations#rethrow(Throwable)} */
1192+
@Specialization
1193+
protected Object executeThrow(CapturedException captured,
1194+
@Cached ConditionProfile rubyExceptionProfile,
1195+
@Cached ConditionProfile errorProfile) {
1196+
final Throwable e = captured.getException();
1197+
if (rubyExceptionProfile.profile(e instanceof RaiseException)) {
1198+
return ((RaiseException) e).getException();
1199+
} else {
1200+
return nil;
1201+
}
1202+
}
1203+
}
1204+
11881205
@CoreMethod(names = "raise_exception", onSingleton = true, required = 1)
11891206
public abstract static class RaiseExceptionNode extends CoreMethodArrayArgumentsNode {
11901207

0 commit comments

Comments
 (0)