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

ruby-changes:60974

From: Yusuke <ko1@a...>
Date: Sat, 2 May 2020 21:44:03 +0900 (JST)
Subject: [ruby-changes:60974] 91e4e2403e (master): internal/process.h: add a no-warning simple wrapper for fork(2)

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

From 91e4e2403e950d06eb49840bdb11409321002847 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sat, 2 May 2020 21:34:10 +0900
Subject: internal/process.h: add a no-warning simple wrapper for fork(2)

As fork(2) is deprecated, its calls must be guarded by
`COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)`.
All usages of fork(2) in process have been alread guarded.  A new call
to fork(2) was added in ruby.c with f22c4ff359498ab342e4b6d6feb21af6004ee270.
This caused a build failure on Solaris 11.

It may hide a bug to guard big code unnecessarily, so this change
introduces a simple wrapper "rb_fork" whose definition is guarded, and
replaces all calls to fork(2) with the wrapper function.

diff --git a/common.mk b/common.mk
index 616276e..811ccf0 100644
--- a/common.mk
+++ b/common.mk
@@ -11806,6 +11806,7 @@ ruby.$(OBJEXT): $(top_srcdir)/internal/parse.h https://github.com/ruby/ruby/blob/trunk/common.mk#L11806
 ruby.$(OBJEXT): $(top_srcdir)/internal/serial.h
 ruby.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
 ruby.$(OBJEXT): $(top_srcdir)/internal/string.h
+ruby.$(OBJEXT): $(top_srcdir)/internal/process.h
 ruby.$(OBJEXT): $(top_srcdir)/internal/variable.h
 ruby.$(OBJEXT): $(top_srcdir)/internal/vm.h
 ruby.$(OBJEXT): $(top_srcdir)/internal/warnings.h
diff --git a/internal/process.h b/internal/process.h
index b47f857..62d54d8 100644
--- a/internal/process.h
+++ b/internal/process.h
@@ -22,6 +22,7 @@ https://github.com/ruby/ruby/blob/trunk/internal/process.h#L22
 
 #include "ruby/ruby.h"          /* for VALUE */
 #include "internal/imemo.h"     /* for RB_IMEMO_TMPBUF_PTR */
+#include "internal/warnings.h"  /* for COMPILER_WARNING_PUSH */
 
 #define RB_MAX_GROUPS (65536)
 
@@ -113,4 +114,15 @@ ARGVSTR2ARGC(VALUE argv_str) https://github.com/ruby/ruby/blob/trunk/internal/process.h#L114
     return i - 1;
 }
 
+COMPILER_WARNING_PUSH
+#if __has_warning("-Wdeprecated-declarations") || RUBY3_COMPILER_IS(GCC)
+COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)
+#endif
+static inline rb_pid_t
+rb_fork(void)
+{
+    return fork();
+}
+COMPILER_WARNING_POP
+
 #endif /* INTERNAL_PROCESS_H */
diff --git a/process.c b/process.c
index 0d0b466..e5cfed8 100644
--- a/process.c
+++ b/process.c
@@ -3957,10 +3957,6 @@ disable_child_handler_fork_child(struct child_handler_disabler_state *old, char https://github.com/ruby/ruby/blob/trunk/process.c#L3957
     return 0;
 }
 
-COMPILER_WARNING_PUSH
-#if __has_warning("-Wdeprecated-declarations") || RUBY3_COMPILER_IS(GCC)
-COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)
-#endif
 static rb_pid_t
 retry_fork_async_signal_safe(int *status, int *ep,
         int (*chfunc)(void*, char *, size_t), void *charg,
@@ -3985,9 +3981,9 @@ retry_fork_async_signal_safe(int *status, int *ep, https://github.com/ruby/ruby/blob/trunk/process.c#L3981
         if (!has_privilege())
             pid = vfork();
         else
-            pid = fork();
+            pid = rb_fork();
 #else
-        pid = fork();
+        pid = rb_fork();
 #endif
         if (pid == 0) {/* fork succeed, child process */
             int ret;
@@ -4021,7 +4017,6 @@ retry_fork_async_signal_safe(int *status, int *ep, https://github.com/ruby/ruby/blob/trunk/process.c#L4017
             return -1;
     }
 }
-COMPILER_WARNING_POP
 
 static rb_pid_t
 fork_check_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg,
@@ -4075,10 +4070,6 @@ rb_fork_async_signal_safe(int *status, https://github.com/ruby/ruby/blob/trunk/process.c#L4070
     return fork_check_err(status, chfunc, charg, fds, errmsg, errmsg_buflen, 0);
 }
 
-COMPILER_WARNING_PUSH
-#if __has_warning("-Wdeprecated-declarations") || RUBY3_COMPILER_IS(GCC)
-COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)
-#endif
 rb_pid_t
 rb_fork_ruby(int *status)
 {
@@ -4093,7 +4084,7 @@ rb_fork_ruby(int *status) https://github.com/ruby/ruby/blob/trunk/process.c#L4084
         if (mjit_enabled) mjit_pause(false); // Don't leave locked mutex to child. Note: child_handler must be enabled to pause MJIT.
 	disable_child_handler_before_fork(&old);
 	before_fork_ruby();
-	pid = fork();
+	pid = rb_fork();
 	err = errno;
         after_fork_ruby();
 	disable_child_handler_fork_parent(&old); /* yes, bad name */
@@ -4105,7 +4096,6 @@ rb_fork_ruby(int *status) https://github.com/ruby/ruby/blob/trunk/process.c#L4096
 	    return -1;
     }
 }
-COMPILER_WARNING_POP
 
 #endif
 
diff --git a/ruby.c b/ruby.c
index 405891f..f2577f5 100644
--- a/ruby.c
+++ b/ruby.c
@@ -56,6 +56,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby.c#L56
 #include "internal/missing.h"
 #include "internal/object.h"
 #include "internal/parse.h"
+#include "internal/process.h"
 #include "internal/variable.h"
 #include "mjit.h"
 #include "ruby/encoding.h"
@@ -1635,7 +1636,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1636
 #ifdef HAVE_WORKING_FORK
                 int fds[2];
                 if (rb_pipe(fds) == 0) {
-                    rb_pid_t pid = fork();
+                    rb_pid_t pid = rb_fork();
                     if (pid > 0) {
                         /* exec PAGER with reading from child */
                         dup2(fds[0], 0);
-- 
cgit v0.10.2


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

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