{"thread":{"id":"45773","subject":"[PATCH] git_fopen: fix a sparse 'not declared' warning","startedAt":"2017-04-22T00:58:31Z","lastAt":"2017-04-24T01:37:30Z","messageCount":2,"participants":["Ramsay Jones","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"317529","messageId":"130ef8bd-1c7b-0206-e1cd-076afae7e292@ramsayjones.plus.com","threadId":"45773","inReplyTo":null,"subject":"[PATCH] git_fopen: fix a sparse 'not declared' warning","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2017-04-22T00:58:23Z","receivedAt":"2017-04-22T00:58:31Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nCommit 8f4f6e53d2 (\"config.mak.uname: set FREAD_READS_DIRECTORIES for\nLinux and FreeBSD\", 20-04-2017) caused sparse to issue a 'not declared,\nshould it be static?' warning on Linux. This is a result of the method\nemployed by 'compat/fopen.c' to suppress the (possible) redefinition of\nthe (system) fopen macro, which also removes the extern declaration of\nthe git_fopen function.\n\nIn order to suppress the warning, introduce a new macro to suppress the\ndefinition (or possibly the re-definition) of the fopen symbol as a\nmacro override. This new macro (SUPPRESS_FOPEN_REDEFINITION) is only\ndefined in 'compat/fopen.c', just prior to the inclusion of the\n'git-compat-util.h' header file.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n\nHi Duy,\n\nCould you (or Junio) please add this to your 'nd/fopen-errors' branch, either\nas a separate patch or squash it into commit 8f4f6e53d2 (\"config.mak.uname: set FREAD_READS_DIRECTORIES for Linux and FreeBSD\", 20-04-2017). I think it would\nbe better as a separate commit, but I will leave you to decide on that. ;-)\n\nThanks!\n\nATB,\nRamsay Jones\n\n compat/fopen.c    |  4 ++--\n git-compat-util.h | 10 ++++++----\n 2 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/compat/fopen.c b/compat/fopen.c\nindex b5ca142fe..107b3e818 100644\n--- a/compat/fopen.c\n+++ b/compat/fopen.c\n@@ -1,14 +1,14 @@\n /*\n  *  The order of the following two lines is important.\n  *\n- *  FREAD_READS_DIRECTORIES is undefined before including git-compat-util.h\n+ *  SUPPRESS_FOPEN_REDEFINITION is defined before including git-compat-util.h\n  *  to avoid the redefinition of fopen within git-compat-util.h. This is\n  *  necessary since fopen is a macro on some platforms which may be set\n  *  based on compiler options. For example, on AIX fopen is set to fopen64\n  *  when _LARGE_FILES is defined. The previous technique of merely undefining\n  *  fopen after including git-compat-util.h is inadequate in this case.\n  */\n-#undef FREAD_READS_DIRECTORIES\n+#define SUPPRESS_FOPEN_REDEFINITION\n #include \"../git-compat-util.h\"\n \n FILE *git_fopen(const char *path, const char *mode)\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex b1e48e5e9..691ebf370 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -698,10 +698,12 @@ char *gitstrdup(const char *s);\n #endif\n \n #ifdef FREAD_READS_DIRECTORIES\n-#ifdef fopen\n-#undef fopen\n-#endif\n-#define fopen(a,b) git_fopen(a,b)\n+# if !defined(SUPPRESS_FOPEN_REDEFINITION)\n+#  ifdef fopen\n+#   undef fopen\n+#  endif\n+#  define fopen(a,b) git_fopen(a,b)\n+# endif\n extern FILE *git_fopen(const char*, const char*);\n #endif\n \n-- \n2.12.0\n"},{"id":"317626","messageId":"xmqqshky37se.fsf@gitster.mtv.corp.google.com","threadId":"45773","inReplyTo":"130ef8bd-1c7b-0206-e1cd-076afae7e292@ramsayjones.plus.com","subject":"Re: [PATCH] git_fopen: fix a sparse 'not declared' warning","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-04-24T01:37:21Z","receivedAt":"2017-04-24T01:37:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramsay Jones <ramsay@ramsayjones.plus.com> writes:\n\n> Commit 8f4f6e53d2 (\"config.mak.uname: set FREAD_READS_DIRECTORIES for\n> Linux and FreeBSD\", 20-04-2017) caused sparse to issue a 'not declared,\n> should it be static?' warning on Linux. This is a result of the method\n> employed by 'compat/fopen.c' to suppress the (possible) redefinition of\n> the (system) fopen macro, which also removes the extern declaration of\n> the git_fopen function.\n>\n> In order to suppress the warning, introduce a new macro to suppress the\n> definition (or possibly the re-definition) of the fopen symbol as a\n> macro override. This new macro (SUPPRESS_FOPEN_REDEFINITION) is only\n> defined in 'compat/fopen.c', just prior to the inclusion of the\n> 'git-compat-util.h' header file.\n>\n> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n> ---\n>\n> Hi Duy,\n>\n> Could you (or Junio) please add this to your 'nd/fopen-errors'\n> branch, either as a separate patch or squash it into commit\n> 8f4f6e53d2 (\"config.mak.uname: set FREAD_READS_DIRECTORIES for\n> Linux and FreeBSD\", 20-04-2017). I think it would be better as a\n> separate commit, but I will leave you to decide on that. ;-)\n\nYeah, I think it makes sense to have this as a separate patch,\napplying even before the other series.\n\nThanks.\n"}]}