# [PATCH 1/5] msvc: Fix compilation errors caused by poll.h emulation

4 messages from 2013-01-31 to 2013-05-09. Participants: Ramsay Jones, Sven Strickroth.
Thread: https://gitlist.dev/t/32797

## Ramsay Jones, 2013-01-31 18:28

Subject: [PATCH 1/5] msvc: Fix compilation errors caused by poll.h emulation
Message-ID: <510AB7D3.7010407@ramsay1.demon.co.uk>
URL: https://gitlist.dev/e/510AB7D3.7010407%40ramsay1.demon.co.uk

```

Commit 0f77dea9 ("mingw: move poll out of sys-folder", 24-10-2011), along
with other commits in the 'ef/mingw-upload-archive' branch (see commit
7406aa20), effectively reintroduced the same problem addressed by commit
56fb3ddc ("msvc: Fix compilation errors in compat/win32/sys/poll.c",
04-12-2010).

In order to fix the compilation errors, we use the same solution adopted
in that earlier commit. In particular, we set _WIN32_WINNT to 0x0502
(which would target Windows Server 2003) prior to including the winsock2.h
header file.

Also, we delete the compat/vcbuild/include/sys/poll.h header file, since
it is now redundant and it's presence may cause some confusion.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 compat/vcbuild/include/sys/poll.h | 1 -
 git-compat-util.h                 | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)
 delete mode 100644 compat/vcbuild/include/sys/poll.h

diff --git a/compat/vcbuild/include/sys/poll.h b/compat/vcbuild/include/sys/poll.h
deleted file mode 100644
index 0d8552a..0000000
--- a/compat/vcbuild/include/sys/poll.h
+++ /dev/null
@@ -1 +0,0 @@
-/* Intentionally empty file to support building git with MSVC */
diff --git a/git-compat-util.h b/git-compat-util.h
index cc2abee..204cb1e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -86,6 +86,9 @@
 #define _SGI_SOURCE 1
 
 #ifdef WIN32 /* Both MinGW and MSVC */
+# if defined (_MSC_VER)
+#  define _WIN32_WINNT 0x0502
+# endif
 #define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */
 #include <winsock2.h>
 #include <windows.h>
-- 
1.8.1

```

## Sven Strickroth, 2013-05-09 01:42

Subject: Re: [PATCH 1/5] msvc: Fix compilation errors caused by poll.h emulation
Message-ID: <518AFEFC.8010904@cs-ware.de>
URL: https://gitlist.dev/e/518AFEFC.8010904%40cs-ware.de
In-Reply-To: <510AB7D3.7010407@ramsay1.demon.co.uk>

```
Am 31.01.2013 19:28 schrieb Ramsay Jones:
> Commit 0f77dea9 ("mingw: move poll out of sys-folder", 24-10-2011), along
> with other commits in the 'ef/mingw-upload-archive' branch (see commit
> 7406aa20), effectively reintroduced the same problem addressed by commit
> 56fb3ddc ("msvc: Fix compilation errors in compat/win32/sys/poll.c",
> 04-12-2010).
> 
> In order to fix the compilation errors, we use the same solution adopted
> in that earlier commit. In particular, we set _WIN32_WINNT to 0x0502
> (which would target Windows Server 2003) prior to including the winsock2.h
> header file.

This change causes problems compiling with MSVC2012 for me. If I don't
define NO_SYS_POLL_H git-compat-util.h now tries to include <sys/poll.h>
which does not exist for MSVC and if I define NO_SYS_POLL_H
git-compat-util.h now tries to include <poll.h> which also doesn't exist
for MSVC.

Including compat/poll into the includes path causes redefinition errors.

How have you tested this?

I think the check in git-compat-util.h has to be extended to only
include any poll.h if _MSC_VER is defined.

-- 
Best regards,
 Sven Strickroth
 PGP key id F5A9D4C4 @ any key-server

```

## Ramsay Jones, 2013-05-09 20:35

Subject: Re: [PATCH 1/5] msvc: Fix compilation errors caused by poll.h emulation
Message-ID: <518C0890.9050508@ramsay1.demon.co.uk>
URL: https://gitlist.dev/e/518C0890.9050508%40ramsay1.demon.co.uk
In-Reply-To: <518AFEFC.8010904@cs-ware.de>

