summaryrefslogtreecommitdiff
path: root/vm_method.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-13 13:29:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-13 13:29:23 +0000
commitb71956d12b061613f8ef9dfe3f8a75e56dfa799d (patch)
tree11f455de1e876bfc478efee2052b0c8ed07e4279 /vm_method.c
parentf1f609bc22a8aea2de4a3d564147ffb73a9ac211 (diff)
proc.c, vm_method.c: fix super and alias
* proc.c (method_owner): return the class where alias is defined, not the class original method is defined. * vm_method.c (rb_method_entry_make, rb_alias): store the originally defined class in me. [Bug #7993] [Bug #7842] [Bug #9236] * vm_method.c (rb_method_entry_get_without_cache): cache included module but not iclass. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_method.c')
-rw-r--r--vm_method.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/vm_method.c b/vm_method.c
index a95c37e30e..af336db616 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -227,7 +227,8 @@ rb_add_refined_method_entry(VALUE refined_class, ID mid)
static rb_method_entry_t *
rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
- rb_method_definition_t *def, rb_method_flag_t noex)
+ rb_method_definition_t *def, rb_method_flag_t noex,
+ VALUE defined_class)
{
rb_method_entry_t *me;
#if NOEX_NOREDEF
@@ -321,7 +322,7 @@ rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
me->flag = NOEX_WITH_SAFE(noex);
me->mark = 0;
me->called_id = mid;
- me->klass = klass;
+ me->klass = defined_class;
me->def = def;
if (def) {
@@ -422,7 +423,7 @@ rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_
rb_thread_t *th;
rb_control_frame_t *cfp;
int line;
- rb_method_entry_t *me = rb_method_entry_make(klass, mid, type, 0, noex);
+ rb_method_entry_t *me = rb_method_entry_make(klass, mid, type, 0, noex, klass);
rb_method_definition_t *def = ALLOC(rb_method_definition_t);
if (me->def && me->def->type == VM_METHOD_TYPE_REFINED) {
me->def->body.orig_me->def = def;
@@ -481,15 +482,23 @@ rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_
return me;
}
-rb_method_entry_t *
-rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me, rb_method_flag_t noex)
+static rb_method_entry_t *
+method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me,
+ rb_method_flag_t noex, VALUE defined_class)
{
rb_method_type_t type = me->def ? me->def->type : VM_METHOD_TYPE_UNDEF;
- rb_method_entry_t *newme = rb_method_entry_make(klass, mid, type, me->def, noex);
+ rb_method_entry_t *newme = rb_method_entry_make(klass, mid, type, me->def, noex,
+ defined_class);
method_added(klass, mid);
return newme;
}
+rb_method_entry_t *
+rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me, rb_method_flag_t noex)
+{
+ return method_entry_set(klass, mid, me, noex, klass);
+}
+
#define UNDEF_ALLOC_FUNC ((rb_alloc_func_t)-1)
void
@@ -551,6 +560,9 @@ rb_method_entry_get_without_cache(VALUE klass, ID id,
VALUE defined_class;
rb_method_entry_t *me = search_method(klass, id, &defined_class);
+ if (me && RB_TYPE_P(me->klass, T_ICLASS))
+ defined_class = me->klass;
+
if (ruby_running) {
struct cache_entry *ent;
ent = GLOBAL_METHOD_CACHE(klass, id);
@@ -1218,6 +1230,7 @@ void
rb_alias(VALUE klass, ID name, ID def)
{
VALUE target_klass = klass;
+ VALUE defined_class;
rb_method_entry_t *orig_me;
rb_method_flag_t flag = NOEX_UNDEF;
@@ -1228,7 +1241,7 @@ rb_alias(VALUE klass, ID name, ID def)
rb_frozen_class_p(klass);
again:
- orig_me = search_method(klass, def, 0);
+ orig_me = search_method(klass, def, &defined_class);
if (UNDEFINED_METHOD_ENTRY_P(orig_me)) {
if ((!RB_TYPE_P(klass, T_MODULE)) ||
@@ -1243,9 +1256,14 @@ rb_alias(VALUE klass, ID name, ID def)
flag = orig_me->flag;
goto again;
}
+ if (RB_TYPE_P(defined_class, T_ICLASS)) {
+ VALUE real_class = RBASIC_CLASS(defined_class);
+ if (real_class && RCLASS_ORIGIN(real_class) == defined_class)
+ defined_class = real_class;
+ }
if (flag == NOEX_UNDEF) flag = orig_me->flag;
- rb_method_entry_set(target_klass, name, orig_me, flag);
+ method_entry_set(target_klass, name, orig_me, flag, defined_class);
}
/*