diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-04-23 02:16:12 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-04-23 02:21:38 +0900 |
commit | 8119bcbfc04772fe4012b5ed396a68f02e312316 (patch) | |
tree | b3fc2b8edc8532f4a634de3e2321cf060228ec27 /vm_method.c | |
parent | 492e8599c60ed22b940aac40f8907fd58f1a879b (diff) |
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.
Diffstat (limited to 'vm_method.c')
-rw-r--r-- | vm_method.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/vm_method.c b/vm_method.c index afda598aa1..1910b1e46d 100644 --- a/vm_method.c +++ b/vm_method.c @@ -936,7 +936,13 @@ search_method_protect(VALUE klass, ID id, VALUE *defined_class_ptr) 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 * |