[前][次][番号順一覧][スレッド一覧]

ruby-changes:68071

From: Samuel <ko1@a...>
Date: Wed, 22 Sep 2021 15:50:40 +0900 (JST)
Subject: [ruby-changes:68071] bf3e314852 (master): Rework order of operations to better handle last_status.

https://git.ruby-lang.org/ruby.git/commit/?id=bf3e314852

From bf3e3148525b8f83be9b7374ae41b07cc73f5052 Mon Sep 17 00:00:00 2001
From: Samuel Williams <samuel.williams@o...>
Date: Wed, 22 Sep 2021 00:02:14 +1200
Subject: Rework order of operations to better handle last_status.

---
 process.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/process.c b/process.c
index ed0454c..c7cda7e 100644
--- a/process.c
+++ b/process.c
@@ -4203,7 +4203,7 @@ retry_fork_async_signal_safe(struct rb_process_status *status, int *ep, https://github.com/ruby/ruby/blob/trunk/process.c#L4203
             _exit(127);
 #endif
         }
-	err = errno;
+        err = errno;
         waitpid_lock = waitpid_lock_init;
         if (waitpid_lock) {
             if (pid > 0 && w != WAITPID_LOCK_ONLY) {
@@ -4768,14 +4768,15 @@ rb_f_system(int argc, VALUE *argv, VALUE _) https://github.com/ruby/ruby/blob/trunk/process.c#L4768
     VALUE execarg_obj = rb_execarg_new(argc, argv, TRUE, TRUE);
     struct rb_execarg *eargp = rb_execarg_get(execarg_obj);
 
-    struct rb_process_status status;
+    struct rb_process_status status = {0};
     eargp->status = &status;
 
-    /* may be different from waitpid_state.pid on exec failure */
-    rb_pid_t pid = rb_execarg_spawn(execarg_obj, 0, 0);
-
     rb_last_status_clear();
 
+    // This function can set the thread's last status.
+    // May be different from waitpid_state.pid on exec failure.
+    rb_pid_t pid = rb_execarg_spawn(execarg_obj, 0, 0);
+
     if (pid > 0) {
         VALUE status = rb_process_status_wait(pid, 0);
         struct rb_process_status *data = RTYPEDDATA_DATA(status);
@@ -4813,10 +4814,6 @@ rb_f_system(int argc, VALUE *argv, VALUE _) https://github.com/ruby/ruby/blob/trunk/process.c#L4814
         RB_GC_GUARD(status);
     }
 
-    if (status.pid > 0) {
-        GET_THREAD()->last_status = rb_process_status_new(status.pid, status.status, status.error);
-    }
-
     if (eargp->exception) {
         VALUE command = eargp->invoke.sh.shell_script;
         RB_GC_GUARD(execarg_obj);
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]