From 5ce32fcfbeca6c4f647303f4ccf0b1e1c7688901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20M=C3=BCller?= Date: Tue, 2 Jul 2019 08:25:40 +0200 Subject: [PATCH] Get latest poll module from gnulib to fix compilation error on mingw-w64 mainly struct pollfd definition caused compilation failure on mingw-w64 * lib/Makefile.am: update target poll.h: * lib/poll.c: * lib/poll.in.h: * m4/poll.m4: * m4/poll_h.m4: update from gnulib git --- lib/Makefile.am | 1 + lib/poll.c | 49 ++++++++++++++++++++++++++++++++++++++----------- lib/poll.in.h | 32 +++++++++++++++++++++++++++----- m4/poll.m4 | 26 +++++++++++++++----------- m4/poll_h.m4 | 6 ++++-- 5 files changed, 85 insertions(+), 29 deletions(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index f1b83a13b..fcaabccb6 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1741,6 +1741,7 @@ poll.h: poll.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_POLL_H''@|$(NEXT_POLL_H)|g' \ -e 's/@''GNULIB_POLL''@/$(GNULIB_POLL)/g' \ + -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ -e 's|@''HAVE_POLL''@|$(HAVE_POLL)|g' \ -e 's|@''REPLACE_POLL''@|$(REPLACE_POLL)|g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ diff --git a/lib/poll.c b/lib/poll.c index e700ac358..2b590bd42 100644 --- a/lib/poll.c +++ b/lib/poll.c @@ -1,22 +1,22 @@ /* Emulation for poll(2) Contributed by Paolo Bonzini. - Copyright 2001-2003, 2006-2017 Free Software Foundation, Inc. + Copyright 2001-2003, 2006-2019 Free Software Foundation, Inc. This file is part of gnulib. This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by + it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. + GNU General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along - with this program; if not, see . */ + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ /* Tell gcc not to warn about the (nfd < 0) tests, below. */ #if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ @@ -34,14 +34,18 @@ #include #include -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +#if defined _WIN32 && ! defined __CYGWIN__ # define WINDOWS_NATIVE # include # include # include # include # include -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #else # include # include @@ -72,6 +76,29 @@ #ifdef WINDOWS_NATIVE +/* Do *not* use the function WSAPoll + + because there is a bug named “Windows 8 Bugs 309411 - WSAPoll does not + report failed connections” that Microsoft won't fix. + See Daniel Stenberg: "WASPoll is broken" + . */ + +/* Here we need the recv() function from Windows, that takes a SOCKET as + first argument, not any possible gnulib override. */ +# undef recv + +/* Here we need the select() function from Windows, because we pass bit masks + of SOCKETs, not bit masks of FDs. */ +# undef select + +/* Here we need timeval from Windows since this is what the select() function + from Windows requires. */ +# undef timeval + +/* Avoid warnings from gcc -Wcast-function-type. */ +# define GetProcAddress \ + (void *) GetProcAddress + static BOOL IsConsoleHandle (HANDLE h) { DWORD mode; @@ -335,13 +362,13 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout) int maxfd, rc; nfds_t i; - if (nfd < 0) + if (nfd > INT_MAX) { errno = EINVAL; return -1; } - /* Don't check directly for NFD too large. Any practical use of a - too-large NFD is caught by one of the other checks below, and + /* Don't check directly for NFD greater than OPEN_MAX. Any practical use + of a too-large NFD is caught by one of the other checks below, and checking directly for getdtablesize is too much of a portability and/or performance and/or correctness hassle. */ @@ -433,7 +460,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout) int rc = 0; nfds_t i; - if (nfd < 0 || timeout < -1) + if (nfd > INT_MAX || timeout < -1) { errno = EINVAL; return -1; diff --git a/lib/poll.in.h b/lib/poll.in.h index e9b141d8f..0b115dcb3 100644 --- a/lib/poll.in.h +++ b/lib/poll.in.h @@ -1,22 +1,22 @@ /* Header for poll(2) emulation Contributed by Paolo Bonzini. - Copyright 2001-2003, 2007, 2009-2017 Free Software Foundation, Inc. + Copyright 2001-2003, 2007, 2009-2019 Free Software Foundation, Inc. This file is part of gnulib. This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by + it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. + GNU General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along - with this program; if not, see . */ + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ #ifndef _@GUARD_PREFIX@_POLL_H @@ -33,6 +33,13 @@ #ifndef _@GUARD_PREFIX@_POLL_H #define _@GUARD_PREFIX@_POLL_H +/* On native Windows, get the 'struct pollfd' type and the POLL* macro + definitions before we override them. mingw defines them in + if _WIN32_WINNT >= 0x0600. */ +#if @HAVE_WINSOCK2_H@ +# include +#endif + /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ @@ -41,6 +48,21 @@ #if !@HAVE_POLL_H@ +# if @HAVE_WINSOCK2_H@ +/* Override the definitions from . */ +# undef POLLIN +# undef POLLPRI +# undef POLLOUT +# undef POLLERR +# undef POLLHUP +# undef POLLNVAL +# undef POLLRDNORM +# undef POLLRDBAND +# undef POLLWRNORM +# undef POLLWRBAND +# define pollfd rpl_pollfd +# endif + /* fake a poll(2) environment */ # define POLLIN 0x0001 /* any readable data available */ # define POLLPRI 0x0002 /* OOB/Urgent readable data */ diff --git a/m4/poll.m4 b/m4/poll.m4 index 5706ab514..354d1666b 100644 --- a/m4/poll.m4 +++ b/m4/poll.m4 @@ -1,5 +1,5 @@ -# poll.m4 serial 17 -dnl Copyright (c) 2003, 2005-2007, 2009-2017 Free Software Foundation, Inc. +# poll.m4 serial 19 +dnl Copyright (c) 2003, 2005-2007, 2009-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -8,6 +8,7 @@ AC_DEFUN([gl_FUNC_POLL], [ AC_REQUIRE([gl_POLL_H]) AC_REQUIRE([gl_SOCKETS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles if test $ac_cv_header_poll_h = no; then ac_cv_func_poll=no gl_cv_func_poll=no @@ -53,16 +54,19 @@ AC_DEFUN([gl_FUNC_POLL], #if (defined(__APPLE__) && defined(__MACH__)) || defined(_AIX) This is MacOSX or AIX #endif -], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])]) - fi - if test $gl_cv_func_poll != yes; then - AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no]) - if test $ac_cv_func_poll = no; then - HAVE_POLL=0 - else - REPLACE_POLL=1 - fi +], [gl_cv_func_poll="guessing no"], [gl_cv_func_poll="guessing yes"])])]) fi + case "$gl_cv_func_poll" in + *yes) ;; + *) + AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no]) + if test $ac_cv_func_poll = no; then + HAVE_POLL=0 + else + REPLACE_POLL=1 + fi + ;; + esac if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then : else diff --git a/m4/poll_h.m4 b/m4/poll_h.m4 index b3d6dab5a..8f0e10528 100644 --- a/m4/poll_h.m4 +++ b/m4/poll_h.m4 @@ -1,5 +1,5 @@ -# poll_h.m4 serial 2 -dnl Copyright (C) 2010-2017 Free Software Foundation, Inc. +# poll_h.m4 serial 3 +dnl Copyright (C) 2010-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -23,6 +23,8 @@ AC_DEFUN([gl_POLL_H], dnl is always overridden, because of GNULIB_POSIXCHECK. gl_CHECK_NEXT_HEADERS([poll.h]) + gl_PREREQ_SYS_H_WINSOCK2 dnl for HAVE_WINSOCK2_H + dnl Check for declarations of anything we want to poison if the dnl corresponding gnulib module is not in use. gl_WARN_ON_USE_PREPARE([[#include ]], -- 2.22.0