From 6b7c4dfa6776083517564850032609618acbb710 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 7 Aug 2015 08:07:58 +0000 Subject: proc.c: fix for uncallable method * proc.c (method_super_method): uncallable method entry does not have the defined class, use the owner instead. [ruby-core:70254] [Bug #11419] * test/ruby/test_method.rb (test_super_method_unbound): add test by Akira Matsuda. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- proc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'proc.c') diff --git a/proc.c b/proc.c index 4b67c69755..0d8ae11f09 100644 --- a/proc.c +++ b/proc.c @@ -1249,6 +1249,12 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope) return mnew_from_me(me, klass, obj, id, mclass, scope); } +static inline VALUE +method_entry_defined_class(const rb_method_entry_t *me) +{ + VALUE defined_class = me->defined_class; + return defined_class ? defined_class : me->owner; +} /********************************************************************** * @@ -1299,8 +1305,8 @@ method_eq(VALUE method, VALUE other) m1 = (struct METHOD *)DATA_PTR(method); m2 = (struct METHOD *)DATA_PTR(other); - klass1 = m1->me->defined_class ? m1->me->defined_class : m1->me->owner; - klass2 = m2->me->defined_class ? m2->me->defined_class : m2->me->owner; + klass1 = method_entry_defined_class(m1->me); + klass2 = method_entry_defined_class(m2->me); if (!rb_method_entry_eq(m1->me, m2->me) || klass1 != klass2 || @@ -2326,7 +2332,7 @@ method_inspect(VALUE method) defined_class = data->me->def->body.alias.original_me->owner; } else { - defined_class = data->me->defined_class ? data->me->defined_class : data->me->owner; + defined_class = method_entry_defined_class(data->me); } if (RB_TYPE_P(defined_class, T_ICLASS)) { @@ -2451,7 +2457,7 @@ method_super_method(VALUE method) const rb_method_entry_t *me; TypedData_Get_Struct(method, struct METHOD, &method_data_type, data); - super_class = RCLASS_SUPER(data->me->defined_class); + super_class = RCLASS_SUPER(method_entry_defined_class(data->me)); if (!super_class) return Qnil; me = (rb_method_entry_t *)rb_callable_method_entry_without_refinements(super_class, data->me->called_id); if (!me) return Qnil; -- cgit v1.2.3