summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-02 19:14:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-02 19:14:24 +0000
commitf7894e422a935d975f7fc4130b73fefba16a9433 (patch)
tree90ef867c4dee346545b93989aba1978ed1c9a7e2
parent0446be770e48de54a32e7f383f064e734473785a (diff)
vm.c: rewrite all catch points
* vm.c (rb_vm_rewrite_ep_in_errinfo): rewrite all catch points in errinfo, not only the topmost frame. based on the patch by ktsj (Kazuki Tsujimoto) in [ruby-dev:45656]. [Bug #6460] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--KNOWNBUGS.rb18
-rw-r--r--bootstraptest/test_flow.rb40
-rw-r--r--vm.c16
4 files changed, 60 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 1182432562..9dfcb03e84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat Nov 3 04:14:19 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * vm.c (rb_vm_rewrite_ep_in_errinfo): rewrite all catch points in
+ errinfo, not only the topmost frame. based on the patch by
+ ktsj (Kazuki Tsujimoto) in [ruby-dev:45656]. [Bug #6460]
+
Fri Nov 2 20:11:17 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (MakeMakefile#timestamp_file): remove @ which looks like
diff --git a/KNOWNBUGS.rb b/KNOWNBUGS.rb
index 2bcedcb150..b97a08d928 100644
--- a/KNOWNBUGS.rb
+++ b/KNOWNBUGS.rb
@@ -3,21 +3,3 @@
# So all tests will cause failure.
#
-[['[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
- assert_equal "false", src + %q{e.all? {false}}, bug
- assert_equal "true", src + %q{e.include?(:foo)}, bug
-end
diff --git a/bootstraptest/test_flow.rb b/bootstraptest/test_flow.rb
index d40d814fbc..0390062a24 100644
--- a/bootstraptest/test_flow.rb
+++ b/bootstraptest/test_flow.rb
@@ -543,9 +543,49 @@ 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
assert_equal "false", src + %q{e.all? {false}}, bug
assert_equal "true", src + %q{e.include?(:foo)}, bug
end
+
+assert_equal "foo", %q{
+ class Bug6460
+ def m1
+ m2 {|e|
+ return e
+ }
+ end
+
+ def m2
+ begin
+ yield :foo
+ ensure
+ begin
+ begin
+ yield :foo
+ ensure
+ Proc.new
+ raise ''
+ end
+ rescue
+ end
+ end
+ end
+ end
+ Bug6460.new.m1
+}, '[ruby-dev:46372]'
diff --git a/vm.c b/vm.c
index d4d4ebbb1c..7e243cbc2f 100644
--- a/vm.c
+++ b/vm.c
@@ -434,7 +434,8 @@ 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 {
+ }
+ else {
rb_vm_rewrite_ep_in_errinfo(th, cfp);
}
return envval;
@@ -493,9 +494,20 @@ rb_vm_make_env_object(rb_thread_t * th, rb_control_frame_t *cfp)
return envval;
}
+static void vm_rewrite_ep_in_errinfo(rb_thread_t *th, rb_control_frame_t *cfp);
+
void
rb_vm_rewrite_ep_in_errinfo(rb_thread_t *th, rb_control_frame_t *cfp)
{
+ while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) {
+ vm_rewrite_ep_in_errinfo(th, cfp);
+ cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
+ }
+}
+
+static void
+vm_rewrite_ep_in_errinfo(rb_thread_t *th, rb_control_frame_t *cfp)
+{
/* rewrite ep in errinfo to point to heap */
if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) &&
(cfp->iseq->type == ISEQ_TYPE_RESCUE ||
@@ -505,7 +517,7 @@ rb_vm_rewrite_ep_in_errinfo(rb_thread_t *th, rb_control_frame_t *cfp)
VALUE *escape_ep = GET_THROWOBJ_CATCH_POINT(errinfo);
if (! ENV_IN_HEAP_P(th, escape_ep)) {
VALUE epval = *escape_ep;
- if (CLASS_OF(epval) == rb_cEnv) {
+ if (!SPECIAL_CONST_P(epval) && RBASIC(epval)->klass == rb_cEnv) {
rb_env_t *epenv;
GetEnvPtr(epval, epenv);
SET_THROWOBJ_CATCH_POINT(errinfo, (VALUE)(epenv->env + epenv->local_size));