From 7dbfe89630f429255ae346cd02d7ca7d2d109650 Mon Sep 17 00:00:00 2001 From: shugo Date: Thu, 3 Dec 2009 18:25:57 +0000 Subject: [PATCH] * compile.c (compile_cpath, iseq_compile_each): reverted constant/class variable lookup in instance_eval etc. to the behavior of 1.8. * eval.c (rb_mod_nesting): ditto. * insns.def (putspecialobject, defineclass): ditto. * node.h (NODE_FL_CREF_PUSHED_BY_EVAL): ditto. * vm_core.h (VM_SPECIAL_OBJECT_CONST_BASE): ditto. * vm_eval.c (yield_under, eval_under): ditto. * vm_insnhelper.c (vm_cref_push, vm_get_const_base, vm_get_ev_const, vm_get_cvar_base): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 19 ++++++++++++++++++ compile.c | 6 ++++-- eval.c | 3 ++- insns.def | 5 ++++- node.h | 1 + test/ruby/test_module.rb | 27 +++++++++++++++++++++---- test/ruby/test_object.rb | 8 ++++++++ vm_core.h | 5 +++-- vm_eval.c | 10 ++++++---- vm_insnhelper.c | 43 ++++++++++++++++++++++++++++++++-------- 10 files changed, 105 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84da2a7b78..ee90df1ad5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +Fri Dec 4 03:10:38 2009 Shugo Maeda + + * compile.c (compile_cpath, iseq_compile_each): reverted + constant/class variable lookup in instance_eval etc. to the + behavior of 1.8. + + * eval.c (rb_mod_nesting): ditto. + + * insns.def (putspecialobject, defineclass): ditto. + + * node.h (NODE_FL_CREF_PUSHED_BY_EVAL): ditto. + + * vm_core.h (VM_SPECIAL_OBJECT_CONST_BASE): ditto. + + * vm_eval.c (yield_under, eval_under): ditto. + + * vm_insnhelper.c (vm_cref_push, vm_get_const_base, + vm_get_ev_const, vm_get_cvar_base): ditto. + Thu Dec 3 20:27:27 2009 Martin Duerst * enc/trans/gb18030-tbl.rb: Fix omission of C1 region in code table diff --git a/compile.c b/compile.c index 5581ea8439..54b513c4c8 100644 --- a/compile.c +++ b/compile.c @@ -2549,7 +2549,8 @@ compile_cpath(LINK_ANCHOR *ret, rb_iseq_t *iseq, NODE *cpath) } else { /* class at cbase Foo */ - ADD_INSN1(ret, nd_line(cpath), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE)); + ADD_INSN1(ret, nd_line(cpath), putspecialobject, + INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE)); return Qtrue; } } @@ -3710,7 +3711,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } if (node->nd_vid) { - ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE)); + ADD_INSN1(ret, nd_line(node), putspecialobject, + INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE)); ADD_INSN1(ret, nd_line(node), setconstant, ID2SYM(node->nd_vid)); } else { diff --git a/eval.c b/eval.c index 9ac63889cf..c5a72dc609 100644 --- a/eval.c +++ b/eval.c @@ -274,7 +274,8 @@ rb_mod_nesting(void) while (cref && cref->nd_next) { VALUE klass = cref->nd_clss; - if (!NIL_P(klass)) { + if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) && + !NIL_P(klass)) { rb_ary_push(ary, klass); } cref = cref->nd_next; diff --git a/insns.def b/insns.def index 49522974dc..5ad4af7491 100644 --- a/insns.def +++ b/insns.def @@ -343,6 +343,9 @@ putspecialobject case VM_SPECIAL_OBJECT_CBASE: val = vm_get_cbase(GET_ISEQ(), GET_LFP(), GET_DFP()); break; + case VM_SPECIAL_OBJECT_CONST_BASE: + val = vm_get_const_base(GET_ISEQ(), GET_LFP(), GET_DFP()); + break; default: rb_bug("putspecialobject insn: unknown value_type"); } @@ -944,7 +947,7 @@ defineclass rb_bug("unknown defineclass type: %d", (int)define_type); } - COPY_CREF(class_iseq->cref_stack, vm_cref_push(th, klass, NOEX_PUBLIC)); + COPY_CREF(class_iseq->cref_stack, vm_cref_push(th, klass, NOEX_PUBLIC, NULL)); /* enter scope */ vm_push_frame(th, class_iseq, diff --git a/node.h b/node.h index c0fb774bc6..4eb3ded7a2 100644 --- a/node.h +++ b/node.h @@ -262,6 +262,7 @@ typedef struct RNode { /* 0..4:T_TYPES, 5:FL_MARK, 6:reserved, 7:NODE_FL_NEWLINE */ #define NODE_FL_NEWLINE (((VALUE)1)<<7) +#define NODE_FL_CREF_PUSHED_BY_EVAL NODE_FL_NEWLINE #define NODE_TYPESHIFT 8 #define NODE_TYPEMASK (((VALUE)0x7f)<cfp->lfp[0])) != 0) { block = *blockptr; block.self = self; th->cfp->lfp[0] = GC_GUARDED_PTR(&block); } + cref = vm_cref_push(th, under, NOEX_PUBLIC, &block); + cref->flags |= NODE_FL_CREF_PUSHED_BY_EVAL; if (values == Qundef) { - return vm_yield_with_cref(th, 0, 0, cref); + return vm_yield_with_cref(th, 1, &self, cref); } else { return vm_yield_with_cref(th, RARRAY_LENINT(values), RARRAY_PTR(values), cref); @@ -1181,7 +1183,7 @@ yield_under(VALUE under, VALUE self, VALUE values) static VALUE eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line) { - NODE *cref = vm_cref_push(GET_THREAD(), under, NOEX_PUBLIC); + NODE *cref = vm_cref_push(GET_THREAD(), under, NOEX_PUBLIC, NULL); if (rb_safe_level() >= 4) { StringValue(src); diff --git a/vm_insnhelper.c b/vm_insnhelper.c index a05574f1db..8f992d2a8f 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1066,14 +1066,17 @@ vm_get_cref(const rb_iseq_t *iseq, const VALUE *lfp, const VALUE *dfp) } static NODE * -vm_cref_push(rb_thread_t *th, VALUE klass, int noex) +vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr) { rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(th, th->cfp); NODE *cref = NEW_BLOCK(klass); cref->nd_file = 0; cref->nd_visi = noex; - if (cfp) { + if (blockptr) { + cref->nd_next = vm_get_cref(blockptr->iseq, blockptr->lfp, blockptr->dfp); + } + else if (cfp) { cref->nd_next = vm_get_cref(cfp->iseq, cfp->lfp, cfp->dfp); } @@ -1096,6 +1099,23 @@ vm_get_cbase(const rb_iseq_t *iseq, const VALUE *lfp, const VALUE *dfp) return klass; } +static inline VALUE +vm_get_const_base(const rb_iseq_t *iseq, const VALUE *lfp, const VALUE *dfp) +{ + NODE *cref = vm_get_cref(iseq, lfp, dfp); + VALUE klass = Qundef; + + while (cref) { + if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) && + (klass = cref->nd_clss) != 0) { + break; + } + cref = cref->nd_next; + } + + return klass; +} + static inline void vm_check_if_namespace(VALUE klass) { @@ -1117,12 +1137,16 @@ vm_get_ev_const(rb_thread_t *th, const rb_iseq_t *iseq, if (orig_klass == Qnil) { /* in current lexical scope */ - const NODE *root_cref = vm_get_cref(iseq, th->cfp->lfp, th->cfp->dfp); - const NODE *cref = root_cref; + const NODE *cref = vm_get_cref(iseq, th->cfp->lfp, th->cfp->dfp); + const NODE *root_cref = NULL; VALUE klass = orig_klass; while (cref && cref->nd_next) { - klass = cref->nd_clss; + if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL)) { + klass = cref->nd_clss; + if (root_cref == NULL) + root_cref = cref; + } cref = cref->nd_next; if (!NIL_P(klass)) { @@ -1149,8 +1173,10 @@ vm_get_ev_const(rb_thread_t *th, const rb_iseq_t *iseq, } /* search self */ - klass = root_cref->nd_clss; - if (NIL_P(klass)) { + if (root_cref && !NIL_P(root_cref->nd_clss)) { + klass = root_cref->nd_clss; + } + else { klass = CLASS_OF(th->cfp->self); } @@ -1178,7 +1204,8 @@ vm_get_cvar_base(NODE *cref) VALUE klass; while (cref && cref->nd_next && - (NIL_P(cref->nd_clss) || FL_TEST(cref->nd_clss, FL_SINGLETON))) { + (NIL_P(cref->nd_clss) || FL_TEST(cref->nd_clss, FL_SINGLETON) || + (cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL))) { cref = cref->nd_next; if (!cref->nd_next) {