From c3e8cca95040dbae915cad793ccb72f56021bd4a Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 16 Jul 2015 13:13:50 +0000 Subject: [PATCH] * vm_core.h: constify rb_iseq_t::parent_iseq. rb_iseq_t::local_iseq is not constant data because local_iseq::flip_cnt can be modified (commentted). * compile.c: catch up this fix. * iseq.c: ditto. * vm_insnhelper.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++++++++++ compile.c | 31 ++++++++++++++++--------------- iseq.c | 6 +++--- vm_core.h | 4 ++-- vm_insnhelper.c | 4 ++-- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 27a06bd220..de0961a71a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Thu Jul 16 22:05:29 2015 Koichi Sasada + + * vm_core.h: constify rb_iseq_t::parent_iseq. + + rb_iseq_t::local_iseq is not constant data because + local_iseq::flip_cnt can be modified (commentted). + + * compile.c: catch up this fix. + + * iseq.c: ditto. + + * vm_insnhelper.c: ditto. + Thu Jul 16 21:47:47 2015 Naohisa Goto * process.c (redirect_dup2): when the new FD of dup2() coflicts diff --git a/compile.c b/compile.c index 3249e9f2af..bcd6ce8507 100644 --- a/compile.c +++ b/compile.c @@ -1068,7 +1068,7 @@ iseq_set_exception_local_table(rb_iseq_t *iseq) } static int -get_lvar_level(rb_iseq_t *iseq) +get_lvar_level(const rb_iseq_t *iseq) { int lev = 0; while (iseq != iseq->local_iseq) { @@ -1079,7 +1079,7 @@ get_lvar_level(rb_iseq_t *iseq) } static int -get_dyna_var_idx_at_raw(rb_iseq_t *iseq, ID id) +get_dyna_var_idx_at_raw(const rb_iseq_t *iseq, ID id) { int i; @@ -1092,7 +1092,7 @@ get_dyna_var_idx_at_raw(rb_iseq_t *iseq, ID id) } static int -get_local_var_idx(rb_iseq_t *iseq, ID id) +get_local_var_idx(const rb_iseq_t *iseq, ID id) { int idx = get_dyna_var_idx_at_raw(iseq->local_iseq, id); @@ -1104,7 +1104,7 @@ get_local_var_idx(rb_iseq_t *iseq, ID id) } static int -get_dyna_var_idx(rb_iseq_t *iseq, ID id, int *level, int *ls) +get_dyna_var_idx(const rb_iseq_t *iseq, ID id, int *level, int *ls) { int lv = 0, idx = -1; @@ -3124,10 +3124,10 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret, } static VALUE -make_name_for_block(rb_iseq_t *iseq) +make_name_for_block(const rb_iseq_t *iseq) { int level = 1; - rb_iseq_t *ip = iseq; + const rb_iseq_t *ip = iseq; if (iseq->parent_iseq != 0) { while (ip->local_iseq != ip) { @@ -3716,7 +3716,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) COMPILE_ERROR((ERROR_ARGS "Can't escape from eval with break")); } else { - rb_iseq_t *ip = iseq->parent_iseq; + const rb_iseq_t *ip = iseq->parent_iseq; while (ip) { if (!ip->compile_data) { ip = 0; @@ -3781,8 +3781,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) COMPILE_ERROR((ERROR_ARGS "Can't escape from eval with next")); } else { - rb_iseq_t *ip; - ip = iseq; + const rb_iseq_t *ip = iseq; + while (ip) { if (!ip->compile_data) { ip = 0; @@ -3849,10 +3849,10 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } } else { - rb_iseq_t *ip; + const rb_iseq_t *ip = iseq; unsigned long level; level = 0x8000 | 0x4000; - ip = iseq; + while (ip) { if (!ip->compile_data) { ip = 0; @@ -4639,7 +4639,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) else { /* NODE_ZSUPER */ int i; - rb_iseq_t *liseq = iseq->local_iseq; + const rb_iseq_t *liseq = iseq->local_iseq; int lvar_level = get_lvar_level(iseq); argc = liseq->param.lead_num; @@ -5382,7 +5382,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_INSN2(ret, line, getlocal, INT2FIX(2), INT2FIX(0)); } else { - rb_iseq_t *ip = iseq; + const rb_iseq_t *ip = iseq; int level = 0; while (ip) { if (ip->type == ISEQ_TYPE_RESCUE) { @@ -6253,7 +6253,8 @@ int rb_dvar_defined(ID id) { rb_thread_t *th = GET_THREAD(); - rb_iseq_t *iseq; + const rb_iseq_t *iseq; + if (th->base_block && (iseq = th->base_block->iseq)) { while (iseq->type == ISEQ_TYPE_BLOCK || iseq->type == ISEQ_TYPE_RESCUE || @@ -6278,7 +6279,7 @@ int rb_local_defined(ID id) { rb_thread_t *th = GET_THREAD(); - rb_iseq_t *iseq; + const rb_iseq_t *iseq; if (th->base_block && th->base_block->iseq) { int i; diff --git a/iseq.c b/iseq.c index e8440de879..eee0148dff 100644 --- a/iseq.c +++ b/iseq.c @@ -102,7 +102,7 @@ iseq_free(void *ptr) static void iseq_mark(void *ptr) { - rb_iseq_t *iseq = ptr; + const rb_iseq_t *iseq = ptr; RUBY_MARK_ENTER("iseq"); @@ -915,7 +915,7 @@ rb_iseq_base_label(VALUE self) VALUE rb_iseq_first_lineno(VALUE self) { - rb_iseq_t *iseq; + const rb_iseq_t *iseq; GetISeqPtr(self, iseq); return iseq->location.first_lineno; } @@ -923,7 +923,7 @@ rb_iseq_first_lineno(VALUE self) VALUE rb_iseq_method_name(VALUE self) { - rb_iseq_t *iseq, *local_iseq; + const rb_iseq_t *iseq, *local_iseq; GetISeqPtr(self, iseq); local_iseq = iseq->local_iseq; if (local_iseq->type == ISEQ_TYPE_METHOD) { diff --git a/vm_core.h b/vm_core.h index 20e4b5fde7..f98ba80876 100644 --- a/vm_core.h +++ b/vm_core.h @@ -336,8 +336,8 @@ struct rb_iseq_struct { struct iseq_catch_table *catch_table; /* for child iseq */ - struct rb_iseq_struct *parent_iseq; - struct rb_iseq_struct *local_iseq; + const struct rb_iseq_struct *parent_iseq; + struct rb_iseq_struct *local_iseq; /* local_iseq->flip_cnt can be modified */ /****************/ /* dynamic data */ diff --git a/vm_insnhelper.c b/vm_insnhelper.c index c90944e1dc..da4ea9db03 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -841,7 +841,7 @@ vm_throw_start(rb_thread_t * const th, rb_control_frame_t * const reg_cfp, int s else if (state == TAG_BREAK) { int is_orphan = 1; VALUE *ep = GET_EP(); - rb_iseq_t *base_iseq = GET_ISEQ(); + const rb_iseq_t *base_iseq = GET_ISEQ(); escape_cfp = reg_cfp; while (base_iseq->type != ISEQ_TYPE_BLOCK) { @@ -1869,7 +1869,7 @@ current_method_entry(rb_thread_t *th, rb_control_frame_t *cfp) rb_control_frame_t *top_cfp = cfp; if (cfp->iseq && cfp->iseq->type == ISEQ_TYPE_BLOCK) { - rb_iseq_t *local_iseq = cfp->iseq->local_iseq; + const rb_iseq_t *local_iseq = cfp->iseq->local_iseq; do { cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {