git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git_fopen: fix a sparse 'not declared' warning
@ 2017-04-22  0:58 Ramsay Jones
  2017-04-24  1:37 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Ramsay Jones @ 2017-04-22  0:58 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: Junio C Hamano, GIT Mailing-list


Commit 8f4f6e53d2 ("config.mak.uname: set FREAD_READS_DIRECTORIES for
Linux and FreeBSD", 20-04-2017) caused sparse to issue a 'not declared,
should it be static?' warning on Linux. This is a result of the method
employed by 'compat/fopen.c' to suppress the (possible) redefinition of
the (system) fopen macro, which also removes the extern declaration of
the git_fopen function.

In order to suppress the warning, introduce a new macro to suppress the
definition (or possibly the re-definition) of the fopen symbol as a
macro override. This new macro (SUPPRESS_FOPEN_REDEFINITION) is only
defined in 'compat/fopen.c', just prior to the inclusion of the
'git-compat-util.h' header file.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---

Hi Duy,

Could you (or Junio) please add this to your 'nd/fopen-errors' branch, either
as 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
be better as a separate commit, but I will leave you to decide on that. ;-)

Thanks!

ATB,
Ramsay Jones

 compat/fopen.c    |  4 ++--
 git-compat-util.h | 10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/compat/fopen.c b/compat/fopen.c
index b5ca142fe..107b3e818 100644
--- a/compat/fopen.c
+++ b/compat/fopen.c
@@ -1,14 +1,14 @@
 /*
  *  The order of the following two lines is important.
  *
- *  FREAD_READS_DIRECTORIES is undefined before including git-compat-util.h
+ *  SUPPRESS_FOPEN_REDEFINITION is defined before including git-compat-util.h
  *  to avoid the redefinition of fopen within git-compat-util.h. This is
  *  necessary since fopen is a macro on some platforms which may be set
  *  based on compiler options. For example, on AIX fopen is set to fopen64
  *  when _LARGE_FILES is defined. The previous technique of merely undefining
  *  fopen after including git-compat-util.h is inadequate in this case.
  */
-#undef FREAD_READS_DIRECTORIES
+#define SUPPRESS_FOPEN_REDEFINITION
 #include "../git-compat-util.h"
 
 FILE *git_fopen(const char *path, const char *mode)
diff --git a/git-compat-util.h b/git-compat-util.h
index b1e48e5e9..691ebf370 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -698,10 +698,12 @@ char *gitstrdup(const char *s);
 #endif
 
 #ifdef FREAD_READS_DIRECTORIES
-#ifdef fopen
-#undef fopen
-#endif
-#define fopen(a,b) git_fopen(a,b)
+# if !defined(SUPPRESS_FOPEN_REDEFINITION)
+#  ifdef fopen
+#   undef fopen
+#  endif
+#  define fopen(a,b) git_fopen(a,b)
+# endif
 extern FILE *git_fopen(const char*, const char*);
 #endif
 
-- 
2.12.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] git_fopen: fix a sparse 'not declared' warning
  2017-04-22  0:58 [PATCH] git_fopen: fix a sparse 'not declared' warning Ramsay Jones
@ 2017-04-24  1:37 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2017-04-24  1:37 UTC (permalink / raw)
  To: Ramsay Jones; +Cc: Nguyen Thai Ngoc Duy, GIT Mailing-list

Ramsay Jones <ramsay@ramsayjones.plus.com> writes:

> Commit 8f4f6e53d2 ("config.mak.uname: set FREAD_READS_DIRECTORIES for
> Linux and FreeBSD", 20-04-2017) caused sparse to issue a 'not declared,
> should it be static?' warning on Linux. This is a result of the method
> employed by 'compat/fopen.c' to suppress the (possible) redefinition of
> the (system) fopen macro, which also removes the extern declaration of
> the git_fopen function.
>
> In order to suppress the warning, introduce a new macro to suppress the
> definition (or possibly the re-definition) of the fopen symbol as a
> macro override. This new macro (SUPPRESS_FOPEN_REDEFINITION) is only
> defined in 'compat/fopen.c', just prior to the inclusion of the
> 'git-compat-util.h' header file.
>
> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
> ---
>
> Hi Duy,
>
> Could you (or Junio) please add this to your 'nd/fopen-errors'
> branch, either as 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 be better as a
> separate commit, but I will leave you to decide on that. ;-)

Yeah, I think it makes sense to have this as a separate patch,
applying even before the other series.

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-24  1:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-22  0:58 [PATCH] git_fopen: fix a sparse 'not declared' warning Ramsay Jones
2017-04-24  1:37 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).