diff options
| author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-15 03:20:13 +0000 |
|---|---|---|
| committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-15 03:20:13 +0000 |
| commit | eaf74a2060dd53de038f9a665f5f5e77c1f65363 (patch) | |
| tree | 8f1e89f4b9634c665102ae5a745f4af38802bc3b | |
| parent | fa304810e15a8c66f787561a472de02ee0ca9002 (diff) | |
| download | ruby-eaf74a2060dd53de038f9a665f5f5e77c1f65363.tar.gz ruby-eaf74a2060dd53de038f9a665f5f5e77c1f65363.tar.xz ruby-eaf74a2060dd53de038f9a665f5f5e77c1f65363.zip | |
* cont.c (rb_cont_call): forbid cross fiber continuation call.
* test/ruby/test_fiber.rb: ditto.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 6 | ||||
| -rw-r--r-- | cont.c | 6 | ||||
| -rw-r--r-- | test/ruby/test_fiber.rb | 30 |
3 files changed, 17 insertions, 25 deletions
@@ -1,3 +1,9 @@ +Fri Jun 15 12:20:11 2007 Koichi Sasada <ko1@atdot.net> + + * cont.c (rb_cont_call): forbid cross fiber continuation call. + + * test/ruby/test_fiber.rb: ditto. + Fri Jun 15 12:14:07 2007 Koichi Sasada <ko1@atdot.net> * sample/test.rb: fix to show line information whether test succeeds. @@ -439,6 +439,10 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval) rb_context_t *fcont; GetContPtr(cont->saved_thread.fiber, fcont); + if (th->fiber != cont->saved_thread.fiber) { + rb_raise(rb_eRuntimeError, "continuation called across fiber"); + } + if (!fcont->alive) { rb_raise(rb_eRuntimeError, "continuation called dead fiber"); } @@ -610,7 +614,7 @@ rb_fiber_yield(int argc, VALUE *argv, VALUE fval) cont_restore_0(cont, (VALUE *)&cont); rb_bug("rb_fiber_yield: unreachable"); } - + return value; } diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb index 6c67a5815..d6212cc7e 100644 --- a/test/ruby/test_fiber.rb +++ b/test/ruby/test_fiber.rb @@ -70,6 +70,12 @@ class TestFiber < Test::Unit::TestCase f.yield f.yield } + assert_raise(RuntimeError){ + f = Fiber.new{ + @c = callcc{|c| @c = c} + }.yield + @c.call # cross fiber callcc + } end def test_loop @@ -102,29 +108,5 @@ class TestFiber < Test::Unit::TestCase end.yield } end - - def test_with_callcc - c = nil - f1 = f2 = nil - f1 = Fiber.new do - callcc do |c2| - c = c2 - f2.yield - end - :ok - end - f2 = Fiber.new do - c.call - end - assert_equal(:ok, f1.yield) - - assert_equal(:ok, - callcc {|c| - Fiber.new { - c.call :ok - }.yield - } - ) - end end |
