{"thread":{"id":"34499","subject":"[PATCH] Fix compilation on OS X.","startedAt":"2013-07-20T07:49:27Z","lastAt":"2013-07-21T22:09:44Z","messageCount":10,"participants":["Benoit Sigoure","Ramkumar Ramachandra","tsuna","Torsten Bögershausen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"223826","messageId":"1374306567-16640-1-git-send-email-tsunanet@gmail.com","threadId":"34499","inReplyTo":null,"subject":"[PATCH] Fix compilation on OS X.","fromName":"Benoit Sigoure","fromEmail":"tsunanet@gmail.com","sentAt":"2013-07-20T07:49:27Z","receivedAt":"2013-07-20T07:49:27Z","isPatch":true,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"On OS X libc headers don't define `environ', and since ec535cc2 removed\nthe redundant declaration this code no longer builds on OS X.\n---\n compat/unsetenv.c | 5 +++++\n 1 file changed, 5 insertions(+)\n\ndiff --git a/compat/unsetenv.c b/compat/unsetenv.c\nindex 4ea1856..addf3dc 100644\n--- a/compat/unsetenv.c\n+++ b/compat/unsetenv.c\n@@ -1,5 +1,10 @@\n #include \"../git-compat-util.h\"\n \n+#ifdef __APPLE__\n+// On OS X libc headers don't define this symbol.\n+extern char **environ;\n+#endif\n+\n void gitunsetenv (const char *name)\n {\n      int src, dst;\n-- \n1.8.2.1.539.g4196a96\n"},{"id":"223827","messageId":"CALkWK0m46SR3C6R_pjYouu7LkHjL_gPGb1A3S94d0nx8227-UA@mail.gmail.com","threadId":"34499","inReplyTo":"1374306567-16640-1-git-send-email-tsunanet@gmail.com","subject":"Re: [PATCH] Fix compilation on OS X.","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-07-20T07:55:09Z","receivedAt":"2013-07-20T07:55:09Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Benoit Sigoure wrote:\n> diff --git a/compat/unsetenv.c b/compat/unsetenv.c\n> index 4ea1856..addf3dc 100644\n> --- a/compat/unsetenv.c\n> +++ b/compat/unsetenv.c\n> @@ -1,5 +1,10 @@\n>  #include \"../git-compat-util.h\"\n>\n> +#ifdef __APPLE__\n> +// On OS X libc headers don't define this symbol.\n> +extern char **environ;\n> +#endif\n> +\n\nShouldn't this go into git-compat-util.h, since there may be other\nfiles depending on this variable?\n"},{"id":"223828","messageId":"CAFKYj4fdYHKukM7kaxxTKYNqTfOXadmZynTxXO9824G6H6HiZA@mail.gmail.com","threadId":"34499","inReplyTo":"CALkWK0m46SR3C6R_pjYouu7LkHjL_gPGb1A3S94d0nx8227-UA@mail.gmail.com","subject":"Re: [PATCH] Fix compilation on OS X.","fromName":"tsuna","fromEmail":"tsunanet@gmail.com","sentAt":"2013-07-20T07:56:40Z","receivedAt":"2013-07-20T07:56:40Z","isPatch":true,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"On Sat, Jul 20, 2013 at 12:55 AM, Ramkumar Ramachandra\n<artagnon@gmail.com> wrote:\n> Benoit Sigoure wrote:\n>> diff --git a/compat/unsetenv.c b/compat/unsetenv.c\n>> index 4ea1856..addf3dc 100644\n>> --- a/compat/unsetenv.c\n>> +++ b/compat/unsetenv.c\n>> @@ -1,5 +1,10 @@\n>>  #include \"../git-compat-util.h\"\n>>\n>> +#ifdef __APPLE__\n>> +// On OS X libc headers don't define this symbol.\n>> +extern char **environ;\n>> +#endif\n>> +\n>\n> Shouldn't this go into git-compat-util.h, since there may be other\n> files depending on this variable?\n\nI thought about that but there are no other files that use `environ'\nso I opted for putting it here instead.\n\n-- \nBenoit \"tsuna\" Sigoure\n"},{"id":"223846","messageId":"51EA7D58.3050800@web.de","threadId":"34499","inReplyTo":"1374306567-16640-1-git-send-email-tsunanet@gmail.com","subject":"Re: [PATCH] Fix compilation on OS X.","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2013-07-20T12:06:48Z","receivedAt":"2013-07-20T12:06:48Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On 2013-07-20 09.49, Benoit Sigoure wrote:\n> +#ifdef __APPLE__\n> +// On OS X libc headers don't define this symbol.\n> +extern char **environ;\n> +#endif\n> +\nA more generic approach could be:\n\nIn the file \"config.mak.uname\": Define a variable in the Darwin section like this\nNO_EXT_ENVIRON = UnfortunatelyYes\n\nIn \"Makefile\", pick it up, and convert it into a compiler option:\nifdef NO_EXT_ENVIRON\n\tBASIC_CFLAGS += -DNO_EXT_ENVIRON\nendif\n\nAnd in \"git-compat-util.h\", add these lines \"at a good place\":\n#ifdef NO_EXT_ENVIRON\nextern char **environ;\n#endif\n\nThis will allow other OS to use the NO_EXT_ENVIRON when needed,.\n\nThanks for working on this.\n/Torsten\n"},{"id":"223851","messageId":"1374345691-21834-1-git-send-email-tsunanet@gmail.com","threadId":"34499","inReplyTo":"51EA7D58.3050800@web.de","subject":"[PATCH] Fix compilation on OS X.","fromName":"Benoit Sigoure","fromEmail":"tsunanet@gmail.com","sentAt":"2013-07-20T18:41:31Z","receivedAt":"2013-07-20T18:41:31Z","isPatch":true,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"On OS X libc headers don't define `environ', and since ec535cc2 removed\nthe redundant declaration this code no longer builds on OS X.\n---\n Makefile          | 5 +++++\n config.mak.uname  | 1 +\n git-compat-util.h | 4 ++++\n 3 files changed, 10 insertions(+)\n\ndiff --git a/Makefile b/Makefile\nindex 0600eb4..774db18 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -98,6 +98,8 @@ all::\n #\n # Define NO_UNSETENV if you don't have unsetenv in the C library.\n #\n+# Define NO_EXT_ENVIRON if your C library doesn't define `environ'.\n+#\n # Define NO_MKDTEMP if you don't have mkdtemp in the C library.\n #\n # Define MKDIR_WO_TRAILING_SLASH if your mkdir() can't deal with trailing slash.\n@@ -1307,6 +1309,9 @@ ifdef NO_UNSETENV\n \tCOMPAT_CFLAGS += -DNO_UNSETENV\n \tCOMPAT_OBJS += compat/unsetenv.o\n endif\n+ifdef NO_EXT_ENVIRON\n+\tCOMPAT_CFLAGS += -DNO_EXT_ENVIRON\n+endif\n ifdef NO_SYS_SELECT_H\n \tBASIC_CFLAGS += -DNO_SYS_SELECT_H\n endif\ndiff --git a/config.mak.uname b/config.mak.uname\nindex 7ac541e..ebcfbfd 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -93,6 +93,7 @@ ifeq ($(uname_S),Darwin)\n \t\tNO_STRLCPY = YesPlease\n \tendif\n \tNO_MEMMEM = YesPlease\n+        NO_EXT_ENVIRON = UnfortunatelyYes\n \tUSE_ST_TIMESPEC = YesPlease\n \tHAVE_DEV_TTY = YesPlease\n \tNEEDS_CLIPPED_WRITE = YesPlease\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex ff193f4..3bac4e9 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -408,6 +408,10 @@ extern ssize_t git_pread(int fd, void *buf, size_t count, off_t offset);\n  */\n extern ssize_t read_in_full(int fd, void *buf, size_t count);\n \n+#ifdef NO_EXT_ENVIRON\n+extern char **environ;\n+#endif\n+\n #ifdef NO_SETENV\n #define setenv gitsetenv\n extern int gitsetenv(const char *, const char *, int);\n-- \n1.8.2.1.539.g4196a96\n"},{"id":"223863","messageId":"7vr4essbkv.fsf@alter.siamese.dyndns.org","threadId":"34499","inReplyTo":"51EA7D58.3050800@web.de","subject":"Re: [PATCH] Fix compilation on OS X.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-21T05:53:36Z","receivedAt":"2013-07-21T05:53:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Torsten Bögershausen <tboegi@web.de> writes:\n\n> On 2013-07-20 09.49, Benoit Sigoure wrote:\n>> +#ifdef __APPLE__\n>> +// On OS X libc headers don't define this symbol.\n>> +extern char **environ;\n>> +#endif\n>> +\n> A more generic approach could be:\n>\n> In the file \"config.mak.uname\": Define a variable in the Darwin section like this\n> NO_EXT_ENVIRON = UnfortunatelyYes\n\nActually, it is _wrong_ for us to rely on system header files to\ndefine this symbol for us.  Declaring \"extern char **environ\" is\nresponsibility of the user programs (like us).\n\nWhen _GNU_SOURCE is defined glibc header (I think it is unistd.h)\nseem to define it for us.\n\nPerhaps the correct fix is to revert ec535cc2 for everybody, and if\nMinGW needs such a workaround, do it inside #ifndef MINGW?\n"},{"id":"223864","messageId":"CAFKYj4dRFvTwM_x0mXsOLQCTuw9nAvh3b4bZ+Omg7M5DVNnVzA@mail.gmail.com","threadId":"34499","inReplyTo":"7vr4essbkv.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Fix compilation on OS X.","fromName":"tsuna","fromEmail":"tsunanet@gmail.com","sentAt":"2013-07-21T06:10:12Z","receivedAt":"2013-07-21T06:10:12Z","isPatch":true,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"On Sat, Jul 20, 2013 at 10:53 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Actually, it is _wrong_ for us to rely on system header files to\n> define this symbol for us.  Declaring \"extern char **environ\" is\n> responsibility of the user programs (like us).\n\nActually, that's right.  The C99 standard doesn't mention anything\nabout `environ' (only 7.20.4.5 defines `getenv') and POSIX explicitly\nstates \"the [environ] variable, which must be declared by the user if\nit is to be used directly\"\n(http://pubs.opengroup.org/onlinepubs/9699919799/functions/environ.html)\n\n> When _GNU_SOURCE is defined glibc header (I think it is unistd.h)\n> seem to define it for us.\n>\n> Perhaps the correct fix is to revert ec535cc2 for everybody, and if\n> MinGW needs such a workaround, do it inside #ifndef MINGW?\n\nThat sounds right.\n\n-- \nBenoit \"tsuna\" Sigoure\n"},{"id":"223865","messageId":"1374387454-27800-1-git-send-email-tsunanet@gmail.com","threadId":"34499","inReplyTo":"7vr4essbkv.fsf@alter.siamese.dyndns.org","subject":"[PATCH] Revert \"compat/unsetenv.c: Fix a sparse warning\"","fromName":"Benoit Sigoure","fromEmail":"tsunanet@gmail.com","sentAt":"2013-07-21T06:17:34Z","receivedAt":"2013-07-21T06:17:34Z","isPatch":true,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"This reverts commit ec535cc27e6c4f5e0b1d157e04f5511f166ecd9d.\n\nPOSIX explicitly states \"the [environ] variable, which\nmust be declared by the user if it is to be used directly\".\nNot declaring it causes compilation to fail on OS X.\n\nInstead don't declare the variable on MinGW, as it causes\na spurious warning there.\n---\n compat/unsetenv.c | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/compat/unsetenv.c b/compat/unsetenv.c\nindex 4ea1856..bf5fd70 100644\n--- a/compat/unsetenv.c\n+++ b/compat/unsetenv.c\n@@ -2,6 +2,9 @@\n \n void gitunsetenv (const char *name)\n {\n+#if !defined(__MINGW32__)\n+     extern char **environ;\n+#endif\n      int src, dst;\n      size_t nmln;\n \n-- \n1.8.2.1.539.g4196a96\n"},{"id":"223887","messageId":"1374436448-8199-1-git-send-email-tsunanet@gmail.com","threadId":"34499","inReplyTo":"1374387454-27800-1-git-send-email-tsunanet@gmail.com","subject":"[PATCH] Revert \"compat/unsetenv.c: Fix a sparse warning\"","fromName":"Benoit Sigoure","fromEmail":"tsunanet@gmail.com","sentAt":"2013-07-21T19:54:08Z","receivedAt":"2013-07-21T19:54:08Z","isPatch":true,"sender":{"key":"tsunanet@gmail.com","avatar":"https://avatars.githubusercontent.com/u/128281?v=4"},"body":"This reverts commit ec535cc27e6c4f5e0b1d157e04f5511f166ecd9d.\n\nPOSIX explicitly states \"the [environ] variable, which\nmust be declared by the user if it is to be used directly\".\nNot declaring it causes compilation to fail on OS X.\n\nInstead don't declare the variable on MinGW, as it causes\na spurious warning there.\n\nSigned-off-by: Benoit Sigoure <tsunanet@gmail.com>\n---\n\nResending as I forgot to Sign-off the previous patch.\n\n compat/unsetenv.c | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/compat/unsetenv.c b/compat/unsetenv.c\nindex 4ea1856..bf5fd70 100644\n--- a/compat/unsetenv.c\n+++ b/compat/unsetenv.c\n@@ -2,6 +2,9 @@\n \n void gitunsetenv (const char *name)\n {\n+#if !defined(__MINGW32__)\n+     extern char **environ;\n+#endif\n      int src, dst;\n      size_t nmln;\n \n-- \n1.8.2.1.539.g4196a96\n"},{"id":"223892","messageId":"7v38r7sgyf.fsf@alter.siamese.dyndns.org","threadId":"34499","inReplyTo":"1374436448-8199-1-git-send-email-tsunanet@gmail.com","subject":"Re: [PATCH] Revert \"compat/unsetenv.c: Fix a sparse warning\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-21T22:09:44Z","receivedAt":"2013-07-21T22:09:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Benoit Sigoure <tsunanet@gmail.com> writes:\n\n> This reverts commit ec535cc27e6c4f5e0b1d157e04f5511f166ecd9d.\n>\n> POSIX explicitly states \"the [environ] variable, which\n> must be declared by the user if it is to be used directly\".\n> Not declaring it causes compilation to fail on OS X.\n>\n> Instead don't declare the variable on MinGW, as it causes\n> a spurious warning there.\n>\n> Signed-off-by: Benoit Sigoure <tsunanet@gmail.com>\n\nThanks, will queue.\n\n> ---\n>\n> Resending as I forgot to Sign-off the previous patch.\n>\n>  compat/unsetenv.c | 3 +++\n>  1 file changed, 3 insertions(+)\n>\n> diff --git a/compat/unsetenv.c b/compat/unsetenv.c\n> index 4ea1856..bf5fd70 100644\n> --- a/compat/unsetenv.c\n> +++ b/compat/unsetenv.c\n> @@ -2,6 +2,9 @@\n>  \n>  void gitunsetenv (const char *name)\n>  {\n> +#if !defined(__MINGW32__)\n> +     extern char **environ;\n> +#endif\n>       int src, dst;\n>       size_t nmln;\n"}]}