summaryrefslogtreecommitdiff
path: root/vm_method.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-06 12:24:58 (GMT)
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-06 12:24:58 (GMT)
commitd84f9b16946bca06ce0557ebe99152d7d445c9ec (patch)
tree8141a5d835d1e5638231aced09a08c74ff8fadae /vm_method.c
parente0f5a6ab4850e2745d5cb6fb081eb81dc024d2d4 (diff)
* fix namespace issue on singleton class expressions. [Bug #10943]
* vm_core.h, method.h: remove rb_iseq_t::cref_stack. CREF is stored to rb_method_definition_t::body.iseq_body.cref. * vm_insnhelper.c: modify SVAR usage. When calling ISEQ type method, push CREF information onto method frame, SVAR located place. Before this fix, SVAR is simply nil. After this patch, CREF (or NULL == Qfalse for not iseq methods) is stored at the method invocation. When SVAR is requierd, then put NODE_IF onto SVAR location, and NDOE_IF::nd_reserved points CREF itself. * vm.c (vm_cref_new, vm_cref_dump, vm_cref_new_toplevel): added. * vm_insnhelper.c (vm_push_frame): accept CREF. * method.h, vm_method.c (rb_add_method_iseq): added. This function accepts iseq and CREF. * class.c (clone_method): use rb_add_method_iseq(). * gc.c (mark_method_entry): mark method_entry::body.iseq_body.cref. * iseq.c: remove CREF related codes. * insns.def (getinlinecache/setinlinecache): CREF should be cache key because a different CREF has a different namespace. * node.c (rb_gc_mark_node): mark NODE_IF::nd_reserved for SVAR. * proc.c: catch up changes. * struct.c: ditto. * insns.def: ditto. * vm_args.c (raise_argument_error): ditto. * vm_eval.c: ditto. * test/ruby/test_class.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_method.c')
-rw-r--r--vm_method.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/vm_method.c b/vm_method.c
index 7dd2f4b..d5fe524 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -245,8 +245,7 @@ rb_add_refined_method_entry(VALUE refined_class, ID mid)
rb_clear_method_cache_by_class(refined_class);
}
else {
- rb_add_method(refined_class, mid, VM_METHOD_TYPE_REFINED, 0,
- NOEX_PUBLIC);
+ rb_add_method(refined_class, mid, VM_METHOD_TYPE_REFINED, 0, NOEX_PUBLIC);
}
}
@@ -325,7 +324,7 @@ rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
rb_warning("method redefined; discarding old %"PRIsVALUE, rb_id2str(mid));
switch (old_def->type) {
case VM_METHOD_TYPE_ISEQ:
- iseq = old_def->body.iseq;
+ iseq = old_def->body.iseq_body.iseq;
break;
case VM_METHOD_TYPE_BMETHOD:
iseq = rb_proc_get_iseq(old_def->body.proc, 0);
@@ -359,7 +358,8 @@ rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
switch(def->type) {
case VM_METHOD_TYPE_ISEQ:
- RB_OBJ_WRITTEN(klass, Qundef, def->body.iseq->self);
+ RB_OBJ_WRITTEN(klass, Qundef, def->body.iseq_body.iseq->self);
+ RB_OBJ_WRITTEN(klass, Qundef, def->body.iseq_body.cref);
break;
case VM_METHOD_TYPE_IVAR:
RB_OBJ_WRITTEN(klass, Qundef, def->body.attr.location);
@@ -447,27 +447,40 @@ setup_method_cfunc_struct(rb_method_cfunc_t *cfunc, VALUE (*func)(), int argc)
}
rb_method_entry_t *
-rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_flag_t noex)
+rb_add_method0(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_flag_t noex, NODE *cref)
{
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, 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;
}
else {
me->def = def;
}
+
+ if (0 && cref) vm_cref_dump("rb_add_method0", cref);
+
def->type = type;
def->original_id = mid;
def->alias_count = 0;
+
switch (type) {
case VM_METHOD_TYPE_ISEQ: {
rb_iseq_t *iseq = (rb_iseq_t *)opts;
- *(rb_iseq_t **)&def->body.iseq = iseq;
- RB_OBJ_WRITTEN(klass, Qundef, iseq->self);
+ NODE *private_cref;
+
+ *(rb_iseq_t **)&def->body.iseq_body.iseq = iseq;
+ RB_OBJ_WRITTEN(klass, Qundef, iseq->self); /* should be set iseq before newobj */
+ def->body.iseq_body.cref = NULL;
+
+ private_cref = vm_cref_new_toplevel(GET_THREAD()); /* TODO: CREF should be shared with other methods */
+ if (cref) COPY_CREF(private_cref, cref);
+ private_cref->nd_visi = NOEX_PUBLIC;
+ RB_OBJ_WRITE(klass, &def->body.iseq_body.cref, private_cref);
break;
}
case VM_METHOD_TYPE_CFUNC:
@@ -511,13 +524,24 @@ rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_
return me;
}
+rb_method_entry_t *
+rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_flag_t noex)
+{
+ return rb_add_method0(klass, mid, type, opts, noex, NULL);
+}
+
+void
+rb_add_method_iseq(VALUE klass, ID mid, rb_iseq_t *iseq, NODE *cref, rb_method_flag_t noex)
+{
+ rb_add_method0(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, noex, cref);
+}
+
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,
- defined_class);
+ rb_method_entry_t *newme = rb_method_entry_make(klass, mid, type, me->def, noex, defined_class);
method_added(klass, mid);
return newme;
}
@@ -1195,7 +1219,7 @@ rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_defini
}
switch (d1->type) {
case VM_METHOD_TYPE_ISEQ:
- return d1->body.iseq == d2->body.iseq;
+ return d1->body.iseq_body.iseq == d2->body.iseq_body.iseq;
case VM_METHOD_TYPE_CFUNC:
return
d1->body.cfunc.func == d2->body.cfunc.func &&
@@ -1226,7 +1250,7 @@ rb_hash_method_definition(st_index_t hash, const rb_method_definition_t *def)
hash = rb_hash_uint(hash, def->type);
switch (def->type) {
case VM_METHOD_TYPE_ISEQ:
- return rb_hash_uint(hash, (st_index_t)def->body.iseq);
+ return rb_hash_uint(hash, (st_index_t)def->body.iseq_body.iseq);
case VM_METHOD_TYPE_CFUNC:
hash = rb_hash_uint(hash, (st_index_t)def->body.cfunc.func);
return rb_hash_uint(hash, def->body.cfunc.argc);