Project

General

Profile

Actions

Bug #2729

closed

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

Added by nobu (Nobuyoshi Nakada) almost 13 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
-
Backport:
[ruby-core:28132]

Description

=begin
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.
=end


Files

proc_in_ensure.patch (449 Bytes) proc_in_ensure.patch wanabe (_ wanabe), 02/21/2010 07:21 PM
rewrite-dfp-in-errinfo.txt (858 Bytes) rewrite-dfp-in-errinfo.txt ktsj (Kazuki Tsujimoto), 07/31/2011 10:58 AM

Related issues 1 (0 open1 closed)

Precedes Backport191 - Backport #2728: ruby segfaults returning from dynamically defined method in ensure blockClosedko1 (Koichi Sasada)Actions
Actions #1

Updated by nobu (Nobuyoshi Nakada) almost 13 years ago

=begin
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

=end

Actions #2

Updated by wanabe (_ wanabe) almost 13 years ago

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

Updated by naruse (Yui NARUSE) over 11 years ago

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

Updated by naruse (Yui NARUSE) over 11 years ago

  • Target version changed from 2.0.0 to 1.9.3

Updated by ktsj (Kazuki Tsujimoto) over 11 years ago

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

Updated by ko1 (Koichi Sasada) over 11 years 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

Actions #7

Updated by ko1 (Koichi Sasada) over 11 years 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
    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.

Updated by lgierth (Lars Gierth) over 10 years ago

=begin
This patch doesn't seem to have landed in 1.9.2 and 1.9.3. Can someone backport it?

$ git checkout trunk
$ git log --oneline | grep 33064
a09e713 * proc.c (proc_new): force to rewrite errinfo when calling Proc.new in ensure. [Bug #5234] [ruby-core:39125] This code will be removed after changing throw mechanism (see r33064).
$ git checkout ruby_1_9_2
$ git log --oneline | grep 33064
$ git checkout ruby_1_9_3
$ git log --oneline | grep 33064
=end

Updated by lgierth (Lars Gierth) over 10 years ago

#5234 has been backported to 1.9.3 at least.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0