Skip to contentSkip to conversation

msvc: Fix compilation errors in compat/win32/sys/poll.c

PATCH In review Ramsay Jones 4 participants 8 messages Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/14 msvc: Fix compilation errors in compat/win32/sys/poll.c

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.

---
 compat/win32/sys/poll.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
compat/win32/sys/poll.c +3 -0
index 7e74ebe..708a6c9 100644
@@ -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>
Signature · 1 line
1.7.3
#1 lore raw
Quoted 5 lines · Ramsay Jones

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.

#2 lore raw
Quoted 10 lines · Jonathan Nieder

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
Quoted 2 lines

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

#3 lore raw
In reply to Ramsay Jones
Quoted 20 lines · Ramsay Jones

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.

---
 compat/win32/sys/poll.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
compat/win32/sys/poll.c +0 -0
index 7e74ebe..708a6c9 100644

compat/win32/sys/poll.c line 42

Quoted 9 lines
compat/win32/sys/poll.c +3 -0
@@ -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

#4 lore raw
Quoted 7 lines · Johannes Sixt
Quoted 6 lines · Ramsay Jones
compat/win32/sys/poll.c +0 -0
index 7e74ebe..708a6c9 100644
@@ -34,6 +34,9 @@
 
Quoted 10 lines

compat/win32/sys/poll.c line 42

Quoted 8 lines
compat/win32/sys/poll.c +3 -0
 #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

#5 lore raw
Quoted 19 lines · Ramsay Jones
Quoted 7 lines · Johannes Sixt
Quoted 6 lines · Ramsay Jones
compat/win32/sys/poll.c +0 -0
index 7e74ebe..708a6c9 100644
@@ -34,6 +34,9 @@
 
Quoted 10 lines

compat/win32/sys/poll.c line 42

Quoted 8 lines
compat/win32/sys/poll.c +3 -0
 #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?

Quoted 2 lines

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.

Quoted 2 lines

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 3 lines · Ramsay Jones

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

Acked-by on v1 1/14
#8 lore raw
In reply to Ramsay Jones
Quoted 21 lines · Ramsay Jones

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.

---
 compat/win32/sys/poll.c |    3 +++

 1 files changed, 3 insertions(+), 0 deletions(-)
compat/win32/sys/poll.c +0 -0
index 7e74ebe..708a6c9 100644

compat/win32/sys/poll.c line 42

Quoted 9 lines
compat/win32/sys/poll.c +3 -0
@@ -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: