Bug #2729
closed`unexpected break' occurs when a proc is called in ensure
Added by nobu (Nobuyoshi Nakada) almost 16 years ago. Updated over 13 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
| 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 |
Updated by nobu (Nobuyoshi Nakada) almost 16 years ago
Actions
#1
=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
Updated by wanabe (_ wanabe) almost 16 years ago
Actions
#2
- File proc_in_ensure.patch proc_in_ensure.patch added
=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 14 years ago
Actions
#3
[ruby-core:37378]
- Status changed from Open to Assigned
- Assignee set to ko1 (Koichi Sasada)
Updated by naruse (Yui NARUSE) over 14 years ago
Actions
#4
[ruby-core:37379]
- Target version changed from 2.0.0 to 1.9.3
Updated by ktsj (Kazuki Tsujimoto) over 14 years ago
Actions
#5
[ruby-core:38617]
A patch fixing the problem is attached, but it might be only a workaroud.
Updated by ko1 (Koichi Sasada) over 14 years ago
Actions
#6
[ruby-core:39099]
- 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) over 14 years ago
Actions
#7
- 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.
Updated by lgierth (Lars Gierth) over 13 years ago
Actions
#8
[ruby-core:46843]
=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 13 years ago
Actions
#9
[ruby-core:46844]
#5234 has been backported to 1.9.3 at least.