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

ruby-changes:59134

From: nagachika <ko1@a...>
Date: Mon, 9 Dec 2019 21:25:55 +0900 (JST)
Subject: [ruby-changes:59134] 00f4c13e22 (ruby_2_6): merge revision(s) 7d805e67f3275aef066d77aa9c32bef715c362ed: [Backport #15780]

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

From 00f4c13e22967de1d7e42085b2fc32bf6718f580 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Mon, 9 Dec 2019 12:25:34 +0000
Subject: merge revision(s) 7d805e67f3275aef066d77aa9c32bef715c362ed: [Backport
 #15780]

	Avoid triggering autoload in Module#const_defined?(String)

	[Bug #15780]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

diff --git a/object.c b/object.c
index 7928592..454d357 100644
--- a/object.c
+++ b/object.c
@@ -2698,16 +2698,19 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod) https://github.com/ruby/ruby/blob/trunk/object.c#L2698
         if (!RTEST(recur)) {
 	    if (!rb_const_defined_at(mod, id))
 		return Qfalse;
+            if (p == pend) return Qtrue;
 	    mod = rb_const_get_at(mod, id);
 	}
         else if (beglen == 0) {
             if (!rb_const_defined(mod, id))
                 return Qfalse;
+            if (p == pend) return Qtrue;
             mod = rb_const_get(mod, id);
         }
         else {
             if (!rb_const_defined_from(mod, id))
                 return Qfalse;
+            if (p == pend) return Qtrue;
             mod = rb_const_get_from(mod, id);
         }
 #endif
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb
index d6af169..ba81321 100644
--- a/spec/ruby/core/module/autoload_spec.rb
+++ b/spec/ruby/core/module/autoload_spec.rb
@@ -409,6 +409,7 @@ describe "Module#autoload" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/autoload_spec.rb#L409
   it "does not load the file when accessing the constants table of the module" do
     ModuleSpecs::Autoload.autoload :P, @non_existent
     ModuleSpecs::Autoload.const_defined?(:P).should be_true
+    ModuleSpecs::Autoload.const_defined?("P").should be_true
   end
 
   it "loads the file when opening a module that is the autoloaded constant" do
diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb
index 8311c40..1d2d1af 100644
--- a/test/ruby/test_autoload.rb
+++ b/test/ruby/test_autoload.rb
@@ -42,8 +42,10 @@ p Foo::Bar https://github.com/ruby/ruby/blob/trunk/test/ruby/test_autoload.rb#L42
     require 'tmpdir'
     Dir.mktmpdir('autoload') {|tmpdir|
       tmpfile = tmpdir + '/foo.rb'
+      tmpfile2 = tmpdir + '/bar.rb'
       a = Module.new do
         autoload :X, tmpfile
+        autoload :Y, tmpfile2
       end
       b = Module.new do
         include a
@@ -52,6 +54,10 @@ p Foo::Bar https://github.com/ruby/ruby/blob/trunk/test/ruby/test_autoload.rb#L54
       assert_equal(true, b.const_defined?(:X))
       assert_equal(tmpfile, a.autoload?(:X), bug4565)
       assert_equal(tmpfile, b.autoload?(:X), bug4565)
+      assert_equal(true, a.const_defined?("Y"))
+      assert_equal(true, b.const_defined?("Y"))
+      assert_equal(tmpfile2, a.autoload?("Y"))
+      assert_equal(tmpfile2, b.autoload?("Y"))
     }
   end
 
diff --git a/version.h b/version.h
index 65491c2..d9885ec 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.6"
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 118
+#define RUBY_PATCHLEVEL 119
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 12
-- 
cgit v0.10.2


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

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