From eb17d6f575de81dbbc113e474d28db0396c12714 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 12 Oct 2016 09:16:31 -0700 Subject: [PATCH] Port --enable-gcc-warnings to GCC 6.2.1 Backport from master. * src/conf_post.h (GNUC_PREREQ): New macro. * src/keyboard.c: Use it to work around GCC bug 54561. * src/process.c (would_block): New function. (server_accept_connection, wait_reading_process_output, send_process): Use it. --- src/conf_post.h | 11 +++++++++++ src/keyboard.c | 5 +++++ src/process.c | 42 +++++++++++++++++------------------------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/conf_post.h b/src/conf_post.h index 209f60792cf..f83965bf8b1 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -34,6 +34,17 @@ along with GNU Emacs. If not, see . */ #include +/* GNUC_PREREQ (V, W, X) is true if this is GNU C version V.W.X or later. + It can be used in a preprocessor expression. */ +#ifndef __GNUC_MINOR__ +# define GNUC_PREREQ(v, w, x) false +#elif ! defined __GNUC_PATCHLEVEL__ +# define GNUC_PREREQ(v, w, x) ((v) < __GNUC__ + ((w) <= __GNUC_MINOR__)) +#else +# define GNUC_PREREQ(v, w, x) \ + ((v) < __GNUC__ + ((w) <= __GNUC_MINOR__ + ((x) <= __GNUC_PATCHLEVEL__))) +#endif + /* The type of bool bitfields. Needed to compile Objective-C with standard GCC. It was also needed to port to pre-C99 compilers, although we don't care about that any more. */ diff --git a/src/keyboard.c b/src/keyboard.c index 918424630f3..f24d86e8833 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -70,6 +70,11 @@ along with GNU Emacs. If not, see . */ #include TERM_HEADER #endif /* HAVE_WINDOW_SYSTEM */ +/* Work around GCC bug 54561. */ +#if GNUC_PREREQ (4, 3, 0) +# pragma GCC diagnostic ignored "-Wclobbered" +#endif + /* Variables for blockinput.h: */ /* Positive if interrupt input is blocked right now. */ diff --git a/src/process.c b/src/process.c index 7ab92b0102c..e6ea2fbe8f7 100644 --- a/src/process.c +++ b/src/process.c @@ -151,6 +151,18 @@ bool inhibit_sentinels; # define SOCK_CLOEXEC 0 #endif +/* True if ERRNUM represents an error where the system call would + block if a blocking variant were used. */ +static bool +would_block (int errnum) +{ +#ifdef EWOULDBLOCK + if (EWOULDBLOCK != EAGAIN && errnum == EWOULDBLOCK) + return true; +#endif + return errnum == EAGAIN; +} + #ifndef HAVE_ACCEPT4 /* Emulate GNU/Linux accept4 and socket well enough for this module. */ @@ -4262,15 +4274,7 @@ server_accept_connection (Lisp_Object server, int channel) if (s < 0) { int code = errno; - - if (code == EAGAIN) - return; -#ifdef EWOULDBLOCK - if (code == EWOULDBLOCK) - return; -#endif - - if (!NILP (ps->log)) + if (!would_block (code) && !NILP (ps->log)) call3 (ps->log, server, Qnil, concat3 (build_string ("accept failed with code"), Fnumber_to_string (make_number (code)), @@ -4687,12 +4691,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, int nread = read_process_output (proc, wait_proc->infd); if (nread < 0) { - if (errno == EIO || errno == EAGAIN) - break; -#ifdef EWOULDBLOCK - if (errno == EWOULDBLOCK) - break; -#endif + if (errno == EIO || would_block (errno)) + break; } else { @@ -5073,11 +5073,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, if (do_display) redisplay_preserve_echo_area (12); } -#ifdef EWOULDBLOCK - else if (nread == -1 && errno == EWOULDBLOCK) - ; -#endif - else if (nread == -1 && errno == EAGAIN) + else if (nread == -1 && would_block (errno)) ; #ifdef WINDOWSNT /* FIXME: Is this special case still needed? */ @@ -5801,11 +5797,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, if (rv < 0) { - if (errno == EAGAIN -#ifdef EWOULDBLOCK - || errno == EWOULDBLOCK -#endif - ) + if (would_block (errno)) /* Buffer is full. Wait, accepting input; that may allow the program to finish doing output and read more. */ -- 2.39.2