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

ruby-changes:56879

From: Nobuyoshi <ko1@a...>
Date: Fri, 9 Aug 2019 00:16:28 +0900 (JST)
Subject: [ruby-changes:56879] Nobuyoshi Nakada: ad3f7a3667 (master): Should require without wrapper module

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

From ad3f7a3667d79a7d23c78e026d3eb5a42bd0b7b3 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 9 Aug 2019 00:06:08 +0900
Subject: Should require without wrapper module


diff --git a/load.c b/load.c
index 8b872a8..c3d1d63 100644
--- a/load.c
+++ b/load.c
@@ -978,6 +978,9 @@ static int https://github.com/ruby/ruby/blob/trunk/load.c#L978
 require_internal(rb_execution_context_t *ec, VALUE fname, int safe, int exception)
 {
     volatile int result = -1;
+    rb_thread_t *th = rb_ec_thread_ptr(ec);
+    volatile VALUE wrapper = th->top_wrapper;
+    volatile VALUE self = th->top_self;
     volatile VALUE errinfo = ec->errinfo;
     enum ruby_tag_type state;
     struct {
@@ -993,6 +996,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int safe, int exceptio https://github.com/ruby/ruby/blob/trunk/load.c#L996
     EC_PUSH_TAG(ec);
     saved.safe = rb_safe_level();
     ec->errinfo = Qnil; /* ensure */
+    th->top_wrapper = 0;
     if ((state = EC_EXEC_TAG()) == TAG_NONE) {
 	long handle;
 	int found;
@@ -1029,6 +1033,9 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int safe, int exceptio https://github.com/ruby/ruby/blob/trunk/load.c#L1033
 	}
     }
     EC_POP_TAG();
+    th = rb_ec_thread_ptr(ec);
+    th->top_self = self;
+    th->top_wrapper = wrapper;
     if (ftptr) load_unlock(RSTRING_PTR(path), !state);
 
     rb_set_safe_level_force(saved.safe);
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index 2504b9e..6c4b97d 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -384,6 +384,19 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L384
     }
   end
 
+  def test_require_in_wrapped_load
+    Dir.mktmpdir do |tmp|
+      File.write("#{tmp}/1.rb", "require_relative '2'\n")
+      File.write("#{tmp}/2.rb", "class Foo\n""end\n")
+      assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+      path = ""#{tmp.dump}"/1.rb"
+      begin;
+        load path, true
+        assert_instance_of(Class, Foo)
+      end;
+    end
+  end
+
   def test_load_scope
     bug1982 = '[ruby-core:25039] [Bug #1982]'
     Tempfile.create(["test_ruby_test_require", ".rb"]) {|t|
-- 
cgit v0.10.2


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

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