summaryrefslogtreecommitdiff
path: root/vm_method.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-22 14:33:11 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-22 14:33:11 +0000
commitf0f3821be7507a96e613e6d8e7e675eada78a892 (patch)
treee4a52931045ae0d6a5f6252837eb6fa0054fc1cb /vm_method.c
parent86d9d122bef745aad9bf3dabd80ad03fbec1beec (diff)
merge revision(s) 44175,44179: [Backport #9236]
* 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. * proc.c (mnew_from_me): achieve the original defined_class from prepended iclass, to fix inherited owner. * proc.c (method_owner): return the defined class, but not the class which the method object is created from. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@44345 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 2801107c16..6a6485e09c 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -222,7 +222,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
@@ -320,7 +321,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) def->alias_count++;
@@ -404,7 +405,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;
@@ -460,15 +461,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
@@ -524,6 +533,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 = cache + EXPR1(klass, id);
@@ -1182,6 +1194,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;
@@ -1195,7 +1208,7 @@ rb_alias(VALUE klass, ID name, ID def)
}
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)) ||
@@ -1210,9 +1223,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(defined_class)->klass;
+ 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);
}
/*