ruby-changes:24236
From: naruse <ko1@a...>
Date: Tue, 3 Jul 2012 19:20:59 +0900 (JST)
Subject: [ruby-changes:24236] naruse:r36287 (ruby_1_9_3): * proc.c (rb_vm_rewrite_dfp_in_errinfo): Fix `unexpected return'
naruse 2012-07-03 19:20:49 +0900 (Tue, 03 Jul 2012) New Revision: 36287 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36287 Log: * proc.c (rb_vm_rewrite_dfp_in_errinfo): Fix `unexpected return' occurs when a proc is called in ensure. [Backport #6460] Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/bootstraptest/test_flow.rb branches/ruby_1_9_3/proc.c branches/ruby_1_9_3/version.h branches/ruby_1_9_3/vm.c branches/ruby_1_9_3/vm_core.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 36286) +++ ruby_1_9_3/ChangeLog (revision 36287) @@ -1,3 +1,8 @@ +Tue Jul 3 19:18:27 2012 NARUSE, Yui <naruse@r...> + + * proc.c (rb_vm_rewrite_dfp_in_errinfo): Fix `unexpected return' + occurs when a proc is called in ensure. [Backport #6460] + Tue Jul 3 11:44:23 2012 Nobuyoshi Nakada <nobu@r...> * file.c (rb_enc_path_next, rb_enc_path_skip_prefix) Index: ruby_1_9_3/bootstraptest/test_flow.rb =================================================================== --- ruby_1_9_3/bootstraptest/test_flow.rb (revision 36286) +++ ruby_1_9_3/bootstraptest/test_flow.rb (revision 36287) @@ -543,6 +543,19 @@ end end e = Bug5234.new +}], + ['[ruby-dev:45656]', %q{ + class Bug6460 + include Enumerable + def each + begin + yield :foo + ensure + 1.times { Proc.new } + end + end + end + e = Bug6460.new }]].each do |bug, src| assert_equal "foo", src + %q{e.detect {true}}, bug assert_equal "true", src + %q{e.any? {true}}, bug Index: ruby_1_9_3/vm_core.h =================================================================== --- ruby_1_9_3/vm_core.h (revision 36286) +++ ruby_1_9_3/vm_core.h (revision 36287) @@ -651,7 +651,7 @@ int argc, const VALUE *argv, const rb_block_t *blockptr); VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass); VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp); -void rb_vm_rewrite_dfp_in_errinfo(rb_thread_t *th, rb_control_frame_t *cfp); +void rb_vm_rewrite_dfp_in_errinfo(rb_thread_t *th); void rb_vm_inc_const_missing_count(void); void rb_vm_gvl_destroy(rb_vm_t *vm); VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, Index: ruby_1_9_3/proc.c =================================================================== --- ruby_1_9_3/proc.c (revision 36286) +++ ruby_1_9_3/proc.c (revision 36287) @@ -417,7 +417,6 @@ } procval = rb_vm_make_proc(th, block, klass); - rb_vm_rewrite_dfp_in_errinfo(th, cfp); if (is_lambda) { rb_proc_t *proc; Index: ruby_1_9_3/vm.c =================================================================== --- ruby_1_9_3/vm.c (revision 36286) +++ ruby_1_9_3/vm.c (revision 36287) @@ -424,8 +424,6 @@ if (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { /* TODO */ env->block.iseq = 0; - } else { - rb_vm_rewrite_dfp_in_errinfo(th, cfp); } return envval; } @@ -480,6 +478,7 @@ } envval = vm_make_env_each(th, cfp, cfp->dfp, cfp->lfp); + rb_vm_rewrite_dfp_in_errinfo(th); if (PROCDEBUG) { check_env_value(envval); @@ -489,24 +488,28 @@ } void -rb_vm_rewrite_dfp_in_errinfo(rb_thread_t *th, rb_control_frame_t *cfp) +rb_vm_rewrite_dfp_in_errinfo(rb_thread_t *th) { - /* rewrite dfp in errinfo to point to heap */ - if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) && - (cfp->iseq->type == ISEQ_TYPE_RESCUE || - cfp->iseq->type == ISEQ_TYPE_ENSURE)) { - VALUE errinfo = cfp->dfp[-2]; /* #$! */ - if (RB_TYPE_P(errinfo, T_NODE)) { - VALUE *escape_dfp = GET_THROWOBJ_CATCH_POINT(errinfo); - if (! ENV_IN_HEAP_P(th, escape_dfp)) { - VALUE dfpval = *escape_dfp; - if (CLASS_OF(dfpval) == rb_cEnv) { - rb_env_t *dfpenv; - GetEnvPtr(dfpval, dfpenv); - SET_THROWOBJ_CATCH_POINT(errinfo, (VALUE)(dfpenv->env + dfpenv->local_size)); + rb_control_frame_t *cfp = th->cfp; + while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) { + /* rewrite dfp in errinfo to point to heap */ + if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) && + (cfp->iseq->type == ISEQ_TYPE_RESCUE || + cfp->iseq->type == ISEQ_TYPE_ENSURE)) { + VALUE errinfo = cfp->dfp[-2]; /* #$! */ + if (RB_TYPE_P(errinfo, T_NODE)) { + VALUE *escape_dfp = GET_THROWOBJ_CATCH_POINT(errinfo); + if (! ENV_IN_HEAP_P(th, escape_dfp)) { + VALUE dfpval = *escape_dfp; + if (CLASS_OF(dfpval) == rb_cEnv) { + rb_env_t *dfpenv; + GetEnvPtr(dfpval, dfpenv); + SET_THROWOBJ_CATCH_POINT(errinfo, (VALUE)(dfpenv->env + dfpenv->local_size)); + } } } } + cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); } } Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 36286) +++ ruby_1_9_3/version.h (revision 36287) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 247 +#define RUBY_PATCHLEVEL 248 #define RUBY_RELEASE_DATE "2012-07-03" #define RUBY_RELEASE_YEAR 2012 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/