From 26eeca71fbb3ee76ad51d3b83b79992f165e5f06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Thu, 10 Feb 2022 22:59:26 +0100 Subject: [PATCH] Silence macOS vfork deprecation warnings 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 | 2 +- src/conf_post.h | 13 +++++++++++++ src/sysdep.c | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/callproc.c b/src/callproc.c index 4d3b0bb8e06..dcee740043c 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -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 diff --git a/src/conf_post.h b/src/conf_post.h index 6db76a2dfad..0b6260b287e 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -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 diff --git a/src/sysdep.c b/src/sysdep.c index d682e87cc71..c772aff6a02 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -664,7 +664,7 @@ sys_subshell (void) #else { char *volatile str_volatile = str; - pid = vfork (); + pid = VFORK (); str = str_volatile; } #endif -- 2.39.5