[前][次][番号順一覧][スレッド一覧]

ruby-changes:71676

From: NAKAMURA <ko1@a...>
Date: Thu, 7 Apr 2022 22:53:00 +0900 (JST)
Subject: [ruby-changes:71676] 19fec939a6 (ruby_2_7): merge revision(s) c79d2e54748f52c5023b0a1ee441561df9826c17: [Backport #18562]

https://git.ruby-lang.org/ruby.git/commit/?id=19fec939a6

From 19fec939a6fed650135c6ce8b567fcb7b001b068 Mon Sep 17 00:00:00 2001
From: NAKAMURA Usaku <usa@r...>
Date: Sat, 19 Mar 2022 22:45:51 +0900
Subject: merge revision(s) c79d2e54748f52c5023b0a1ee441561df9826c17: [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(-)
---
 load.c                      |  2 +-
 test/ruby/test_exception.rb | 21 +++++++++++++++++++++
 version.h                   |  2 +-
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/load.c b/load.c
index 2441acfded..51c21ee4f2 100644
--- a/load.c
+++ b/load.c
@@ -1076,7 +1076,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception) https://github.com/ruby/ruby/blob/trunk/load.c#L1076
     if (ftptr) load_unlock(RSTRING_PTR(path), !state);
 
     if (state) {
-        if (state == TAG_FATAL) {
+        if (state == TAG_FATAL || state == TAG_THROW) {
             EC_JUMP_TAG(ec, state);
         }
         else if (exception) {
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 69bf7ebf0e..9efcfc76cf 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -181,6 +181,27 @@ class TestException < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L181
     }
   end
 
+  def test_catch_throw_in_require_cant_be_rescued
+    bug18562 = '[ruby-core:107403]'
+    Tempfile.create(["dep", ".rb"]) {|t|
+      t.puts("throw :extdep, 42")
+      t.close
+
+      rescue_all = Class.new(Exception)
+      def rescue_all.===(_)
+        raise "should not reach here"
+      end
+
+      v = assert_throw(:extdep, bug18562) do
+        require t.path
+      rescue rescue_all => e
+        assert(false, "should not reach here")
+      end
+
+      assert_equal(42, v, bug18562)
+    }
+  end
+
   def test_throw_false
     bug12743 = '[ruby-core:77229] [Bug #12743]'
     Thread.start {
diff --git a/version.h b/version.h
index 6fbb66953c..944a877c76 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L2
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 6
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 216
+#define RUBY_PATCHLEVEL 217
 
 #define RUBY_RELEASE_YEAR 2022
 #define RUBY_RELEASE_MONTH 3
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]