diff --git a/ChangeLog b/ChangeLog index e869d9a8ec..4d0a55e740 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Jun 1 11:21:29 2009 Nobuyoshi Nakada + + * cont.c (cont_capture, fiber_store): reraise transferred error. + + * cont.c (fiber_switch): transfers dead fiber error to the previouse + or root fiber if the current fiber is dead. [ruby-core:23651] + Mon Jun 1 10:41:41 2009 Nobuyoshi Nakada * include/ruby/intern.h (rb_exc_new2): optimization for literal. diff --git a/cont.c b/cont.c index 363e913b4f..c0a5dd78ef 100644 --- a/cont.c +++ b/cont.c @@ -279,6 +279,7 @@ cont_capture(volatile int *stat) VALUE value; value = cont->value; + if (cont->argc == -1) rb_exc_raise(value); cont->value = Qnil; *stat = 1; return value; @@ -850,6 +851,7 @@ fiber_store(rb_fiber_t *next_fib) if (ruby_setjmp(fib->cont.jmpbuf)) { /* restored */ GetFiberPtr(th->fiber, fib); + if (fib->cont.argc == -1) rb_exc_raise(fib->cont.value); return fib->cont.value; } else { @@ -875,7 +877,15 @@ fiber_switch(VALUE fibval, int argc, VALUE *argv, int is_resume) rb_raise(rb_eFiberError, "fiber called across trap"); } else if (fib->status == TERMINATED) { - rb_raise(rb_eFiberError, "dead fiber called"); + value = rb_exc_new2(rb_eFiberError, "dead fiber called"); + if (th->fiber != fibval) rb_exc_raise(value); + fibval = fib->prev; + if (NIL_P(fibval)) fibval = th->root_fiber; + GetFiberPtr(fibval, fib); + cont = &fib->cont; + cont->argc = -1; + cont->value = value; + cont_restore_0(cont, &value); } if (is_resume) { @@ -886,7 +896,7 @@ fiber_switch(VALUE fibval, int argc, VALUE *argv, int is_resume) cont->value = make_passing_arg(argc, argv); if ((value = fiber_store(fib)) == Qundef) { - cont_restore_0(&fib->cont, &value); + cont_restore_0(cont, &value); rb_bug("rb_fiber_resume: unreachable"); } diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb index 6d64ccf72b..e6afe55b96 100644 --- a/test/ruby/test_fiber.rb +++ b/test/ruby/test_fiber.rb @@ -173,5 +173,10 @@ class TestFiber < Test::Unit::TestCase fib.resume assert_equal(false, fib.alive?) end + + def test_resume_self + f = Fiber.new {f.resume} + assert_raise(FiberError, '[ruby-core:23651]') {f.transfer} + end end