threads / patch / 30298

patchFixed compilation with Visual Studio by including poll.h

Subject: [PATCH] Fixed compilation with Visual Studio by including poll.h

## tl;dr

6 messages between Apr 20, 2012 and Apr 20, 2012. Diffs are folded; open one to read it.

replies: 5people: 4as markdown or json

Sven Strickroth· Apr 20, 2012, 20:37 UTC · lore

upload-archive.c and upload-pack.c use pollfd struct and POLLIN constant which are defined in poll.h. However, poll.h is not included.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
---
 builtin/upload-archive.c |    1 +
 upload-pack.c            |    1 +
 2 files changed, 2 insertions(+)
Show changes to 2 files +2 −0

builtin/upload-archive.c, upload-pack.c

diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index b928beb..6226bbb 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2006 Franck Bui-Huu
  */
+#include "poll.h"
 #include "cache.h"
 #include "builtin.h"
 #include "archive.h"
diff --git a/upload-pack.c b/upload-pack.c
index bb08e2e..79f9f8f 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1,3 +1,4 @@
+#include "poll.h"
 #include "cache.h"
 #include "refs.h"
 #include "pkt-line.h"
-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server
Jeff King· Apr 20, 2012, 20:47 UTC · re: Sven Strickroth · lore

Re: [PATCH] Fixed compilation with Visual Studio by including poll.h

On Fri, Apr 20, 2012 at 10:37:19PM +0200, Sven Strickroth wrote:
> upload-archive.c and upload-pack.c use pollfd struct and POLLIN constant
> which are defined in poll.h. However, poll.h is not included.
This should already be included by git-compat-util.h:
  $ grep -C1 poll.h git-compat-util.h
  #ifndef NO_SYS_POLL_H
  #include <sys/poll.h>
  #else
  #include <poll.h>
  #endif

It looks like we will prefer sys/poll.h if it exists. The official XSI location is "poll.h", but I guess in practice they are equivalent on most systems if you have both (certainly on Linux, poll.h just includes sys/poll.h).

Does your environments have a sys/poll.h that exists isn't sufficient to use poll? Maybe we need to tweak git-compat-util to include both if they both exist.

-Peff
Sven Strickroth· Apr 20, 2012, 21:26 UTC · re: Jeff King · lore

Re: [PATCH] Fixed compilation with Visual Studio by including poll.h

Windows does not have sys/poll.h. I have to use the one from compat/win32.
The problem is that
    NO_SYS_POLL_H
is defined in compat/msvc.h in my environment.
And in git-compat-util.h
    #ifndef NO_SYS_POLL_H
    #include <sys/poll.h>
    #else
    #include <poll.h>
    #endif
is before
    #elif defined(_MSC_VER)
    #include "compat/msvc.h"
. Moving it down, solves the issue for me. (Suppose this is a fix for my
scenario only).
Show changes to git-compat-util.h +5 −5
diff --git a/git-compat-util.h b/git-compat-util.h
index ed11ad8..a96849c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -111,11 +111,6 @@
 #include <regex.h>
 #include <utime.h>
 #include <syslog.h>
-#ifndef NO_SYS_POLL_H
-#include <sys/poll.h>
-#else
-#include <poll.h>
-#endif
 #if defined(__MINGW32__)
 /* pull in Windows compatibility stuff */
 #include "compat/mingw.h"
@@ -152,6 +147,11 @@
 #define _ALL_SOURCE 1
 #endif
 #endif
+#ifndef NO_SYS_POLL_H
+#include <sys/poll.h>
+#else
+#include <poll.h>
+#endif

 #ifndef NO_LIBGEN_H
 #include <libgen.h>
-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server
Erik Faye-Lund· Apr 20, 2012, 21:58 UTC · re: Sven Strickroth · lore

Re: [PATCH] Fixed compilation with Visual Studio by including poll.h

On Fri, Apr 20, 2012 at 11:26 PM, Sven Strickroth <sven.strickroth@tu-clausthal.de> wrote:

Show 17 quoted lines
> Windows does not have sys/poll.h. I have to use the one from compat/win32.
>
> The problem is that
>    NO_SYS_POLL_H
> is defined in compat/msvc.h in my environment.
> And in git-compat-util.h
>    #ifndef NO_SYS_POLL_H
>    #include <sys/poll.h>
>    #else
>    #include <poll.h>
>    #endif
> is before
>    #elif defined(_MSC_VER)
>    #include "compat/msvc.h"
> . Moving it down, solves the issue for me. (Suppose this is a fix for my
> scenario only).
>

NO_SYS_POLL_H shouldn't be defined in compat/msvc.h, it should be defined by the build-system. Our Makefile already does this inside the "ifeq ($(uname_S),Windows)"-block.

How are you building Git?
Junio C Hamano· Apr 20, 2012, 21:51 UTC · re: Jeff King · lore

Re: [PATCH] Fixed compilation with Visual Studio by including poll.h

Jeff King <peff@peff.net> writes:
Show 6 quoted lines
> On Fri, Apr 20, 2012 at 10:37:19PM +0200, Sven Strickroth wrote:
>
>> upload-archive.c and upload-pack.c use pollfd struct and POLLIN constant
>> which are defined in poll.h. However, poll.h is not included.
>
> This should already be included by git-compat-util.h:
Thanks for a bit of sanity.
Show 11 quoted lines
>   $ grep -C1 poll.h git-compat-util.h
>   #ifndef NO_SYS_POLL_H
>   #include <sys/poll.h>
>   #else
>   #include <poll.h>
>   #endif
>
> It looks like we will prefer sys/poll.h if it exists. The official XSI
> location is "poll.h", but I guess in practice they are equivalent on
> most systems if you have both (certainly on Linux, poll.h just includes
> sys/poll.h).

There actually is no preference between the two from _our_ side. It is up to the builder to know and define necessary make variables.

> Does your environments have a sys/poll.h that exists isn't sufficient to
> use poll? Maybe we need to tweak git-compat-util to include both if they
> both exist.

Both? I guess, but I suspect that on most sane systems one would include the other if there are both provided (iow, just so that you can complile sources written both for XSI and for systems in the field).

Jeff King· Apr 20, 2012, 23:23 UTC · re: Junio C Hamano · lore

Re: [PATCH] Fixed compilation with Visual Studio by including poll.h

On Fri, Apr 20, 2012 at 02:51:58PM -0700, Junio C Hamano wrote:
Show 7 quoted lines
> > It looks like we will prefer sys/poll.h if it exists. The official XSI
> > location is "poll.h", but I guess in practice they are equivalent on
> > most systems if you have both (certainly on Linux, poll.h just includes
> > sys/poll.h).
> 
> There actually is no preference between the two from _our_ side. It is
> up to the builder to know and define necessary make variables.

I say "prefer" only because if you set nothing, you get "sys/poll.h". So it is up to the builder to say "no, I do not have that non-standard location. Use the standard one instead". Which seems a little backwards.

Of course "standard" here is just what POSIX says; sys/poll.h may be much more standard in the real world (I don't know).

Show 7 quoted lines
> > Does your environments have a sys/poll.h that exists isn't sufficient to
> > use poll? Maybe we need to tweak git-compat-util to include both if they
> > both exist.
> 
> Both?  I guess, but I suspect that on most sane systems one would
> include the other if there are both provided (iow, just so that you can
> complile sources written both for XSI and for systems in the field).

I would think one or the other would be fine. But the fact that Sven's patch works makes me think that he has sys/poll.h, but it is not sufficient. Hopefully including "poll.h" would be enough, but it's not clear to me.

-Peff

← back to recent threads