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

ruby-changes:60391

From: Nobuyoshi <ko1@a...>
Date: Sat, 14 Mar 2020 20:27:58 +0900 (JST)
Subject: [ruby-changes:60391] c7e0ce6743 (ruby_2_7): Add the loaded feature after no exception raised

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

From c7e0ce67430b5e312eb626a2c2f4b6a810b3b68b Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 4 Feb 2020 15:21:49 +0900
Subject: Add the loaded feature after no exception raised

Retrying after rescued `require` should try to load the same
library again.  [Bug #16607]

(cherry picked from commit 7d6903dc476f982e7b432adbeef3a3d9372a309f)

diff --git a/load.c b/load.c
index fda100f..07acc9a 100644
--- a/load.c
+++ b/load.c
@@ -1007,7 +1007,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception) https://github.com/ruby/ruby/blob/trunk/load.c#L1007
 		result = 0;
 	    }
 	    else if (!*ftptr) {
-		rb_provide_feature(path);
 		result = TAG_RETURN;
 	    }
 	    else {
@@ -1022,7 +1021,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception) https://github.com/ruby/ruby/blob/trunk/load.c#L1021
 		    rb_ary_push(ruby_dln_librefs, LONG2NUM(handle));
 		    break;
 		}
-                rb_provide_feature(path);
                 result = TAG_RETURN;
 	    }
 	}
@@ -1056,6 +1054,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception) https://github.com/ruby/ruby/blob/trunk/load.c#L1054
         rb_exc_raise(ec->errinfo);
     }
 
+    if (result == TAG_RETURN) rb_provide_feature(path);
     ec->errinfo = errinfo;
 
     RUBY_DTRACE_HOOK(REQUIRE_RETURN, RSTRING_PTR(fname));
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index 05dc18c..a86ea35 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -214,6 +214,13 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L214
     assert_syntax_error_backtrace {|req| require req}
   end
 
+  def test_require_syntax_error_rescued
+    assert_syntax_error_backtrace do |req|
+      assert_raise_with_message(SyntaxError, /unexpected/) {require req}
+      require req
+    end
+  end
+
   def test_load_syntax_error
     assert_syntax_error_backtrace {|req| load req}
   end
-- 
cgit v0.10.2


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

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