summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-27 10:14:29 +0000
committerktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-27 10:14:29 +0000
commit3bffb317d69977f3da4b384913740f30995e6725 (patch)
tree0be245e3baad2cd691cb0a755614a5efe0693363
parent9754ed4885b6f54f73200208087f83476da0c78a (diff)
* backport r33096 from trunk.
* proc.c (proc_new): force to rewrite errinfo when calling Proc.new in ensure. [Bug #5234] [ruby-core:39125] * vm.c (rb_vm_rewrite_dfp_in_errinfo): new function. * vm.c (vm_make_env_each): changed accordingly. * vm_core.h: ditto. * bootstraptest/test_flow.rb: add tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@33098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog15
-rw-r--r--bootstraptest/test_flow.rb13
-rw-r--r--proc.c1
-rw-r--r--vm.c39
-rw-r--r--vm_core.h1
5 files changed, 53 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 8a9cd2cb13..e290daa867 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Sat Aug 27 19:03:44 2011 Kazuki Tsujimoto <kazuki@callcc.net>
+
+ * backport r33096 from trunk.
+
+ * proc.c (proc_new): force to rewrite errinfo when calling Proc.new in ensure.
+ [Bug #5234] [ruby-core:39125]
+
+ * vm.c (rb_vm_rewrite_dfp_in_errinfo): new function.
+
+ * vm.c (vm_make_env_each): changed accordingly.
+
+ * vm_core.h: ditto.
+
+ * bootstraptest/test_flow.rb: add tests for above.
+
Sat Aug 27 08:59:12 2011 Eric Hodel <drbrain@segment7.net>
* NEWS: Update version of rake to 0.9.2.2.
diff --git a/bootstraptest/test_flow.rb b/bootstraptest/test_flow.rb
index 100ad0a2f1..d40d814fbc 100644
--- a/bootstraptest/test_flow.rb
+++ b/bootstraptest/test_flow.rb
@@ -530,6 +530,19 @@ assert_equal %Q{ENSURE\n}, %q{
end
end
e = Bug2729.new
+}],
+ ['[ruby-core:39125]', %q{
+ class Bug5234
+ include Enumerable
+ def each
+ begin
+ yield :foo
+ ensure
+ proc
+ end
+ end
+ end
+ e = Bug5234.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 427d1fe744..47c8614480 100644
--- a/proc.c
+++ b/proc.c
@@ -417,6 +417,7 @@ 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/vm.c b/vm.c
index 4805e286e7..cbf79f189f 100644
--- a/vm.c
+++ b/vm.c
@@ -416,22 +416,7 @@ vm_make_env_each(rb_thread_t * const th, rb_control_frame_t * const cfp,
/* TODO */
env->block.iseq = 0;
} else {
- /* rewrite dfp in errinfo to point to heap */
- if (cfp->iseq->type == ISEQ_TYPE_RESCUE ||
- cfp->iseq->type == ISEQ_TYPE_ENSURE) {
- VALUE errinfo = env->env[0]; /* #$! */
- 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(th, cfp);
}
return envval;
}
@@ -494,6 +479,28 @@ rb_vm_make_env_object(rb_thread_t * th, rb_control_frame_t *cfp)
return envval;
}
+VALUE
+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));
+ }
+ }
+ }
+ }
+}
+
void
rb_vm_stack_to_heap(rb_thread_t *th)
{
diff --git a/vm_core.h b/vm_core.h
index 1cb7788439..749e9a03e1 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -651,6 +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);
+VALUE rb_vm_rewrite_dfp_in_errinfo(rb_thread_t *th, rb_control_frame_t *cfp);
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,