diff mbox

w32: include winsock2.h before windows.h

Message ID 1455027417-32278-1-git-send-email-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paolo Bonzini Feb. 9, 2016, 2:16 p.m. UTC
Recent Fedora complains while compiling ui/sdl.c:

    /usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock2.h:15:2: warning: #warning Please include winsock2.h before windows.h [-Wcpp]

And with this patch we dutifully obey.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/sysemu/os-win32.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Daniel P. Berrangé Feb. 9, 2016, 2:21 p.m. UTC | #1
On Tue, Feb 09, 2016 at 03:16:57PM +0100, Paolo Bonzini wrote:
> Recent Fedora complains while compiling ui/sdl.c:
> 
>     /usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock2.h:15:2: warning: #warning Please include winsock2.h before windows.h [-Wcpp]
> 
> And with this patch we dutifully obey.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/sysemu/os-win32.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> index 400e098..fbed346 100644
> --- a/include/sysemu/os-win32.h
> +++ b/include/sysemu/os-win32.h
> @@ -26,8 +26,8 @@
>  #ifndef QEMU_OS_WIN32_H
>  #define QEMU_OS_WIN32_H
>  
> -#include <windows.h>
>  #include <winsock2.h>
> +#include <windows.h>
>  
>  /* Workaround for older versions of MinGW. */
>  #ifndef ECONNREFUSED

include/qemu/sockets.h also has windows.h included before winsock2.h

Presumably it didn't cause a failure for you because everything using
sockets.h already pulls in osdep.h. A reason to prune sockets.h
headers perhaps.

Regards,
Daniel
Peter Maydell Feb. 9, 2016, 2:28 p.m. UTC | #2
On 9 February 2016 at 14:21, Daniel P. Berrange <berrange@redhat.com> wrote:
> On Tue, Feb 09, 2016 at 03:16:57PM +0100, Paolo Bonzini wrote:
> include/qemu/sockets.h also has windows.h included before winsock2.h
>
> Presumably it didn't cause a failure for you because everything using
> sockets.h already pulls in osdep.h. A reason to prune sockets.h
> headers perhaps.

More generally we could prune anything including windows.h manually
(there are a dozen or so .c and .h files doing that currently).

thanks
-- PMM
Paolo Bonzini Feb. 9, 2016, 2:37 p.m. UTC | #3
On 09/02/2016 15:28, Peter Maydell wrote:
> On 9 February 2016 at 14:21, Daniel P. Berrange <berrange@redhat.com> wrote:
>> > On Tue, Feb 09, 2016 at 03:16:57PM +0100, Paolo Bonzini wrote:
>> > include/qemu/sockets.h also has windows.h included before winsock2.h
>> >
>> > Presumably it didn't cause a failure for you because everything using
>> > sockets.h already pulls in osdep.h. A reason to prune sockets.h
>> > headers perhaps.
> More generally we could prune anything including windows.h manually
> (there are a dozen or so .c and .h files doing that currently).

I honestly do not have time to work on this. :(

Paolo
Peter Maydell Feb. 9, 2016, 2:38 p.m. UTC | #4
On 9 February 2016 at 14:37, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>
> On 09/02/2016 15:28, Peter Maydell wrote:
>> On 9 February 2016 at 14:21, Daniel P. Berrange <berrange@redhat.com> wrote:
>>> > On Tue, Feb 09, 2016 at 03:16:57PM +0100, Paolo Bonzini wrote:
>>> > include/qemu/sockets.h also has windows.h included before winsock2.h
>>> >
>>> > Presumably it didn't cause a failure for you because everything using
>>> > sockets.h already pulls in osdep.h. A reason to prune sockets.h
>>> > headers perhaps.
>> More generally we could prune anything including windows.h manually
>> (there are a dozen or so .c and .h files doing that currently).
>
> I honestly do not have time to work on this. :(

That's OK, I currently have a bunch of include file cleanups
going through so one more won't hurt too much :-)

-- PMM
Stefan Weil Feb. 9, 2016, 4:03 p.m. UTC | #5
Am 09.02.2016 um 15:16 schrieb Paolo Bonzini:
> Recent Fedora complains while compiling ui/sdl.c:
>
>     /usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock2.h:15:2: warning: #warning Please include winsock2.h before windows.h [-Wcpp]
>
> And with this patch we dutifully obey.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/sysemu/os-win32.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> index 400e098..fbed346 100644
> --- a/include/sysemu/os-win32.h
> +++ b/include/sysemu/os-win32.h
> @@ -26,8 +26,8 @@
>  #ifndef QEMU_OS_WIN32_H
>  #define QEMU_OS_WIN32_H
>  
> -#include <windows.h>
>  #include <winsock2.h>
> +#include <windows.h>
>  
>  /* Workaround for older versions of MinGW. */
>  #ifndef ECONNREFUSED

Reviewed-by: Stefan Weil <sw@weilnetz.de>

Without that patch, windows.h will include winsock.h
(which conflicts with winsock2.h) when compiling sdl.c.

Normally we define WIN32_LEAN_AND_MEAN, and
windows.h won't include winsock.h.

include/ui/sdl2.h and ui/sdl.c undefine that macro,
so the order of the include files is important.

Without testing this, I think that Paolo's patch is needed
since commit e16f4c8770b73f530dad842a31298963b6c7e41d.
Paolo Bonzini Feb. 9, 2016, 4:06 p.m. UTC | #6
On 09/02/2016 17:03, Stefan Weil wrote:
> Reviewed-by: Stefan Weil <sw@weilnetz.de>
> 
> Without that patch, windows.h will include winsock.h
> (which conflicts with winsock2.h) when compiling sdl.c.
> 
> Normally we define WIN32_LEAN_AND_MEAN, and
> windows.h won't include winsock.h.
> 
> include/ui/sdl2.h and ui/sdl.c undefine that macro,
> so the order of the include files is important.
> 
> Without testing this, I think that Paolo's patch is needed
> since commit e16f4c8770b73f530dad842a31298963b6c7e41d.
> 

That also explains why only that file complains.  Thanks!

Paolo
Michael Tokarev Feb. 11, 2016, 5:56 a.m. UTC | #7
09.02.2016 17:16, Paolo Bonzini wrote:
> Recent Fedora complains while compiling ui/sdl.c:
> 
>     /usr/x86_64-w64-mingw32/sys-root/mingw/include/winsock2.h:15:2: warning: #warning Please include winsock2.h before windows.h [-Wcpp]
> 
> And with this patch we dutifully obey.

Applied to -trivial, adding Stefan's comments to the commit
message too.

Thanks,

/mjt
diff mbox

Patch

diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index 400e098..fbed346 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -26,8 +26,8 @@ 
 #ifndef QEMU_OS_WIN32_H
 #define QEMU_OS_WIN32_H
 
-#include <windows.h>
 #include <winsock2.h>
+#include <windows.h>
 
 /* Workaround for older versions of MinGW. */
 #ifndef ECONNREFUSED