stricter check for double resume; close #1885

parent 31b2980a
......@@ -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) {
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment