# [PATCH 01/14] msvc: Fix compilation errors in compat/win32/sys/poll.c

8 messages from 2010-12-04 to 2010-12-11. Participants: Ramsay Jones, Jonathan Nieder, Erik Faye-Lund, Johannes Sixt.
Thread: https://gitlist.dev/t/25955

## Ramsay Jones, 2010-12-04 18:54

Subject: [PATCH 01/14] msvc: Fix compilation errors in compat/win32/sys/poll.c
Message-ID: <4CFA8E64.6070402@ramsay1.demon.co.uk>
URL: https://gitlist.dev/e/4CFA8E64.6070402%40ramsay1.demon.co.uk

```

The msvc winsock2.h header file conditionally defines or declares
poll() related symbols which cause many macro redefinition errors,
a struct type redefinition error and syntax errors. These symbols
are defined in support of the WSAPoll() API, new in Windows Vista,
when the symbol _WIN32_WINNT is defined and _WIN32_WINNT >= 0x0600.

In order to avoid the compilation errors, we set _WIN32_WINNT to
0x0502 (which would target Windows Server 2003) prior to including
the winsock2.h header file.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 compat/win32/sys/poll.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/compat/win32/sys/poll.c b/compat/win32/sys/poll.c
index 7e74ebe..708a6c9 100644
--- a/compat/win32/sys/poll.c
+++ b/compat/win32/sys/poll.c
@@ -34,6 +34,9 @@
 
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 # define WIN32_NATIVE
+# if defined (_MSC_VER)
+#  define _WIN32_WINNT 0x0502
+# endif
 # include <winsock2.h>
 # include <windows.h>
 # include <io.h>
-- 
1.7.3

```

## Jonathan Nieder, 2010-12-04 20:45

Subject: Re: [PATCH 01/14] msvc: Fix compilation errors in compat/win32/sys/poll.c
Message-ID: <20101204204541.GA3170@burratino>
URL: https://gitlist.dev/e/20101204204541.GA3170%40burratino
In-Reply-To: <4CFA8E64.6070402@ramsay1.demon.co.uk>

```
Ramsay Jones wrote:

> The msvc winsock2.h header file conditionally defines or declares
> poll() related symbols which cause many macro redefinition errors,
> a struct type redefinition error and syntax errors. These symbols
> are defined in support of the WSAPoll() API, new in Windows Vista,
> when the symbol _WIN32_WINNT is defined and _WIN32_WINNT >= 0x0600.

Could it make sense to define this at the same time as _GNU_SOURCE et
al?

	#define _ALL_SOURCE 1
	#define _GNU_SOURCE 1
	#define _BSD_SOURCE 1
	#define _NETBSD_SOURCE 1
	#define _SGI_SOURCE 1
	#define _WIN32_WINNT 0x0502

Haven't thought carefully about the consequences, though; your patch
is probably safer.

```

## Erik Faye-Lund, 2010-12-04 21:12

Subject: Re: [PATCH 01/14] msvc: Fix compilation errors in compat/win32/sys/poll.c
Message-ID: <AANLkTinDoeYarLQLtZ327a7Us0cvaN42NFCoYorwMsT-@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinDoeYarLQLtZ327a7Us0cvaN42NFCoYorwMsT-%40mail.gmail.com
In-Reply-To: <4CFA8E64.6070402@ramsay1.demon.co.uk>

```
On Sat, Dec 4, 2010 at 7:54 PM, Ramsay Jones <ramsay@ramsay1.demon.co.uk> wrote:
>
> The msvc winsock2.h header file conditionally defines or declares
> poll() related symbols which cause many macro redefinition errors,
> a struct type redefinition error and syntax errors. These symbols
> are defined in support of the WSAPoll() API, new in Windows Vista,
> when the symbol _WIN32_WINNT is defined and _WIN32_WINNT >= 0x0600.
>
> In order to avoid the compilation errors, we set _WIN32_WINNT to
> 0x0502 (which would target Windows Server 2003) prior to including
> the winsock2.h header file.
>
> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
> ---
>  compat/win32/sys/poll.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/compat/win32/sys/poll.c b/compat/win32/sys/poll.c
> index 7e74ebe..708a6c9 100644
> --- a/compat/win32/sys/poll.c
> +++ b/compat/win32/sys/poll.c
> @@ -34,6 +34,9 @@
>
>  #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
>  # define WIN32_NATIVE
> +# if defined (_MSC_VER)
> +#  define _WIN32_WINNT 0x0502
> +# endif
>  # include <winsock2.h>
>  # include <windows.h>
>  # include <io.h>

I have an almost identical patch in my msvc-tree, so FWIW:

Acked-by: Erik Faye-Lund <kusmabite@gmail.com>

```

## Johannes Sixt, 2010-12-04 21:22

Subject: Re: [PATCH 01/14] msvc: Fix compilation errors in compat/win32/sys/poll.c
Message-ID: <201012042222.23384.j6t@kdbg.org>
URL: https://gitlist.dev/e/201012042222.23384.j6t%40kdbg.org
In-Reply-To: <4CFA8E64.6070402@ramsay1.demon.co.uk>

