From 150ebfdf77320b24b0358f8a903e90d7940ad4a4 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 23 Sep 2020 23:46:58 +0100 Subject: Suppress bogus [-Wlogical-op] warning from GCC See GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 which emits the warning for (errno == EWOULDBLOCK || errno == EAGAIN) which is the correct way of handling errors as the value of EWOULDBLOCK and EAGAIN is implementation defined. Therefore introduce a new macro function PHP_IS_TRANSIENT_ERROR() which handles the case when EWOULDBLOCK and EAGAIN are identical. Thanks to @twose for the idea. --- main/php_network.h | 7 +++++++ main/streams/plain_wrapper.c | 4 ++-- main/streams/xp_socket.c | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'main') diff --git a/main/php_network.h b/main/php_network.h index 437069b4fc..5c8cee3fa8 100644 --- a/main/php_network.h +++ b/main/php_network.h @@ -49,6 +49,13 @@ # define EWOULDBLOCK EAGAIN #endif +/* This is a work around for GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 */ +#if EAGAIN != EWOULDBLOCK +# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN || err == EWOULDBLOCK) +#else +# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN) +#endif + #ifdef PHP_WIN32 #define php_socket_errno() WSAGetLastError() #else diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 8a891ddf72..0373cc4c94 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -351,7 +351,7 @@ static ssize_t php_stdiop_write(php_stream *stream, const char *buf, size_t coun ssize_t bytes_written = write(data->fd, buf, count); #endif if (bytes_written < 0) { - if (errno == EWOULDBLOCK || errno == EAGAIN) { + if (PHP_IS_TRANSIENT_ERROR(errno)) { return 0; } if (errno == EINTR) { @@ -420,7 +420,7 @@ static ssize_t php_stdiop_read(php_stream *stream, char *buf, size_t count) } if (ret < 0) { - if (errno == EWOULDBLOCK || errno == EAGAIN) { + if (PHP_IS_TRANSIENT_ERROR(errno)) { /* Not an error. */ ret = 0; } else if (errno == EINTR) { diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index f3370e89f7..cd67fcb8ca 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -75,7 +75,8 @@ retry: if (didwrite <= 0) { char *estr; int err = php_socket_errno(); - if (err == EWOULDBLOCK || err == EAGAIN) { + + if (PHP_IS_TRANSIENT_ERROR(err)) { if (sock->is_blocked) { int retval; @@ -166,7 +167,7 @@ static ssize_t php_sockop_read(php_stream *stream, char *buf, size_t count) err = php_socket_errno(); if (nr_bytes < 0) { - if (err == EAGAIN || err == EWOULDBLOCK) { + if (PHP_IS_TRANSIENT_ERROR(err)) { nr_bytes = 0; } else { stream->eof = 1; -- cgit v1.2.1