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

ruby-changes:69945

From: Koichi <ko1@a...>
Date: Fri, 26 Nov 2021 10:56:17 +0900 (JST)
Subject: [ruby-changes:69945] e984c2a9ea (master): fix to choose correct callcache

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

From e984c2a9ea29fa17c5f55d324d181f8eaa677d69 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 25 Nov 2021 15:57:36 +0900
Subject: fix to choose correct callcache

It should retun general `cc`, not for overloaded (mandatory only)
method call cache.

This issue is reported by @shugo and @ktou
https://twitter.com/shugomaeda/status/1463699797182119936
---
 test/ruby/test_iseq.rb |  7 +++++++
 vm_eval.c              | 13 +++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 847ce6995cf..ac191531dec 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -714,4 +714,11 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L714
       RubyVM::InstructionSequence.compile("", debug_level: 5)
     end;
   end
+
+  def test_mandatory_only
+    assert_separately [], <<~RUBY
+      at0 = Time.at(0)
+      assert_equal at0, Time.public_send(:at, 0, 0)
+    RUBY
+  end
 end
diff --git a/vm_eval.c b/vm_eval.c
index 983baf7de67..73739fc3a5e 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -382,7 +382,7 @@ static inline enum method_missing_reason rb_method_call_status(rb_execution_cont https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L382
 static const struct rb_callcache *
 cc_new(VALUE klass, ID mid, int argc, const rb_callable_method_entry_t *cme)
 {
-    const struct rb_callcache *cc;
+    const struct rb_callcache *cc = NULL;
 
     RB_VM_LOCK_ENTER();
     {
@@ -399,10 +399,15 @@ cc_new(VALUE klass, ID mid, int argc, const rb_callable_method_entry_t *cme) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L399
             rb_id_table_insert(cc_tbl, mid, (VALUE)ccs);
         }
 
-        if (ccs->len > 0) {
-            cc = ccs->entries[0].cc;
+        for (int i=0; i<ccs->len; i++) {
+            cc = ccs->entries[i].cc;
+            if (vm_cc_cme(cc) == cme) {
+                break;
+            }
+            cc = NULL;
         }
-        else {
+
+        if (cc == NULL) {
             const struct rb_callinfo *ci = vm_ci_new(mid, 0, argc, false); // TODO: proper ci
             cc = vm_cc_new(klass, cme, vm_call_general);
             METHOD_ENTRY_CACHED_SET((struct rb_callable_method_entry_struct *)cme);
-- 
cgit v1.2.1


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

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