diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-17 09:25:11 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-17 09:25:11 +0000 |
commit | fbf633c3723368470cf7adf79e703b06c3ed4a0c (patch) | |
tree | c52f01d87e7f31f809bf6d8a87e2cb7b009822f2 /proc.c | |
parent | 2a13a71e80e2be2dbc84ba3d9eeb0b3100345869 (diff) |
merge revision(s) 63067,63068: [Backport #14658]
Fix Kernel#singleton_method with Module#Prepend
* proc.c (rb_obj_singleton_method): search the method entry from
the origin class, for fix prepended modules. [Bug #14658]
From: Vasiliy Ermolovich <younash@gmail.com>
proc.c: fix segfault when no singleton class
* proc.c (rb_obj_singleton_method): bail out if the receiver does
not have the singleton class without accessing the origin class
not to segfault. [Bug #14658]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@65118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -1766,21 +1766,23 @@ VALUE rb_obj_singleton_method(VALUE obj, VALUE vid) { const rb_method_entry_t *me; - VALUE klass; + VALUE klass = rb_singleton_class_get(obj); ID id = rb_check_id(&vid); + if (NIL_P(klass) || NIL_P(klass = RCLASS_ORIGIN(klass))) { + undef: + rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'", + obj, vid); + } if (!id) { - if (!NIL_P(klass = rb_singleton_class_get(obj)) && - respond_to_missing_p(klass, obj, vid, FALSE)) { + if (respond_to_missing_p(klass, obj, vid, FALSE)) { id = rb_intern_str(vid); return mnew_missing(klass, obj, id, rb_cMethod); } - undef: - rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'", - obj, vid); + goto undef; } - if (NIL_P(klass = rb_singleton_class_get(obj)) || - UNDEFINED_METHOD_ENTRY_P(me = rb_method_entry_at(klass, id)) || + me = rb_method_entry_at(klass, id); + if (UNDEFINED_METHOD_ENTRY_P(me) || UNDEFINED_REFINED_METHOD_P(me->def)) { vid = ID2SYM(id); goto undef; |