```
Sven Strickroth wrote:
> Am 31.01.2013 19:28 schrieb Ramsay Jones:
>> Commit 0f77dea9 ("mingw: move poll out of sys-folder", 24-10-2011), along
>> with other commits in the 'ef/mingw-upload-archive' branch (see commit
>> 7406aa20), effectively reintroduced the same problem addressed by commit
>> 56fb3ddc ("msvc: Fix compilation errors in compat/win32/sys/poll.c",
>> 04-12-2010).
>>
>> In order to fix the compilation errors, we use the same solution adopted
>> in that earlier commit. In particular, we set _WIN32_WINNT to 0x0502
>> (which would target Windows Server 2003) prior to including the winsock2.h
>> header file.
> 
> This change causes problems compiling with MSVC2012 for me. If I don't
> define NO_SYS_POLL_H git-compat-util.h now tries to include <sys/poll.h>
> which does not exist for MSVC and if I define NO_SYS_POLL_H
> git-compat-util.h now tries to include <poll.h> which also doesn't exist
> for MSVC.
> 
> Including compat/poll into the includes path causes redefinition errors.
> 
> How have you tested this?

I used the Makefile, with the Visual C++ 2008 command line compiler on
Windows XP (SP3), to build a vanilla git on MinGW.
Viz:

    ramsay (pu) ms $ git checkout master
    Switched to branch 'master'
    ramsay (master) ms $ git rev-parse master
    423ecb0bb66e9d60b6667aebc2844e82205369a1
    ramsay (master) ms $ make clean >/dev/null 2>&1
    ramsay (master) ms $ make >ms-out1 2>&1
    ramsay (master) ms $ grep error ms-out1
    ramsay (master) ms $ ./git version
    git version 1.8.3.rc1.25.g423ecb0.MSVC
    ramsay (master) ms $

Also

    ramsay (tmp) ms $ rm git.o
    ramsay (tmp) ms $ make V=1 git.o
    compat/vcbuild/scripts/clink.pl -o git.o -c    -nologo -I. -I../zlib -Icompat/vc
    build -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_
    NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -GL -Os -MT -DNO_CURL -DNO_ST_BLOCKS_IN_
    STRUCT_STAT -DNO_NSEC -DNO_SYMLINK_HEAD -DNO_GETTEXT -DNO_SYS_POLL_H -DNO_THREAD
    _SAFE_PREAD -DNO_IPV6 -DNO_INET_NTOP -DNO_INET_PTON -DNO_ICONV -DNO_POSIX_GOODIE
    S  -DUNRELIABLE_FSTAT -DSHA1_HEADER='"block-sha1/sha1.h"' -D__USE_MINGW_ACCESS -
    DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -D
    STRIP_EXTENSION=\".exe\" -DNO_LIBGEN_H -DSNPRINTF_RETURNS_BOGUS -DNO_POLL -Icomp
    at/poll -DNO_STRCASESTR -DNO_STRLCPY -DNO_STRTOUMAX -Icompat/fnmatch -DNO_FNMATC
    H -DNO_SETENV -DNO_MKDTEMP -DNO_MKSTEMPS -DNO_UNSETENV -DUSE_WIN32_MMAP -DOBJECT
    _CREATION_MODE=1 -DNO_PREAD -DNO_MEMMEM -DRUNTIME_PREFIX -Icompat/regex -DSHELL_
    PATH='"/bin/sh"' -DDEFAULT_HELP_FORMAT='"html"' '-DGIT_HTML_PATH="share/doc/git-
    doc"' '-DGIT_MAN_PATH="share/man"' '-DGIT_INFO_PATH="share/info"' git.c
    git.c
    git.c(204) : warning C4090: 'function' : different 'const' qualifiers
    git.c(218) : warning C4090: 'function' : different 'const' qualifiers
    git.c(221) : warning C4090: 'function' : different 'const' qualifiers
    ramsay (tmp) ms $

Note that '-Icompat/poll' is passed on the command-line (it is split at -Icomp
above), which comes from:

    ramsay (tmp) ms $ git grep -n 'compat/poll'
    Makefile:647:LIB_H += compat/poll/poll.h
    Makefile:1235:  COMPAT_CFLAGS += -DNO_POLL -Icompat/poll
    Makefile:1236:  COMPAT_OBJS += compat/poll/poll.o
    ramsay (tmp) ms $

I have a patch which allows me to generate the preprocessed output file
and, after running it on git.c (=> git.i), I can see that msvc reads the
compat/poll/poll.h file. (from line 128 of git-compat-util.h).

Are you using a MSVC "project" file? If so, is it equivalent to the Makefile?
Has the "#include" behaviour changed between MSVC 2008 -> MSVC 2012?

ATB,
Ramsay Jones

```

## Sven Strickroth, 2013-05-09 21:12

Subject: Re: [PATCH 1/5] msvc: Fix compilation errors caused by poll.h emulation
Message-ID: <518C113C.3080106@cs-ware.de>
URL: https://gitlist.dev/e/518C113C.3080106%40cs-ware.de
In-Reply-To: <518C0890.9050508@ramsay1.demon.co.uk>

```
Am 09.05.2013 22:35 schrieb Ramsay Jones:
> Note that '-Icompat/poll' is passed on the command-line (it is split at -Icomp
> above), which comes from:
> 
>     ramsay (tmp) ms $ git grep -n 'compat/poll'
>     Makefile:647:LIB_H += compat/poll/poll.h
>     Makefile:1235:  COMPAT_CFLAGS += -DNO_POLL -Icompat/poll
>     Makefile:1236:  COMPAT_OBJS += compat/poll/poll.o
>     ramsay (tmp) ms $
> 
> I have a patch which allows me to generate the preprocessed output file
> and, after running it on git.c (=> git.i), I can see that msvc reads the
> compat/poll/poll.h file. (from line 128 of git-compat-util.h).
> 
> Are you using a MSVC "project" file? If so, is it equivalent to the Makefile?
> Has the "#include" behaviour changed between MSVC 2008 -> MSVC 2012?

Thank you for your explanation. The problem for me was, that
_WIN32_WINNT was set to 0x0600 and thus winsck2.h was also declaring pollfd.

Building libgit works now.

-- 
Best regards,
 Sven Strickroth
 PGP key id F5A9D4C4 @ any key-server

```
