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

ruby-changes:60874

From: Koichi <ko1@a...>
Date: Thu, 23 Apr 2020 02:22:04 +0900 (JST)
Subject: [ruby-changes:60874] 8119bcbfc0 (master): rb_method_entry() returns valid me.

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

From 8119bcbfc04772fe4012b5ed396a68f02e312316 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 23 Apr 2020 02:16:12 +0900
Subject: rb_method_entry() returns valid me.

search_method() can return invalid method, but vm_defined() checks
it as valid method entry. This is why defined?(foo) if foo is undef'ed.
To solve this problem, check invalidation and return NULL.
[Bug #16669]
https://twitter.com/kamipo/status/1252881930103558144

Tests will be merged by nobu soon.

diff --git a/vm_method.c b/vm_method.c
index afda598..1910b1e 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -936,7 +936,13 @@ search_method_protect(VALUE klass, ID id, VALUE *defined_class_ptr) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L936
 MJIT_FUNC_EXPORTED const rb_method_entry_t *
 rb_method_entry(VALUE klass, ID id)
 {
-    return search_method(klass, id, NULL);
+    const rb_method_entry_t *me = search_method(klass, id, NULL);
+    if (me && me->def && me->def->type != VM_METHOD_TYPE_UNDEF) {
+        return me;
+    }
+    else {
+        return NULL;
+    }
 }
 
 static inline const rb_callable_method_entry_t *
-- 
cgit v0.10.2


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

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