Permalink
Browse files

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
  • Loading branch information...
1 parent 0446be7 commit f7894e422a935d975f7fc4130b73fefba16a9433 @nobu nobu committed Nov 2, 2012
Showing with 60 additions and 20 deletions.
  1. +6 −0 ChangeLog
  2. +0 −18 KNOWNBUGS.rb
  3. +40 −0 bootstraptest/test_flow.rb
  4. +14 −2 vm.c
View
6 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
View
18 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
View
40 bootstraptest/test_flow.rb
@@ -543,9 +543,49 @@ def each
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]'
View
16 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));

0 comments on commit f7894e4

Please sign in to comment.