ruby-changes:71392
From: nagachika <ko1@a...>
Date: Sun, 13 Mar 2022 12:12:23 +0900 (JST)
Subject: [ruby-changes:71392] 6a8c166498 (ruby_3_0): merge revision(s) 5c7af72304d0ad33cd3f21b24a4bc44e8acd5b2c,d650b17686d49c2ce8e6a87039861154e93d4621: [Backport #18497]
https://git.ruby-lang.org/ruby.git/commit/?id=6a8c166498 From 6a8c166498b856ca1dcb53248f0be5fc138f1af3 Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@r...> Date: Sun, 13 Mar 2022 11:47:39 +0900 Subject: merge revision(s) 5c7af72304d0ad33cd3f21b24a4bc44e8acd5b2c,d650b17686d49c2ce8e6a87039861154e93d4621: [Backport #18497] Assuming EXIT_SUCCESS equals 0 is not portable --- test/ruby/test_fiber.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) `rb_fiber_terminate` must not return [Bug #18497] In a forked process from a fiber, the fiber becomes the only fiber, `fiber_switch` does nothing as there is no other fibers, `rb_fiber_terminate` does not terminate the fiber. In that case, reaches the end of `fiber_entry` finaly, which is declared as "COROUTINE" and should never return. --- cont.c | 3 ++- eval_intern.h | 2 +- test/fiber/test_process.rb | 15 +++++++++++++++ test/ruby/test_fiber.rb | 5 +++++ 4 files changed, 23 insertions(+), 2 deletions(-) --- cont.c | 3 ++- test/fiber/test_process.rb | 15 +++++++++++++++ test/ruby/test_fiber.rb | 11 ++++++++--- version.h | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cont.c b/cont.c index aad7612b25..a7103a087e 100644 --- a/cont.c +++ b/cont.c @@ -2008,7 +2008,7 @@ rb_fiber_set_scheduler(VALUE klass, VALUE scheduler) https://github.com/ruby/ruby/blob/trunk/cont.c#L2008 return rb_scheduler_set(scheduler); } -static void rb_fiber_terminate(rb_fiber_t *fiber, int need_interrupt); +NORETURN(static void rb_fiber_terminate(rb_fiber_t *fiber, int need_interrupt)); void rb_fiber_start(void) @@ -2384,6 +2384,7 @@ rb_fiber_terminate(rb_fiber_t *fiber, int need_interrupt) https://github.com/ruby/ruby/blob/trunk/cont.c#L2384 next_fiber = return_fiber(true); if (need_interrupt) RUBY_VM_SET_INTERRUPT(&next_fiber->cont.saved_ec); fiber_switch(next_fiber, 1, &value, RB_NO_KEYWORDS, Qfalse, false); + ruby_stop(0); } VALUE diff --git a/test/fiber/test_process.rb b/test/fiber/test_process.rb index c6583cac9b..a5990be204 100644 --- a/test/fiber/test_process.rb +++ b/test/fiber/test_process.rb @@ -33,4 +33,19 @@ class TestFiberProcess < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fiber/test_process.rb#L33 end end.join end + + def test_fork + omit 'fork not supported' unless Process.respond_to?(:fork) + Thread.new do + scheduler = Scheduler.new + Fiber.set_scheduler scheduler + + Fiber.schedule do + pid = Process.fork {} + Process.wait(pid) + + assert_predicate $?, :success? + end + end.join + end end diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb index e0cc59bd3c..9e994c7349 100644 --- a/test/ruby/test_fiber.rb +++ b/test/ruby/test_fiber.rb @@ -397,7 +397,7 @@ class TestFiber < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fiber.rb#L397 Fiber.new {}.transfer Fiber.new { Fiber.yield } end - exit!(0) + exit!(true) end }.transfer _, status = Process.waitpid2(xpid) @@ -406,8 +406,13 @@ class TestFiber < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fiber.rb#L406 end.resume end pid, status = Process.waitpid2(pid) - assert_equal(0, status.exitstatus, bug5700) - assert_equal(false, status.signaled?, bug5700) + assert_not_predicate(status, :signaled?, bug5700) + assert_predicate(status, :success?, bug5700) + + pid = Fiber.new {fork}.resume + pid, status = Process.waitpid2(pid) + assert_not_predicate(status, :signaled?) + assert_predicate(status, :success?) end def test_exit_in_fiber diff --git a/version.h b/version.h index ade88256a4..5de5de5fc7 100644 --- a/version.h +++ b/version.h @@ -12,7 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L12 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 4 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 190 +#define RUBY_PATCHLEVEL 191 #define RUBY_RELEASE_YEAR 2022 #define RUBY_RELEASE_MONTH 3 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/