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

ruby-changes:69875

From: nagachika <ko1@a...>
Date: Tue, 23 Nov 2021 15:12:12 +0900 (JST)
Subject: [ruby-changes:69875] b6f87d527f (ruby_3_0): merge revision(s) 84202963c52e02cecad3e6b2fad478bfbeee1bc7: [Backport #18329]

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

From b6f87d527f59257f07ba6774addaefdedee4fcde Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Tue, 23 Nov 2021 14:19:44 +0900
Subject: merge revision(s) 84202963c52e02cecad3e6b2fad478bfbeee1bc7: [Backport
 #18329]

	[Bug #18329] Fix crash when calling non-existent super method

	The cme is NULL when a method does not exist, so check it before
	accessing the callcache.
	---
	 test/ruby/test_super.rb | 31 +++++++++++++++++++++++++++++++
	 vm_insnhelper.c         |  3 ++-
	 2 files changed, 33 insertions(+), 1 deletion(-)
---
 test/ruby/test_super.rb | 31 +++++++++++++++++++++++++++++++
 version.h               |  4 ++--
 vm_insnhelper.c         |  3 ++-
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb
index d94f4679d32..3afde9b0e3a 100644
--- a/test/ruby/test_super.rb
+++ b/test/ruby/test_super.rb
@@ -521,6 +521,37 @@ class TestSuper < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_super.rb#L521
     assert_equal(%w[B A], result, bug9721)
   end
 
+  # [Bug #18329]
+  def test_super_missing_prepended_module
+    a = Module.new do
+      def probe(*methods)
+        prepend(probing_module(methods))
+      end
+
+      def probing_module(methods)
+        Module.new do
+          methods.each do |method|
+            define_method(method) do |*args, **kwargs, &block|
+              super(*args, **kwargs, &block)
+            end
+          end
+        end
+      end
+    end
+
+    b = Class.new do
+      extend a
+
+      probe :danger!, :missing
+
+      def danger!; end
+    end
+
+    o = b.new
+    o.danger!
+    2.times { o.missing rescue NoMethodError }
+  end
+
   def test_from_eval
     bug10263 = '[ruby-core:65122] [Bug #10263a]'
     a = Class.new do
diff --git a/version.h b/version.h
index 9303a7e6c3d..5f7bdee1ca5 100644
--- a/version.h
+++ b/version.h
@@ -12,11 +12,11 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L12
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 3
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 150
+#define RUBY_PATCHLEVEL 151
 
 #define RUBY_RELEASE_YEAR 2021
 #define RUBY_RELEASE_MONTH 11
-#define RUBY_RELEASE_DAY 22
+#define RUBY_RELEASE_DAY 23
 
 #include "ruby/version.h"
 
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index fc2c7f8fcaa..757e75d66fa 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1806,7 +1806,8 @@ vm_search_method_fastpath(VALUE cd_owner, struct rb_call_data *cd, VALUE klass) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1806
 
 #if OPT_INLINE_METHOD_CACHE
     if (LIKELY(vm_cc_class_check(cc, klass))) {
-        if (LIKELY(!METHOD_ENTRY_INVALIDATED(vm_cc_cme(cc)))) {
+        const struct rb_callable_method_entry_struct *cme = vm_cc_cme(cc);
+        if (LIKELY(cme && !METHOD_ENTRY_INVALIDATED(cme))) {
             VM_ASSERT(callable_method_entry_p(vm_cc_cme(cc)));
             RB_DEBUG_COUNTER_INC(mc_inline_hit);
             VM_ASSERT(vm_cc_cme(cc) == NULL ||                        // not found
-- 
cgit v1.2.1


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

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