mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[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.
This commit is contained in:
parent
a9a94540d6
commit
84202963c5
Notes:
git
2021-11-12 04:08:58 +09:00
2 changed files with 33 additions and 1 deletions
|
|
@ -521,6 +521,37 @@ class TestSuper < Test::Unit::TestCase
|
||||||
assert_equal(%w[B A], result, bug9721)
|
assert_equal(%w[B A], result, bug9721)
|
||||||
end
|
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
|
def test_from_eval
|
||||||
bug10263 = '[ruby-core:65122] [Bug #10263a]'
|
bug10263 = '[ruby-core:65122] [Bug #10263a]'
|
||||||
a = Class.new do
|
a = Class.new do
|
||||||
|
|
|
||||||
|
|
@ -1936,7 +1936,8 @@ vm_search_method_fastpath(VALUE cd_owner, struct rb_call_data *cd, VALUE klass)
|
||||||
|
|
||||||
#if OPT_INLINE_METHOD_CACHE
|
#if OPT_INLINE_METHOD_CACHE
|
||||||
if (LIKELY(vm_cc_class_check(cc, klass))) {
|
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)));
|
VM_ASSERT(callable_method_entry_p(vm_cc_cme(cc)));
|
||||||
RB_DEBUG_COUNTER_INC(mc_inline_hit);
|
RB_DEBUG_COUNTER_INC(mc_inline_hit);
|
||||||
VM_ASSERT(vm_cc_cme(cc) == NULL || // not found
|
VM_ASSERT(vm_cc_cme(cc) == NULL || // not found
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue