bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* modules poll* fail on mingw-w64 for i686 and x86_64
@ 2019-06-29  6:54 Hannes Müller
  2019-06-29 14:06 ` Bruno Haible
  0 siblings, 1 reply; 6+ messages in thread
From: Hannes Müller @ 2019-06-29  6:54 UTC (permalink / raw)
  To: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 4970 bytes --]

Hi,
on platform mingw-w64 for i686 and x86_64 I noticed the poll* modules
fail to compile with slightly different errors.
For the following test command I got the below noted output.
./gnulib-tool --create-testdir --dir=/tmp/testdir poll poll-tests poll-
h poll-h-testscd /tmp/testdir./configure && make
Result for i686:
 In file included from
poll.c:39:C:/Users/hm/Documents/msys32/mingw32/i686-w64-
mingw32/include/winsock2.h:1155:16: error: redefinition of 'struct
pollfd' 1155 | typedef struct pollfd {      |                ^~~~~~In
file included from poll.c:32:./poll.h:506:8: note: originally defined
here  506 | struct pollfd      |        ^~~~~~poll.c:345:1: error:
conflicting types for 'poll'  345 | poll (struct pollfd *pfd, nfds_t
nfd, int timeout)      | ^~~~In file included from
poll.c:32:./poll.h:536:1: note: previous declaration of 'poll' was
here  536 | _GL_FUNCDECL_SYS (poll, int, (struct pollfd *pfd, nfds_t
nfd, int timeout));      | ^~~~~~~~~~~~~~~~make[4]: *** [Makefile:1459:
poll.o] Fehler 1make[4]: Verzeichnis „/tmp/testdir/gllib“ wird
verlassenmake[3]: *** [Makefile:1481: all-recursive] Fehler 1make[3]:
Verzeichnis „/tmp/testdir/gllib“ wird verlassenmake[2]: ***
[Makefile:1318: all] Fehler 2make[2]: Verzeichnis „/tmp/testdir/gllib“
wird verlassenmake[1]: *** [Makefile:1220: all-recursive] Fehler
1make[1]: Verzeichnis „/tmp/testdir“ wird verlassenmake: ***
[Makefile:1161: all] Fehler 2

Result for x86_64:

In file included from
poll.c:39:C:/Users/hm/Documents/msys32/mingw64/x86_64-w64-
mingw32/include/winsock2.h:1155:16: error: redefinition of 'struct
pollfd' 1155 | typedef struct pollfd {      |                ^~~~~~In
file included from poll.c:32:./poll.h:506:8: note: originally defined
here  506 | struct pollfd      |        ^~~~~~poll.c:345:1: error:
conflicting types for 'poll'  345 | poll (struct pollfd *pfd, nfds_t
nfd, int timeout)      | ^~~~In file included from
poll.c:32:./poll.h:536:1: note: previous declaration of 'poll' was
here  536 | _GL_FUNCDECL_SYS (poll, int, (struct pollfd *pfd, nfds_t
nfd, int timeout));      | ^~~~~~~~~~~~~~~~poll.c: In function
'poll':poll.c:519:39: warning: passing argument 5 of 'select' from
incompatible pointer type [-Wincompatible-pointer-types]  519 |   if
(select (0, &rfds, &wfds, &xfds, &tv0) >
0)      |                                       ^~~~      |            
                           |      |                                    
   struct rpl_timeval *In file included from
poll.c:39:C:/Users/th18mn/Documents/msys32/mingw64/x86_64-w64-
mingw32/include/winsock2.h:995:116: note: expected 'PTIMEVAL' {aka
'struct timeval * const'} but argument is of type 'struct rpl_timeval
*'  995 |   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set
*readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL
timeout);      |                                                       
                                              ~~~~~~~~~~~~~~~^~~~~~~pol
l.c:555:37: warning: passing argument 5 of 'select' from incompatible
pointer type [-Wincompatible-pointer-types]  555 |     select (0,
&rfds, &wfds, &xfds,
&tv0);      |                                     ^~~~      |          
                           |      |                                    
 struct rpl_timeval *In file included from
poll.c:39:C:/Users/th18mn/Documents/msys32/mingw64/x86_64-w64-
mingw32/include/winsock2.h:995:116: note: expected 'PTIMEVAL' {aka
'struct timeval * const'} but argument is of type 'struct rpl_timeval
*'  995 |   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set
*readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL
timeout);      |                                                       
                                              ~~~~~~~~~~~~~~~^~~~~~~mak
e[4]: *** [Makefile:1459: poll.o] Fehler 1make[4]: Verzeichnis
„/tmp/testdir-64/gllib“ wird verlassenmake[3]: *** [Makefile:1481: all-
recursive] Fehler 1make[3]: Verzeichnis „/tmp/testdir-64/gllib“ wird
verlassenmake[2]: *** [Makefile:1318: all] Fehler 2make[2]: Verzeichnis
„/tmp/testdir-64/gllib“ wird verlassenmake[1]: *** [Makefile:1221: all-
recursive] Fehler 1make[1]: Verzeichnis „/tmp/testdir-64“ wird
verlassenmake: *** [Makefile:1162: all] Fehler 2
I very much appreciate a fix. Thanks!

[-- Attachment #2: Type: text/html, Size: 11437 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: modules poll* fail on mingw-w64 for i686 and x86_64
  2019-06-29  6:54 modules poll* fail on mingw-w64 for i686 and x86_64 Hannes Müller
@ 2019-06-29 14:06 ` Bruno Haible
  2019-06-29 18:32   ` Hannes Müller
  0 siblings, 1 reply; 6+ messages in thread
From: Bruno Haible @ 2019-06-29 14:06 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Hannes Müller

Hi,

Hannes Müller wrote:
> on platform mingw-w64 for i686 and x86_64 I noticed the poll* modules
> fail to compile with slightly different errors.
> For the following test command I got the below noted output.

The output is unreadable, because line breaks have been removed from
where they originally were, and other line breaks were inserted. Can you
resend the output with readable line-breaking?

Bruno



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: modules poll* fail on mingw-w64 for i686 and x86_64
  2019-06-29 14:06 ` Bruno Haible
@ 2019-06-29 18:32   ` Hannes Müller
  2019-06-30 12:46     ` Bruno Haible
  0 siblings, 1 reply; 6+ messages in thread
From: Hannes Müller @ 2019-06-29 18:32 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 5037 bytes --]

Hi Bruno, 

Thanks for your reply. Sorry, now the output with correct line breaks.
For the following test command I got the below noted output on mingw-
w64 with latest gnulib from git repository.

./gnulib-tool --create-testdir --dir=/tmp/testdir poll poll-tests poll-
h poll-h-tests
cd /tmp/testdir
./configure && make




Result for i686:

In file included from poll.c:39:
C:/Users/hm/Documents/msys32/mingw32/i686-w64-
mingw32/include/winsock2.h:1155:16: error: redefinition of 'struct
pollfd'
 1155 | typedef struct pollfd {
      |                ^~~~~~
In file included from poll.c:32:
./poll.h:506:8: note: originally defined here
  506 | struct pollfd
      |        ^~~~~~
poll.c:345:1: error: conflicting types for 'poll'
  345 | poll (struct pollfd *pfd, nfds_t nfd, int timeout)
      | ^~~~
In file included from poll.c:32:
./poll.h:536:1: note: previous declaration of 'poll' was here
  536 | _GL_FUNCDECL_SYS (poll, int, (struct pollfd *pfd, nfds_t nfd,
int timeout));
      | ^~~~~~~~~~~~~~~~
make[4]: *** [Makefile:1459: poll.o] Fehler 1
make[4]: Verzeichnis „/tmp/testdir/gllib“ wird verlassen
make[3]: *** [Makefile:1481: all-recursive] Fehler 1
make[3]: Verzeichnis „/tmp/testdir/gllib“ wird verlassen
make[2]: *** [Makefile:1318: all] Fehler 2
make[2]: Verzeichnis „/tmp/testdir/gllib“ wird verlassen
make[1]: *** [Makefile:1220: all-recursive] Fehler 1
make[1]: Verzeichnis „/tmp/testdir“ wird verlassen
make: *** [Makefile:1161: all] Fehler 2

Result for x86_64:


In file included from poll.c:39:
C:/Users/hm/Documents/msys32/mingw64/x86_64-w64-
mingw32/include/winsock2.h:1155:16: error: redefinition of 'struct
pollfd'
 1155 | typedef struct pollfd {
      |                ^~~~~~
In file included from poll.c:32:
./poll.h:506:8: note: originally defined here
  506 | struct pollfd
      |        ^~~~~~
poll.c:345:1: error: conflicting types for 'poll'
  345 | poll (struct pollfd *pfd, nfds_t nfd, int timeout)
      | ^~~~
In file included from poll.c:32:
./poll.h:536:1: note: previous declaration of 'poll' was here
  536 | _GL_FUNCDECL_SYS (poll, int, (struct pollfd *pfd, nfds_t nfd,
int timeout));
      | ^~~~~~~~~~~~~~~~
poll.c: In function 'poll':
poll.c:519:39: warning: passing argument 5 of 'select' from
incompatible pointer type [-Wincompatible-pointer-types]
  519 |   if (select (0, &rfds, &wfds, &xfds, &tv0) > 0)
      |                                       ^~~~
      |                                       |
      |                                       struct rpl_timeval *
In file included from poll.c:39:
C:/Users/hm/Documents/msys32/mingw64/x86_64-w64-
mingw32/include/winsock2.h:995:116: note: expected 'PTIMEVAL' {aka
'struct timeval * const'} but argument is of type 'struct rpl_timeval
*'
  995 |   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set
*readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL timeout);
      |                                                                
                                     ~~~~~~~~~~~~~~~^~~~~~~
poll.c:555:37: warning: passing argument 5 of 'select' from
incompatible pointer type [-Wincompatible-pointer-types]
  555 |     select (0, &rfds, &wfds, &xfds, &tv0);
      |                                     ^~~~
      |                                     |
      |                                     struct rpl_timeval *
In file included from poll.c:39:
C:/Users/hm/Documents/msys32/mingw64/x86_64-w64-
mingw32/include/winsock2.h:995:116: note: expected 'PTIMEVAL' {aka
'struct timeval * const'} but argument is of type 'struct rpl_timeval
*'
  995 |   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set
*readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL timeout);
      |                                                                
                                     ~~~~~~~~~~~~~~~^~~~~~~
make[4]: *** [Makefile:1459: poll.o] Fehler 1
make[4]: Verzeichnis „/tmp/testdir-64/gllib“ wird verlassen
make[3]: *** [Makefile:1481: all-recursive] Fehler 1
make[3]: Verzeichnis „/tmp/testdir-64/gllib“ wird verlassen
make[2]: *** [Makefile:1318: all] Fehler 2
make[2]: Verzeichnis „/tmp/testdir-64/gllib“ wird verlassen
make[1]: *** [Makefile:1221: all-recursive] Fehler 1
make[1]: Verzeichnis „/tmp/testdir-64“ wird verlassen
make: *** [Makefile:1162: all] Fehler 2


[-- Attachment #2: Type: text/html, Size: 11541 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: modules poll* fail on mingw-w64 for i686 and x86_64
  2019-06-29 18:32   ` Hannes Müller
@ 2019-06-30 12:46     ` Bruno Haible
  2019-07-01 18:16       ` Patch: Fix warning for timeval in poll.c on mingw-w64 for x86_64 Hannes Müller
  0 siblings, 1 reply; 6+ messages in thread
From: Bruno Haible @ 2019-06-30 12:46 UTC (permalink / raw)
  To: Hannes Müller; +Cc: bug-gnulib

Hannes Müller wrote:
> In file included from poll.c:39:
> C:/Users/hm/Documents/msys32/mingw32/i686-w64-
> mingw32/include/winsock2.h:1155:16: error: redefinition of 'struct
> pollfd'
>  1155 | typedef struct pollfd {
>       |                ^~~~~~
> In file included from poll.c:32:
> ./poll.h:506:8: note: originally defined here
>   506 | struct pollfd
>       |        ^~~~~~

Thanks for the report. I reproduce it, when adding -D_WIN32_WINNT=0x0600
(-> compilation for Windows Vista or newer) to the CPPFLAGS.

This patch fixes it.


2019-06-30  Bruno Haible  <bruno@clisp.org>

	poll-h: Fix compilation error on mingw with _WIN32_WINNT >= 0x0600.
	Reported by Hannes Müller <h.c.f.mueller@gmx.de>.
	* lib/poll.in.h: Include <winsock2.h>.
	(POLL*, pollfd): Override on native Windows.
	* m4/poll_h.m4 (gl_POLL_H): Invoke gl_PREREQ_SYS_H_WINSOCK2.
	* modules/poll-h (Files): Add m4/sys_socket_h.m4.
	(Makefile.am): Substitute HAVE_WINSOCK2_H.

diff --git a/lib/poll.in.h b/lib/poll.in.h
index 5cf6566..0b115dc 100644
--- a/lib/poll.in.h
+++ b/lib/poll.in.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 <winsock2.h>
+   if _WIN32_WINNT >= 0x0600.  */
+#if @HAVE_WINSOCK2_H@
+# include <winsock2.h>
+#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 <winsock2.h>.  */
+#  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_h.m4 b/m4/poll_h.m4
index 94de19b..8f0e105 100644
--- a/m4/poll_h.m4
+++ b/m4/poll_h.m4
@@ -1,4 +1,4 @@
-# poll_h.m4 serial 2
+# 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,
@@ -23,6 +23,8 @@ AC_DEFUN([gl_POLL_H],
   dnl <poll.h> 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 <poll.h>]],
diff --git a/modules/poll-h b/modules/poll-h
index c1d3969..3c68758 100644
--- a/modules/poll-h
+++ b/modules/poll-h
@@ -4,6 +4,7 @@ A POSIX-like <poll.h>.
 Files:
 lib/poll.in.h
 m4/poll_h.m4
+m4/sys_socket_h.m4
 
 Depends-on:
 extensions
@@ -29,6 +30,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)' \



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Patch: Fix warning for timeval in poll.c on mingw-w64 for x86_64
  2019-06-30 12:46     ` Bruno Haible
@ 2019-07-01 18:16       ` Hannes Müller
  2019-07-01 23:51         ` Bruno Haible
  0 siblings, 1 reply; 6+ messages in thread
From: Hannes Müller @ 2019-07-01 18:16 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib


[-- Attachment #1.1: Type: text/plain, Size: 2947 bytes --]

Hi Bruno,

Thanks for poll the fixes. 
I would like to propose attached patch to fix on mingw-w64 for x86_64
still present problem:


poll.c: In function 'poll':
poll.c:526:39: warning: passing argument 5 of 'select' from
incompatible pointer type [-Wincompatible-pointer-types]
  526 |   if (select (0, &rfds, &wfds, &xfds, &tv0) > 0)
      |                                       ^~~~
      |                                       |
      |                                       struct rpl_timeval *
In file included from ./poll.h:41,
                 from poll.c:32:
C:/Users/hm/Documents/msys32/mingw64/x86_64-w64-
mingw32/include/winsock2.h:995:116: note: expected 'PTIMEVAL' {aka
'struct timeval * const'} but argument is of type 'struct rpl_timeval
*'
  995 |   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set
*readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL timeout);
      |                                                                
                                     ~~~~~~~~~~~~~~~^~~~~~~
poll.c:562:37: warning: passing argument 5 of 'select' from
incompatible pointer type [-Wincompatible-pointer-types]
  562 |     select (0, &rfds, &wfds, &xfds, &tv0);
      |                                     ^~~~
      |                                     |
      |                                     struct rpl_timeval *
In file included from ./poll.h:41,
                 from poll.c:32:
C:/Users/hm/Documents/msys32/mingw64/x86_64-w64-
mingw32/include/winsock2.h:995:116: note: expected 'PTIMEVAL' {aka
'struct timeval * const'} but argument is of type 'struct rpl_timeval
*'
  995 |   WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set
*readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL timeout);
      |                                                                
                                     ~~~~~~~~~~~~~~~^~~~~~



It turns out in sys_time.in.h:
i686:   @REPLACE_STRUCT_TIMEVAL@=0
x86_64: @REPLACE_STRUCT_TIMEVAL@=1


causing poll.c line 448 on x86_64 to become
static struct rpl_timeval tv0;


But poll.c in line 90 states:
/* Here we need the select() function from Windows, because we pass bit
masks 
   of SOCKETs, not bit masks of FDs.  */

So we need also the original timeval definiton from Windows at least
for x86_64.

Thanks for reviewing the patch.

Best regards
Hannes

[-- Attachment #1.2: Type: text/html, Size: 7133 bytes --]

[-- Attachment #2: Fix_warning_for_timeval_in_poll_c_on_mingw_w64_for_x86_64.patch --]
[-- Type: text/x-patch, Size: 804 bytes --]

From 3a46ec557f72d4c46adba8e8b39a6344bb911570 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hannes=20M=C3=BCller?= <h.c.f.mueller@gmx.de>
Date: Mon, 1 Jul 2019 16:59:45 +0200
Subject: [PATCH] Fix warning for timeval in poll.c on mingw-w64 for x86_64

* lib/poll.c: call windows native select() with windows native timeval
---
 lib/poll.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/poll.c b/lib/poll.c
index 5d9150c13..330144950 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -91,6 +91,10 @@
    of SOCKETs, not bit masks of FDs.  */
 # undef select
 
+/* Here we need timeval from Windows since this is what select() function
+   from Windows requires */
+# undef timeval
+
 /* Avoid warnings from gcc -Wcast-function-type.  */
 # define GetProcAddress \
    (void *) GetProcAddress
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Patch: Fix warning for timeval in poll.c on mingw-w64 for x86_64
  2019-07-01 18:16       ` Patch: Fix warning for timeval in poll.c on mingw-w64 for x86_64 Hannes Müller
@ 2019-07-01 23:51         ` Bruno Haible
  0 siblings, 0 replies; 6+ messages in thread
From: Bruno Haible @ 2019-07-01 23:51 UTC (permalink / raw)
  To: Hannes Müller; +Cc: bug-gnulib

Hi Hannes,

> Thanks for poll the fixes. 
> I would like to propose attached patch to fix on mingw-w64 for x86_64
> still present problem:
> 
> 
> poll.c: In function 'poll':
> poll.c:526:39: warning: passing argument 5 of 'select' from
> incompatible pointer type [-Wincompatible-pointer-types]
>   526 |   if (select (0, &rfds, &wfds, &xfds, &tv0) > 0)
>       |                                       ^~~~
>       |                                       |
>       |                                       struct rpl_timeval *
> In file included from ./poll.h:41,
>                  from poll.c:32:
> C:/Users/hm/Documents/msys32/mingw64/x86_64-w64-
> mingw32/include/winsock2.h:995:116: note: expected 'PTIMEVAL' {aka
> 'struct timeval * const'} but argument is of type 'struct rpl_timeval
> *'
> ...
> 
> 
> It turns out in sys_time.in.h:
> i686:   @REPLACE_STRUCT_TIMEVAL@=0
> x86_64: @REPLACE_STRUCT_TIMEVAL@=1
> 
> 
> causing poll.c line 448 on x86_64 to become
> static struct rpl_timeval tv0;
> 
> 
> But poll.c in line 90 states:
> /* Here we need the select() function from Windows, because we pass bit
> masks 
>    of SOCKETs, not bit masks of FDs.  */
> 
> So we need also the original timeval definiton from Windows at least
> for x86_64.

Thanks! Good observation. Convincing explanation of the cause. Good patch.
=> Applied.

Bruno



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-07-02  2:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-29  6:54 modules poll* fail on mingw-w64 for i686 and x86_64 Hannes Müller
2019-06-29 14:06 ` Bruno Haible
2019-06-29 18:32   ` Hannes Müller
2019-06-30 12:46     ` Bruno Haible
2019-07-01 18:16       ` Patch: Fix warning for timeval in poll.c on mingw-w64 for x86_64 Hannes Müller
2019-07-01 23:51         ` Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).