# [PATCH] Windows: Do not redefine _WIN32_WINNT

5 messages from 2013-09-11 to 2013-09-12. Participants: Sebastian Schuberth, Junio C Hamano.
Thread: https://gitlist.dev/t/34908

## Sebastian Schuberth, 2013-09-11 16:06

Subject: [PATCH] Windows: Do not redefine _WIN32_WINNT
Message-ID: <52309507.1090908@gmail.com>
URL: https://gitlist.dev/e/52309507.1090908%40gmail.com

```
With MinGW runtime version 4.0 this interferes with the previous definition
from sdkddkver.h.

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
---
 compat/nedmalloc/malloc.c.h | 2 ++
 git-compat-util.h           | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/compat/nedmalloc/malloc.c.h b/compat/nedmalloc/malloc.c.h
index 1401a67..930d03b 100644
--- a/compat/nedmalloc/malloc.c.h
+++ b/compat/nedmalloc/malloc.c.h
@@ -495,7 +495,9 @@ MAX_RELEASE_CHECK_RATE   default: 4095 unless not HAVE_MMAP
 #endif  /* WIN32 */
 #ifdef WIN32
 #define WIN32_LEAN_AND_MEAN
+#ifndef _WIN32_WINNT
 #define _WIN32_WINNT 0x403
+#endif
 #include <windows.h>
 #define HAVE_MMAP 1
 #define HAVE_MORECORE 0
diff --git a/git-compat-util.h b/git-compat-util.h
index 664305c..f5c756d 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -93,7 +93,9 @@
 #undef __NO_INLINE__
 
 #ifdef WIN32 /* Both MinGW and MSVC */
+#ifndef _WIN32_WINNT
 #define _WIN32_WINNT 0x0502
+#endif
 #define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */
 #include <winsock2.h>
 #include <windows.h>
-- 
1.8.3.mingw.1.2.g56240b5.dirty

```

## Junio C Hamano, 2013-09-11 18:29

Subject: Re: [PATCH] Windows: Do not redefine _WIN32_WINNT
Message-ID: <xmqq4n9rtdol.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqq4n9rtdol.fsf%40gitster.dls.corp.google.com
In-Reply-To: <52309507.1090908@gmail.com>

```
Sebastian Schuberth <sschuberth@gmail.com> writes:

> diff --git a/git-compat-util.h b/git-compat-util.h
> index 664305c..f5c756d 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -93,7 +93,9 @@
>  #undef __NO_INLINE__
>  
>  #ifdef WIN32 /* Both MinGW and MSVC */
> +#ifndef _WIN32_WINNT
>  #define _WIN32_WINNT 0x0502
> +#endif
>  #define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */
>  #include <winsock2.h>
>  #include <windows.h>

This unfortunately does not seem to match what I have. I think the
patch is based on the codebase before these two:

 380395d0 (mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE, 2013-05-02)
 41f29991 (msvc: Fix compilation errors caused by poll.h emulation, 2013-01-31)

I could of course wiggle it in, if you want, but I wanted to know
what is going on.  Is it a pre-release freeze period on your side or
something?

```

## Sebastian Schuberth, 2013-09-11 20:03

Subject: Re: [PATCH] Windows: Do not redefine _WIN32_WINNT
Message-ID: <CAHGBnuPdixkH42SNW0enF8C-GFwH8gX8NOXb69VscV3qvA6bxg@mail.gmail.com>
URL: https://gitlist.dev/e/CAHGBnuPdixkH42SNW0enF8C-GFwH8gX8NOXb69VscV3qvA6bxg%40mail.gmail.com
In-Reply-To: <xmqq4n9rtdol.fsf@gitster.dls.corp.google.com>

```
On Wed, Sep 11, 2013 at 8:29 PM, Junio C Hamano <gitster@pobox.com> wrote:

> This unfortunately does not seem to match what I have. I think the
> patch is based on the codebase before these two:
>
>  380395d0 (mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE, 2013-05-02)
>  41f29991 (msvc: Fix compilation errors caused by poll.h emulation, 2013-01-31)
>
> I could of course wiggle it in, if you want, but I wanted to know
> what is going on.  Is it a pre-release freeze period on your side or
> something?

That's right, I currently have a code freeze at Git 1.8.3 because I
need to solve several other issues with Git 1.8.4 on Windows first.
I'd be grateful if you could "wiggle it in".

-- 
Sebastian Schuberth

```

## Junio C Hamano, 2013-09-11 21:51

Subject: Re: [PATCH] Windows: Do not redefine _WIN32_WINNT
Message-ID: <xmqq61u7rpr3.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqq61u7rpr3.fsf%40gitster.dls.corp.google.com
In-Reply-To: <CAHGBnuPdixkH42SNW0enF8C-GFwH8gX8NOXb69VscV3qvA6bxg@mail.gmail.com>

