ruby-changes:49028
From: mrkn <ko1@a...>
Date: Tue, 12 Dec 2017 18:00:22 +0900 (JST)
Subject: [ruby-changes:49028] mrkn:r61143 (trunk): process.c: add Process.last_status
mrkn 2017-12-12 18:00:17 +0900 (Tue, 12 Dec 2017) New Revision: 61143 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61143 Log: process.c: add Process.last_status * process.c (proc_s_last_status): add Process.last_status [ruby-core:83514] [Feature #14043] * test/ruby/test_process.rb (test_last_status): add a test case for Process.last_status. Modified files: trunk/process.c trunk/test/ruby/test_process.rb Index: process.c =================================================================== --- process.c (revision 61142) +++ process.c (revision 61143) @@ -472,6 +472,27 @@ rb_last_status_get(void) https://github.com/ruby/ruby/blob/trunk/process.c#L472 return GET_THREAD()->last_status; } +/* + * call-seq: + * Process.last_status -> Process::Status + * + * Return the status of the last executed child process in the + * current thread. + * + * Process.wait Process.spawn("ruby", "-e", "exit 13") + * Process.last_status #=> #<Process::Status: pid 4825 exit 13> + * + * If no child process has never been executed in the current + * thread, this returns +nil+. + * + * Process.last_status #=> nil + */ +static VALUE +proc_s_last_status(VALUE mod) +{ + return rb_last_status_get(); +} + void rb_last_status_set(int status, rb_pid_t pid) { @@ -7600,6 +7621,7 @@ InitVM_process(void) https://github.com/ruby/ruby/blob/trunk/process.c#L7621 rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1); rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1); rb_define_singleton_method(rb_mProcess, "abort", rb_f_abort, -1); + rb_define_singleton_method(rb_mProcess, "last_status", proc_s_last_status, 0); rb_define_module_function(rb_mProcess, "kill", rb_f_kill, -1); /* in signal.c */ rb_define_module_function(rb_mProcess, "wait", proc_wait, -1); Index: test/ruby/test_process.rb =================================================================== --- test/ruby/test_process.rb (revision 61142) +++ test/ruby/test_process.rb (revision 61143) @@ -2352,4 +2352,9 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L2352 end end end + + def test_last_status + Process.wait spawn(RUBY, "-e", "exit 13") + assert_same(Process.last_status, $?) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/