```
On Samstag, 4. Dezember 2010, Ramsay Jones wrote:
> The msvc winsock2.h header file conditionally defines or declares
> poll() related symbols which cause many macro redefinition errors,
> a struct type redefinition error and syntax errors. These symbols
> are defined in support of the WSAPoll() API, new in Windows Vista,
> when the symbol _WIN32_WINNT is defined and _WIN32_WINNT >= 0x0600.
>
> In order to avoid the compilation errors, we set _WIN32_WINNT to
> 0x0502 (which would target Windows Server 2003) prior to including
> the winsock2.h header file.
>
> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
> ---
>  compat/win32/sys/poll.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/compat/win32/sys/poll.c b/compat/win32/sys/poll.c
> index 7e74ebe..708a6c9 100644
> --- a/compat/win32/sys/poll.c
> +++ b/compat/win32/sys/poll.c
> @@ -34,6 +34,9 @@
>
>  #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
>  # define WIN32_NATIVE
> +# if defined (_MSC_VER)
> +#  define _WIN32_WINNT 0x0502
> +# endif
>  # include <winsock2.h>
>  # include <windows.h>
>  # include <io.h>

Don't you have to do the same in git-compat-util.h?

-- Hannes

```

## Ramsay Jones, 2010-12-07 22:54

Subject: Re: [PATCH 01/14] msvc: Fix compilation errors in compat/win32/sys/poll.c
Message-ID: <4CFEBB3E.2060401@ramsay1.demon.co.uk>
URL: https://gitlist.dev/e/4CFEBB3E.2060401%40ramsay1.demon.co.uk
In-Reply-To: <20101204204541.GA3170@burratino>

```
Jonathan Nieder wrote:
> Could it make sense to define this at the same time as _GNU_SOURCE et
> al?
> 
> 	#define _ALL_SOURCE 1
> 	#define _GNU_SOURCE 1
> 	#define _BSD_SOURCE 1
> 	#define _NETBSD_SOURCE 1
> 	#define _SGI_SOURCE 1
> 	#define _WIN32_WINNT 0x0502
> 
> Haven't thought carefully about the consequences, though; your patch
> is probably safer.

[Sorry for the late reply, I've been away from email for several days]

This would not fix the compilation errors, since compat/win32/sys/poll.c
does not include the git-compat-util.h header file (and I *don't* think
it should). ;-)

ATB,
Ramsay Jones

```

## Ramsay Jones, 2010-12-08 00:18

Subject: Re: [PATCH 01/14] msvc: Fix compilation errors in compat/win32/sys/poll.c
Message-ID: <4CFECEBB.7060703@ramsay1.demon.co.uk>
URL: https://gitlist.dev/e/4CFECEBB.7060703%40ramsay1.demon.co.uk
In-Reply-To: <201012042222.23384.j6t@kdbg.org>

```
Johannes Sixt wrote:
> On Samstag, 4. Dezember 2010, Ramsay Jones wrote:
>> diff --git a/compat/win32/sys/poll.c b/compat/win32/sys/poll.c
>> index 7e74ebe..708a6c9 100644
>> --- a/compat/win32/sys/poll.c
>> +++ b/compat/win32/sys/poll.c
>> @@ -34,6 +34,9 @@
>>
>>  #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
>>  # define WIN32_NATIVE
>> +# if defined (_MSC_VER)
>> +#  define _WIN32_WINNT 0x0502
>> +# endif
>>  # include <winsock2.h>
>>  # include <windows.h>
>>  # include <io.h>
> 
> Don't you have to do the same in git-compat-util.h?

No. compat/win32/sys/poll.c doesn't include git-compat-util.h (and I
don't think it should), so adding it there would not solve the immediate
problem. Also, I don't see any reason to restrict the API used by both
MinGW and msvc in other parts of git.

ATB,
Ramsay Jones

```

## Johannes Sixt, 2010-12-08 19:42

Subject: Re: [PATCH 01/14] msvc: Fix compilation errors in compat/win32/sys/poll.c
Message-ID: <201012082042.06935.j6t@kdbg.org>
URL: https://gitlist.dev/e/201012082042.06935.j6t%40kdbg.org
In-Reply-To: <4CFECEBB.7060703@ramsay1.demon.co.uk>

```
On Mittwoch, 8. Dezember 2010, Ramsay Jones wrote:
> Johannes Sixt wrote:
> > On Samstag, 4. Dezember 2010, Ramsay Jones wrote:
> >> diff --git a/compat/win32/sys/poll.c b/compat/win32/sys/poll.c
> >> index 7e74ebe..708a6c9 100644
> >> --- a/compat/win32/sys/poll.c
> >> +++ b/compat/win32/sys/poll.c
> >> @@ -34,6 +34,9 @@
> >>
> >>  #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
> >>  # define WIN32_NATIVE
> >> +# if defined (_MSC_VER)
> >> +#  define _WIN32_WINNT 0x0502
> >> +# endif
> >>  # include <winsock2.h>
> >>  # include <windows.h>
> >>  # include <io.h>
> >
> > Don't you have to do the same in git-compat-util.h?
>
> No. compat/win32/sys/poll.c doesn't include git-compat-util.h (and I
> don't think it should),

I know and I agree.

> so adding it there would not solve the immediate 
> problem.

Didn't I say: "do the same..."? :-) So the question remains open. After all, 
by doing so, you would make sure that the rest of git sees the same API 
(struct definitions and #defined constants) as compat/win32/sys/poll.c, no?

-- Hannes

```

## Johannes Sixt, 2010-12-11 22:09

Subject: Re: [PATCH 01/14] msvc: Fix compilation errors in compat/win32/sys/poll.c
Message-ID: <201012112309.51102.j6t@kdbg.org>
URL: https://gitlist.dev/e/201012112309.51102.j6t%40kdbg.org
In-Reply-To: <4D039E73.80301@ramsay1.demon.co.uk>

```
On Samstag, 11. Dezember 2010, Ramsay Jones wrote:
> Before sending the patch, I generated a
> before and after pre-processor file and spent about 2-3 hours using tkdiff,
> vim, grep etc., to try and determine if it was a "safe" change.

Thanks. This dispels my concerns.

-- Hannes

```
