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

ruby-changes:56535

From: Takashi <ko1@a...>
Date: Mon, 15 Jul 2019 10:33:00 +0900 (JST)
Subject: [ruby-changes:56535] Takashi Kokubun: a191009a26 (master): Simplify start_process by exploiting C99

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

From a191009a266e97453971f9b24f750861855aaa7b Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Mon, 15 Jul 2019 10:29:39 +0900
Subject: Simplify start_process by exploiting C99

Having a block for mixing a declaration was confusing.
Also I moved `dev_null` and `pid` to limit their scope.

diff --git a/mjit_worker.c b/mjit_worker.c
index 2ee9a53..27af15b 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -548,36 +548,32 @@ COMPILER_WARNING_IGNORED(-Wdeprecated-declarations) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L548
 static pid_t
 start_process(const char *abspath, char *const *argv)
 {
-    pid_t pid;
-    // Not calling non-async-signal-safe functions between vfork
-    // and execv for safety
-    int dev_null = rb_cloexec_open(ruby_null_device, O_WRONLY, 0);
-
     if (mjit_opts.verbose >= 2) {
-        int i;
         const char *arg;
-
         fprintf(stderr, "Starting process: %s", abspath);
-        for (i = 0; (arg = argv[i]) != NULL; i++)
+        for (int i = 0; (arg = argv[i]) != NULL; i++)
             fprintf(stderr, " %s", arg);
         fprintf(stderr, "\n");
     }
+
+    // Not calling non-async-signal-safe functions between vfork
+    // and execv for safety
+    int dev_null = rb_cloexec_open(ruby_null_device, O_WRONLY, 0);
+    pid_t pid;
 #ifdef _WIN32
-    {
-        extern HANDLE rb_w32_start_process(const char *abspath, char *const *argv, int out_fd);
-        int out_fd = 0;
-        if (mjit_opts.verbose <= 1) {
-            // Discard cl.exe's outputs like:
-            //   _ruby_mjit_p12u3.c
-            //     Creating library C:.../_ruby_mjit_p12u3.lib and object C:.../_ruby_mjit_p12u3.exp
-            out_fd = dev_null;
-        }
+    extern HANDLE rb_w32_start_process(const char *abspath, char *const *argv, int out_fd);
+    int out_fd = 0;
+    if (mjit_opts.verbose <= 1) {
+        // Discard cl.exe's outputs like:
+        //   _ruby_mjit_p12u3.c
+        //     Creating library C:.../_ruby_mjit_p12u3.lib and object C:.../_ruby_mjit_p12u3.exp
+        out_fd = dev_null;
+    }
 
-        pid = (pid_t)rb_w32_start_process(abspath, argv, out_fd);
-        if (pid == 0) {
-            verbose(1, "MJIT: Failed to create process: %s", dlerror());
-            return -1;
-        }
+    pid = (pid_t)rb_w32_start_process(abspath, argv, out_fd);
+    if (pid == 0) {
+        verbose(1, "MJIT: Failed to create process: %s", dlerror());
+        return -1;
     }
 #else
     if ((pid = vfork()) == 0) { /* TODO: reuse some function in process.c */
-- 
cgit v0.10.2


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

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