stricter check for double resume; close #1885

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-03-18 23:47:01 +09:00
parent 31b2980acb
commit 53a282ac0e
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -164,7 +164,7 @@ fiber_resume(mrb_state *mrb, mrb_value self)
mrb_raise(mrb, E_ARGUMENT_ERROR, "can't cross C function boundary");
}
}
if (c->status == MRB_FIBER_RUNNING) {
if (c->status == MRB_FIBER_RUNNING || (mrb->c->prev && mrb->c->prev != mrb->root_c)) {
mrb_raise(mrb, E_RUNTIME_ERROR, "double resume");
}
if (c->status == MRB_FIBER_TERMINATED) {
+13
View File
@@ -88,3 +88,16 @@ assert('Double resume of Fiber') do
assert_false f1.alive?
assert_false f2.alive?
end
assert('Recursive resume of Fiber') do
f1, f2 = nil, nil
f1 = Fiber.new { assert_raise(RuntimeError) { f2.resume } }
f2 = Fiber.new {
f1.resume
Fiber.yield 0
}
assert_equal 0, f2.resume
f2.resume
assert_false f1.alive?
assert_false f2.alive?
end