Bug #2729

`unexpected break' occurs when a proc is called in ensure

Added by nobu (Nobuyoshi Nakada) over 2 years ago. Updated 9 months ago.

[ruby-core:28132]
Status:Closed Start date:02/10/2010
Priority:Normal Due date:
Assignee:ko1 (Koichi Sasada) % Done:

100%

Category:core
Target version:1.9.3
ruby -v:-

Description

Reproducing code:

  class Bug
    include Enumerable
    def each
      begin
        yield :foo
      ensure
        proc {}.call
      end
    end
  end
  e = Bug.new
  p e.detect{true}   # => :foo
  p e.any?{true}     # => true
  p e.all?{false}    # => false
  p e.include?(:foo) # => true

All work expectedly if no Proc#call, but all occurs `unexpected break' with it.

proc_in_ensure.patch (449 Bytes) wanabe (_ wanabe), 02/21/2010 07:21 pm

rewrite-dfp-in-errinfo.txt (858 Bytes) ktsj (Kazuki Tsujimoto), 07/31/2011 10:58 am


Related issues

precedes Archive91 - Backport #2728: ruby segfaults returning from dynamically defined method ... Assigned 02/11/2010 02/11/2010

Associated revisions

Revision 33063
Added by ko1 (Koichi Sasada) 9 months ago

* vm.c (vm_make_env_each): work around to solve Bug #2729. fixes: Bug #2729 a patch from Kazuki Tsujimoto <kazuki@callcc.net> This problem is caused by changing dfp (dynamic env pointer) from saved dfp. Saved dfp is pointed env in VM stack. However, the dfp can be moved because VM copies env from VM stack to the heap. At this copying, dfp was also changed. To solve this problem, I'll try to change throw mechanism (not save target dfp, but save target cfp). * bootstraptest/test_flow.rb: add a test for above.

Revision 33064
Added by ko1 (Koichi Sasada) 9 months ago

* vm.c (vm_make_env_each): work around to solve Bug #2729. fixes: Bug #2729 a patch from Kazuki Tsujimoto <kazuki@callcc.net> This problem is caused by changing dfp (dynamic env pointer) from saved dfp. Saved dfp is pointed env in VM stack. However, the dfp can be moved because VM copies env from VM stack to the heap. At this copying, dfp was also changed. To solve this problem, I'll try to change throw mechanism (not save target dfp, but save target cfp). * bootstraptest/test_flow.rb: add a test for above.

History

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

Hi,

At Wed, 10 Feb 2010 04:36:18 +0900,
Nobuyoshi Nakada wrote in [ruby-core:28132]:
> Bug #2729: `unexpected break' occurs when a proc is called in ensure

Test case.


Index: bootstraptest/test_flow.rb
===================================================================
--- bootstraptest/test_flow.rb	(revision 26629)
+++ bootstraptest/test_flow.rb	(working copy)
@@ -518,4 +518,17 @@ assert_equal %Q{ENSURE\n}, %q{
   end
   e = Bug2728.new
+}],
+ ['[ruby-core:28132]', %q{
+  class Bug2729
+    include Enumerable
+    def each
+      begin
+        yield :foo
+      ensure
+        proc {}.call
+      end
+    end
+  end
+  e = Bug2729.new
 }]].each do |bug, src|
   assert_equal "foo", src + %q{e.detect {true}}, bug


-- 
Nobu Nakada

Updated by wanabe (_ wanabe) over 2 years ago

This patch prevent the exception.
I know it's not a fundamental solution, but I hope it will help for finding a bug.

Updated by naruse (Yui NARUSE) 11 months ago

  • Status changed from Open to Assigned
  • Assignee set to ko1 (Koichi Sasada)

Updated by naruse (Yui NARUSE) 11 months ago

  • Target version changed from 2.0.0 to 1.9.3

Updated by ktsj (Kazuki Tsujimoto) 10 months ago

A patch fixing the problem is attached, but it might be only a workaroud.

Updated by ko1 (Koichi Sasada) 9 months ago

  • ruby -v changed from ruby 1.9.2dev (2010-02-10 trunk 26629) [x86_64-darwin9.0] to -
(2011/07/30 18:58), Kazuki Tsujimoto wrote: > A patch fixing the problem is attached, but it might be only a workaroud. Thank you. I'll apply this patch for 1.9.3 and trunk. To solve it, I'll change the vm_throw mechanism on trunk (not throw dfp, but throw cfp). # BTW, vm_throw() is toooo complicated. Regards, Koichi -- // SASADA Koichi at atdot dot net

Updated by ko1 (Koichi Sasada) 9 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100
This issue was solved with changeset r33064. Nobuyoshi, thank you for reporting this issue. Your contribution to Ruby is greatly appreciated. May Ruby be with you. ---------- * vm.c (vm_make_env_each): work around to solve Bug #2729. fixes: Bug #2729 a patch from Kazuki Tsujimoto <kazuki@callcc.net> This problem is caused by changing dfp (dynamic env pointer) from saved dfp. Saved dfp is pointed env in VM stack. However, the dfp can be moved because VM copies env from VM stack to the heap. At this copying, dfp was also changed. To solve this problem, I'll try to change throw mechanism (not save target dfp, but save target cfp). * bootstraptest/test_flow.rb: add a test for above.

Also available in: Atom PDF