Silence macOS vfork deprecation warnings
authorMattias Engdegård <mattiase@acm.org>
Thu, 10 Feb 2022 21:59:26 +0000 (22:59 +0100)
committerMattias Engdegård <mattiase@acm.org>
Thu, 10 Feb 2022 22:06:17 +0000 (23:06 +0100)
The vfork system call exists and works in macOS 11.6 but the compiler
gives a deprecation message; silence it, because the performance is
still better than that of plain fork.  See discussion at
https://lists.gnu.org/archive/html/emacs-devel/2022-02/msg00260.html

* src/conf_post.h (VFORK): New #define.
* src/callproc.c (emacs_spawn):
* src/sysdep.c (sys_subshell): Use it.

src/callproc.c
src/conf_post.h
src/sysdep.c

index 4d3b0bb8e065212fe27bd46dfc933a0c4414eb69..dcee740043c59319e06fc86fcc5199b67d9e0e22 100644 (file)
@@ -1500,7 +1500,7 @@ emacs_spawn (pid_t *newpid, int std_in, int std_out, int std_err,
   if (pty != NULL)
     pid = fork ();
   else
-    pid = vfork ();
+    pid = VFORK ();
 #else
   pid = vfork ();
 #endif
index 6db76a2dfad2a757dd931780dd8b6fe04119754f..0b6260b287e62ed9aee361765843df6ad9994f6e 100644 (file)
@@ -353,6 +353,19 @@ extern int emacs_setenv_TZ (char const *);
 # define vfork fork
 #endif
 
+/* vfork is deprecated on at least macOS 11.6 and later, but it still works
+   and is faster than fork, so silence the warning as if we knew what we
+   are doing.  */
+#ifdef DARWIN_OS
+#define VFORK()                                                                \
+  (_Pragma("clang diagnostic push")                                    \
+   _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")   \
+   vfork ()                                                            \
+   _Pragma("clang diagnostic pop"))
+#else
+#define VFORK() vfork ()
+#endif
+
 #if ! (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__)
 # undef PROFILING
 #endif
index d682e87cc710815c965b54896c3b27733fab1881..c772aff6a021b1db1b1284500d809efde202af53 100644 (file)
@@ -664,7 +664,7 @@ sys_subshell (void)
 #else
   {
     char *volatile str_volatile = str;
-    pid = vfork ();
+    pid = VFORK ();
     str = str_volatile;
   }
 #endif