```
Sebastian Schuberth <sschuberth@gmail.com> writes:

> On Wed, Sep 11, 2013 at 8:29 PM, Junio C Hamano <gitster@pobox.com> wrote:
>
>> This unfortunately does not seem to match what I have. I think the
>> patch is based on the codebase before these two:
>>
>>  380395d0 (mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE, 2013-05-02)
>>  41f29991 (msvc: Fix compilation errors caused by poll.h emulation, 2013-01-31)
>>
>> I could of course wiggle it in, if you want, but I wanted to know
>> what is going on.  Is it a pre-release freeze period on your side or
>> something?
>
> That's right, I currently have a code freeze at Git 1.8.3 because I
> need to solve several other issues with Git 1.8.4 on Windows first.
> I'd be grateful if you could "wiggle it in".

It seems that compat/poll/poll.c also defines _WIN32_WINNT (but only
with _MSC_VER defined).  The change to git-compat-util.h in this
patch avoids redefinition for both MinGW and MSVC case.  Do you also
need to have this, too?

Here is what I tentatively queued on top of the three from Karsten,
and your "Fix stat definitions".

-- >8 --
From: Sebastian Schuberth <sschuberth@gmail.com>
Date: Wed, 11 Sep 2013 18:06:31 +0200
Subject: [PATCH] Windows: do not redefine _WIN32_WINNT

With MinGW runtime version 4.0 this interferes with the previous
definition from sdkddkver.h.

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 compat/nedmalloc/malloc.c.h | 2 ++
 compat/poll/poll.c          | 2 +-
 git-compat-util.h           | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/compat/nedmalloc/malloc.c.h b/compat/nedmalloc/malloc.c.h
index ed4f1fa..f216a2a 100644
--- a/compat/nedmalloc/malloc.c.h
+++ b/compat/nedmalloc/malloc.c.h
@@ -499,7 +499,9 @@ MAX_RELEASE_CHECK_RATE   default: 4095 unless not HAVE_MMAP
 #endif  /* WIN32 */
 #ifdef WIN32
 #define WIN32_LEAN_AND_MEAN
+#ifndef _WIN32_WINNT
 #define _WIN32_WINNT 0x403
+#endif
 #include <windows.h>
 #define HAVE_MMAP 1
 #define HAVE_MORECORE 0
diff --git a/compat/poll/poll.c b/compat/poll/poll.c
index 4410310..31163f2 100644
--- a/compat/poll/poll.c
+++ b/compat/poll/poll.c
@@ -39,7 +39,7 @@
 
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 # define WIN32_NATIVE
-# if defined (_MSC_VER)
+# if defined (_MSC_VER) && !defined(_WIN32_WINNT)
 #  define _WIN32_WINNT 0x0502
 # endif
 # include <winsock2.h>
diff --git a/git-compat-util.h b/git-compat-util.h
index 9549de6..7776f12 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -86,7 +86,7 @@
 #define _SGI_SOURCE 1
 
 #if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */
-# if defined (_MSC_VER)
+# if defined (_MSC_VER) && !defined(_WIN32_WINNT)
 #  define _WIN32_WINNT 0x0502
 # endif
 #define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */
-- 
1.8.4-469-g57f7e3a

```

## Sebastian Schuberth, 2013-09-12 08:41

Subject: Re: [PATCH] Windows: Do not redefine _WIN32_WINNT
Message-ID: <CAHGBnuPXPrpfdQYuwHz-AhLWcY3fx7KoWQ9L+RRz9hPnoQL4Dg@mail.gmail.com>
URL: https://gitlist.dev/e/CAHGBnuPXPrpfdQYuwHz-AhLWcY3fx7KoWQ9L%2BRRz9hPnoQL4Dg%40mail.gmail.com
In-Reply-To: <xmqq61u7rpr3.fsf@gitster.dls.corp.google.com>

```
On Wed, Sep 11, 2013 at 11:51 PM, Junio C Hamano <gitster@pobox.com> wrote:

> It seems that compat/poll/poll.c also defines _WIN32_WINNT (but only
> with _MSC_VER defined).  The change to git-compat-util.h in this
> patch avoids redefinition for both MinGW and MSVC case.  Do you also
> need to have this, too?

In my patch I did not change poll.c because I did only check this
issue with MinGW, not MSVC, so I never ran into the _MSC_VER code
path. Back in 1.8.3 git-compat-util.h did define _WIN32_WINNT for both
MinGW and MSVC, which is why in my patch I had to add the #ifndef /
#endif. But I believe it's good to have these guards for both MinGW
and MSVC, actually.

> Here is what I tentatively queued on top of the three from Karsten,
> and your "Fix stat definitions".

Looks good to me, thanks!

-- 
Sebastian Schuberth

```
