summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-03 10:20:49 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-03 10:20:49 +0000
commit54952586fd5ff136843ecf581355a3da5d328f7b (patch)
tree8d285a56312839c037cff3ef1eb849a00d6d10cd
parent309cef7e08eda2dd305fdee35e746fa71ea56e52 (diff)
* proc.c (rb_vm_rewrite_dfp_in_errinfo): Fix `unexpected return'
occurs when a proc is called in ensure. [Backport #6460] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@36287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--bootstraptest/test_flow.rb13
-rw-r--r--proc.c1
-rw-r--r--version.h2
-rw-r--r--vm.c37
-rw-r--r--vm_core.h2
6 files changed, 40 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 6569001023..6e74101333 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Jul 3 19:18:27 2012 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* file.c (rb_enc_path_next, rb_enc_path_skip_prefix)
diff --git a/bootstraptest/test_flow.rb b/bootstraptest/test_flow.rb
index d40d814fbc..fc93a5a46c 100644
--- a/bootstraptest/test_flow.rb
+++ b/bootstraptest/test_flow.rb
@@ -543,6 +543,19 @@ assert_equal %Q{ENSURE\n}, %q{
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
diff --git a/proc.c b/proc.c
index cb44b102a5..943a49a96a 100644
--- a/proc.c
+++ b/proc.c
@@ -417,7 +417,6 @@ proc_new(VALUE klass, int is_lambda)
}
procval = rb_vm_make_proc(th, block, klass);
- rb_vm_rewrite_dfp_in_errinfo(th, cfp);
if (is_lambda) {
rb_proc_t *proc;
diff --git a/version.h b/version.h
index 670806a4ec..d3815de2a8 100644
--- a/version.h
+++ b/version.h
@@ -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
diff --git a/vm.c b/vm.c
index e997afa0c7..3d7b76e2b9 100644
--- a/vm.c
+++ b/vm.c
@@ -424,8 +424,6 @@ vm_make_env_each(rb_thread_t * const th, rb_control_frame_t * const cfp,
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 @@ rb_vm_make_env_object(rb_thread_t * th, rb_control_frame_t *cfp)
}
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 @@ 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)
-{
- /* 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_vm_rewrite_dfp_in_errinfo(rb_thread_t *th)
+{
+ 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);
}
}
diff --git a/vm_core.h b/vm_core.h
index 7211005169..60146f0d62 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -651,7 +651,7 @@ VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self,
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,