Bug #2729
closed
`unexpected break' occurs when a proc is called in ensure
Added by nobu (Nobuyoshi Nakada) over 14 years ago.
Updated about 12 years ago.
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
=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
=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
- Status changed from Open to Assigned
- Assignee set to ko1 (Koichi Sasada)
- Target version changed from 2.0.0 to 1.9.3
A patch fixing the problem is attached, but it might be only a workaroud.
- 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
- 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.
=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
#5234 has been backported to 1.9.3 at least.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0