Skip to content

Commit 0bd3e43

Browse files
committed
merge revision(s) c79d2e5: [Backport #18562]
Fix TAG_THROW through require [Bug #18562] Previously this was being incorrectly swapped with TAG_RAISE in the next line. This would end up checking the T_IMEMO throw_data to the exception handling (which calls Module#===). This happened to not break existing tests because Module#=== returned false when klass is NULL. This commit handles throw from require correctly by jumping to the tag retaining the TAG_THROW state. --- load.c | 2 +- test/ruby/test_exception.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
1 parent f4f0c79 commit 0bd3e43

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

load.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception)
11311131
if (ftptr) load_unlock(RSTRING_PTR(path), !state);
11321132

11331133
if (state) {
1134-
if (state == TAG_FATAL) {
1134+
if (state == TAG_FATAL || state == TAG_THROW) {
11351135
EC_JUMP_TAG(ec, state);
11361136
}
11371137
else if (exception) {

test/ruby/test_exception.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,27 @@ def test_catch_throw_in_require
181181
}
182182
end
183183

184+
def test_catch_throw_in_require_cant_be_rescued
185+
bug18562 = '[ruby-core:107403]'
186+
Tempfile.create(["dep", ".rb"]) {|t|
187+
t.puts("throw :extdep, 42")
188+
t.close
189+
190+
rescue_all = Class.new(Exception)
191+
def rescue_all.===(_)
192+
raise "should not reach here"
193+
end
194+
195+
v = assert_throw(:extdep, bug18562) do
196+
require t.path
197+
rescue rescue_all => e
198+
assert(false, "should not reach here")
199+
end
200+
201+
assert_equal(42, v, bug18562)
202+
}
203+
end
204+
184205
def test_throw_false
185206
bug12743 = '[ruby-core:77229] [Bug #12743]'
186207
Thread.start {

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1313
#define RUBY_VERSION_TEENY 4
1414
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
15-
#define RUBY_PATCHLEVEL 194
15+
#define RUBY_PATCHLEVEL 195
1616

1717
#define RUBY_RELEASE_YEAR 2022
1818
#define RUBY_RELEASE_MONTH 3

0 commit comments

Comments
 (0)