Skip to content

Commit 953cc21

Browse files
committed
[GR-18163] Fix rb_rescue2() to stop when seeing the (VALUE)0 argument
PullRequest: truffleruby/2125
2 parents 70531ba + adc9bf1 commit 953cc21

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Bug fixes:
4141
* Fixed `SystemStackError` sometimes replaced by an internal Java `NoClassDefFoundError` on JVM (#1743).
4242
* Fixed constant/identifier detection in lexer for non-ASCII encodings (#2079, #2102, @ivoanjo).
4343
* Fixed parsing of `--jvm` as an application argument (#2108).
44+
* Fix `rb_rescue2` to ignore the end marker `(VALUE)0` (#2127, #2130).
4445

4546
Compatibility:
4647

spec/ruby/optional/capi/kernel_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,20 @@ def proc_caller
396396
proc = -> x { x }
397397
arg_error_proc = -> *_ { raise ArgumentError, '' }
398398
run_error_proc = -> *_ { raise RuntimeError, '' }
399-
type_error_proc = -> *_ { raise TypeError, '' }
399+
type_error_proc = -> *_ { raise Exception, 'custom error' }
400400
@s.rb_rescue2(arg_error_proc, :no_exc, proc, :exc, ArgumentError, RuntimeError).should == :exc
401401
@s.rb_rescue2(run_error_proc, :no_exc, proc, :exc, ArgumentError, RuntimeError).should == :exc
402402
-> {
403403
@s.rb_rescue2(type_error_proc, :no_exc, proc, :exc, ArgumentError, RuntimeError)
404-
}.should raise_error(TypeError)
404+
}.should raise_error(Exception, 'custom error')
405+
end
406+
407+
ruby_bug "#17305", ""..."2.7" do
408+
it "raises TypeError if one of the passed exceptions is not a Module" do
409+
-> {
410+
@s.rb_rescue2(-> *_ { raise RuntimeError, "foo" }, :no_exc, -> x { x }, :exc, Object.new, 42)
411+
}.should raise_error(TypeError, /class or module required/)
412+
end
405413
end
406414
end
407415

src/main/c/cext/exception.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ VALUE rb_rescue2(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*r_proc)(ANYARGS)
8585
// arguments using the polyglot api.
8686
for (;n < total; n++) {
8787
VALUE arg = polyglot_get_arg(n);
88+
if (arg == (VALUE)0) {
89+
break;
90+
}
91+
8892
rb_ary_push(rescued, arg);
8993
}
9094
return cext_rb_rescue2(b_proc, data1, r_proc, data2, rb_tr_unwrap(rescued));

0 commit comments

Comments
 (0)