threads / patch / 33638

patch, 6 partspath: Make the 'get_st_mode_bits' symbol a file static

Subject: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static

## tl;dr

8 messages between Apr 27, 2013 and Apr 30, 2013. Diffs are folded; open one to read it.

replies: 7people: 4as markdown or json

Ramsay Jones· Apr 27, 2013, 18:42 UTC · lore

On MinGW, sparse issues an "'get_st_mode_bits' not declared. Should it be static?" warning. The MinGW and MSVC builds do not see the declaration of this function, within git-compat-util.h, due to it's placement within an preprocessor conditional. (So, one solution would be to simply move the declaration to the top level of the header.)

In order to suppress the warning, since this symbol does not need more than file visibility, we simply remove the declaration from the header and add the static modifier to the function definition.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 git-compat-util.h | 1 -
 path.c            | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
Show changes to 2 files +1 −2

git-compat-util.h, path.c

diff --git a/git-compat-util.h b/git-compat-util.h
index e955bb5..3a990b3 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -163,7 +163,6 @@
 typedef long intptr_t;
 typedef unsigned long uintptr_t;
 #endif
-int get_st_mode_bits(const char *path, int *mode);
 #if defined(__CYGWIN__)
 #undef _XOPEN_SOURCE
 #include <grp.h>
diff --git a/path.c b/path.c
index 04ff148..cc2e9ac 100644
--- a/path.c
+++ b/path.c
@@ -11,7 +11,7 @@
  * may return wrong permission bits. Most of the time we do not care,
  * but the callsites of this wrapper do care.
  */
-int get_st_mode_bits(const char *path, int *mode)
+static int get_st_mode_bits(const char *path, int *mode)
 {
 	struct stat st;
 	if (lstat(path, &st) < 0)
-- 
1.8.2
Eric Sunshine· Apr 28, 2013, 02:26 UTC · re: Ramsay Jones · lore

Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static

On Sat, Apr 27, 2013 at 2:42 PM, Ramsay Jones <ramsay@ramsay1.demon.co.uk> wrote:

>
> On MinGW, sparse issues an "'get_st_mode_bits' not declared. Should
> it be static?" warning. The MinGW and MSVC builds do not see the
> declaration of this function, within git-compat-util.h, due to it's
s/it's/its/
Show 8 quoted lines
> placement within an preprocessor conditional. (So, one solution would
> be to simply move the declaration to the top level of the header.)
>
> In order to suppress the warning, since this symbol does not need
> more than file visibility, we simply remove the declaration from
> the header and add the static modifier to the function definition.
>
> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Torsten Bögershausen· Apr 28, 2013, 06:02 UTC · re: Ramsay Jones · lore

Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static

On 2013-04-27 20.42, Ramsay Jones wrote:
Show 43 quoted lines
> 
> On MinGW, sparse issues an "'get_st_mode_bits' not declared. Should
> it be static?" warning. The MinGW and MSVC builds do not see the
> declaration of this function, within git-compat-util.h, due to it's
> placement within an preprocessor conditional. (So, one solution would
> be to simply move the declaration to the top level of the header.)
> 
> In order to suppress the warning, since this symbol does not need
> more than file visibility, we simply remove the declaration from
> the header and add the static modifier to the function definition.
> 
> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
> ---
>  git-compat-util.h | 1 -
>  path.c            | 2 +-
>  2 files changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/git-compat-util.h b/git-compat-util.h
> index e955bb5..3a990b3 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -163,7 +163,6 @@
>  typedef long intptr_t;
>  typedef unsigned long uintptr_t;
>  #endif
> -int get_st_mode_bits(const char *path, int *mode);
>  #if defined(__CYGWIN__)
>  #undef _XOPEN_SOURCE
>  #include <grp.h>
> diff --git a/path.c b/path.c
> index 04ff148..cc2e9ac 100644
> --- a/path.c
> +++ b/path.c
> @@ -11,7 +11,7 @@
>   * may return wrong permission bits. Most of the time we do not care,
>   * but the callsites of this wrapper do care.
>   */
> -int get_st_mode_bits(const char *path, int *mode)
> +static int get_st_mode_bits(const char *path, int *mode)
>  {
>  	struct stat st;
>  	if (lstat(path, &st) < 0)
> 

Sorry for breaking the MiNGW/MSVC builds. It seams that the get_st_mode_bits is badly placed.

It should be in git compat-util.h, so that both compat/cygwin.c and path.c can see it.
So from my understanding, it should be placed here:
(I will send an official patch later)
/Torsten
 
diff -C 3 git-compat-util.h.~9526aa461f6c6900cb892a6fe248150ad436c0d~ git-compat-util.h.new
*** git-compat-util.h.~9526aa461f6c6900cb892a6fe248150ad436c0d~ 2013-04-28 07:53:28.000000000 +0200
--- git-compat-util.h.new       2013-04-28 07:53:58.000000000 +0200
***************
*** 127,132 ****
--- 127,133 ----
  #else
  #include <poll.h>
  #endif
+ int get_st_mode_bits(const char *path, int *mode);
  #if defined(__MINGW32__)
  /* pull in Windows compatibility stuff */
  #include "compat/mingw.h"
***************
*** 163,169 ****
  typedef long intptr_t;
  typedef unsigned long uintptr_t;
  #endif
- int get_st_mode_bits(const char *path, int *mode);
  #if defined(__CYGWIN__)
  #undef _XOPEN_SOURCE
  #include <grp.h>
Torsten Bögershausen· Apr 28, 2013, 11:32 UTC · re: Torsten Bögershausen · lore

Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static

On 2013-04-28 08.02, Torsten Bögershausen wrote:
Show 75 quoted lines
> On 2013-04-27 20.42, Ramsay Jones wrote:
>>
>> On MinGW, sparse issues an "'get_st_mode_bits' not declared. Should
>> it be static?" warning. The MinGW and MSVC builds do not see the
>> declaration of this function, within git-compat-util.h, due to it's
>> placement within an preprocessor conditional. (So, one solution would
>> be to simply move the declaration to the top level of the header.)
>>
>> In order to suppress the warning, since this symbol does not need
>> more than file visibility, we simply remove the declaration from
>> the header and add the static modifier to the function definition.
>>
>> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
>> ---
>>  git-compat-util.h | 1 -
>>  path.c            | 2 +-
>>  2 files changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/git-compat-util.h b/git-compat-util.h
>> index e955bb5..3a990b3 100644
>> --- a/git-compat-util.h
>> +++ b/git-compat-util.h
>> @@ -163,7 +163,6 @@
>>  typedef long intptr_t;
>>  typedef unsigned long uintptr_t;
>>  #endif
>> -int get_st_mode_bits(const char *path, int *mode);
>>  #if defined(__CYGWIN__)
>>  #undef _XOPEN_SOURCE
>>  #include <grp.h>
>> diff --git a/path.c b/path.c
>> index 04ff148..cc2e9ac 100644
>> --- a/path.c
>> +++ b/path.c
>> @@ -11,7 +11,7 @@
>>   * may return wrong permission bits. Most of the time we do not care,
>>   * but the callsites of this wrapper do care.
>>   */
>> -int get_st_mode_bits(const char *path, int *mode)
>> +static int get_st_mode_bits(const char *path, int *mode)
>>  {
>>  	struct stat st;
>>  	if (lstat(path, &st) < 0)
>>
> Sorry for breaking the MiNGW/MSVC builds.
> It seams that the get_st_mode_bits is badly placed.
> 
> It should be in git compat-util.h, so that both compat/cygwin.c and path.c can see it.
> So from my understanding, it should be placed here:
> (I will send an official patch later)
> /Torsten
>  
> 
> diff -C 3 git-compat-util.h.~9526aa461f6c6900cb892a6fe248150ad436c0d~ git-compat-util.h.new
> *** git-compat-util.h.~9526aa461f6c6900cb892a6fe248150ad436c0d~ 2013-04-28 07:53:28.000000000 +0200
> --- git-compat-util.h.new       2013-04-28 07:53:58.000000000 +0200
> ***************
> *** 127,132 ****
> --- 127,133 ----
>   #else
>   #include <poll.h>
>   #endif
> + int get_st_mode_bits(const char *path, int *mode);
>   #if defined(__MINGW32__)
>   /* pull in Windows compatibility stuff */
>   #include "compat/mingw.h"
> ***************
> *** 163,169 ****
>   typedef long intptr_t;
>   typedef unsigned long uintptr_t;
>   #endif
> - int get_st_mode_bits(const char *path, int *mode);
>   #if defined(__CYGWIN__)
>   #undef _XOPEN_SOURCE
>   #include <grp.h>
I probably change my mind:
  Declaring get_st_mode_bits() static in path.c makes sense.
  And for cygwin we have the re-define in compat/cygwin.h:
  int cygwin_get_st_mode_bits(const char *path, int *mode);
  #define get_st_mode_bits(p,m) cygwin_get_st_mode_bits((p),(m))

So, (besides the typo found by Eric), Thanks. Reviewed,and tested OK here. In short:

Acked-By: Torsten Bögershausen <tboegi@web.de>
Ramsay Jones· Apr 29, 2013, 21:57 UTC · re: Torsten Bögershausen · lore

Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static

Torsten Bögershausen wrote:
Show 46 quoted lines
> On 2013-04-27 20.42, Ramsay Jones wrote:
>>
>> On MinGW, sparse issues an "'get_st_mode_bits' not declared. Should
>> it be static?" warning. The MinGW and MSVC builds do not see the
>> declaration of this function, within git-compat-util.h, due to it's
>> placement within an preprocessor conditional. (So, one solution would
>> be to simply move the declaration to the top level of the header.)
>>
>> In order to suppress the warning, since this symbol does not need
>> more than file visibility, we simply remove the declaration from
>> the header and add the static modifier to the function definition.
>>
>> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
>> ---
>>  git-compat-util.h | 1 -
>>  path.c            | 2 +-
>>  2 files changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/git-compat-util.h b/git-compat-util.h
>> index e955bb5..3a990b3 100644
>> --- a/git-compat-util.h
>> +++ b/git-compat-util.h
>> @@ -163,7 +163,6 @@
>>  typedef long intptr_t;
>>  typedef unsigned long uintptr_t;
>>  #endif
>> -int get_st_mode_bits(const char *path, int *mode);
>>  #if defined(__CYGWIN__)
>>  #undef _XOPEN_SOURCE
>>  #include <grp.h>
>> diff --git a/path.c b/path.c
>> index 04ff148..cc2e9ac 100644
>> --- a/path.c
>> +++ b/path.c
>> @@ -11,7 +11,7 @@
>>   * may return wrong permission bits. Most of the time we do not care,
>>   * but the callsites of this wrapper do care.
>>   */
>> -int get_st_mode_bits(const char *path, int *mode)
>> +static int get_st_mode_bits(const char *path, int *mode)
>>  {
>>  	struct stat st;
>>  	if (lstat(path, &st) < 0)
>>
> Sorry for breaking the MiNGW/MSVC builds.
> It seams that the get_st_mode_bits is badly placed.
You didn't break the build; simply provoked a warning.

As I said in the commit message, an alternative is to simply move the declaration to the top level of the header (out of the preprocessor conditional).

ATB, Ramsay Jones

Junio C Hamano· Apr 28, 2013, 19:06 UTC · re: Ramsay Jones · lore

Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static

Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:
Show 5 quoted lines
> On MinGW, sparse issues an "'get_st_mode_bits' not declared. Should
> it be static?" warning. The MinGW and MSVC builds do not see the
> declaration of this function, within git-compat-util.h, due to it's
> placement within an preprocessor conditional. (So, one solution would
> be to simply move the declaration to the top level of the header.)

Well, the idea was that the user of this function in path.c will call get_st_mode_bits(), and whatever platform that provides a replacement implementation would do

	#define get_st_mode_bits(a,b) cygwin_get_st_mode_bits((a),(b))

so that the calling site in path.c will end up calling that replacement implementation. So if anything get_st_mode_bits() declaration may want to go at the _end_ (not top) after including all the compatibility crufts.

We could make the declaration static to path.c, but then nobody other than path.c would be able to make use of it in the future, and we'll have the same discussion when somebody wants to hoist the declaration to git-compat-util.h, no?

Ramsay Jones· Apr 29, 2013, 22:53 UTC · re: Junio C Hamano · lore

Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static

Junio C Hamano wrote:
Show 23 quoted lines
> Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:
> 
>> On MinGW, sparse issues an "'get_st_mode_bits' not declared. Should
>> it be static?" warning. The MinGW and MSVC builds do not see the
>> declaration of this function, within git-compat-util.h, due to it's
>> placement within an preprocessor conditional. (So, one solution would
>> be to simply move the declaration to the top level of the header.)
> 
> Well, the idea was that the user of this function in path.c will
> call get_st_mode_bits(), and whatever platform that provides a
> replacement implementation would do
> 
> 	#define get_st_mode_bits(a,b) cygwin_get_st_mode_bits((a),(b))
> 
> so that the calling site in path.c will end up calling that
> replacement implementation.  So if anything get_st_mode_bits()
> declaration may want to go at the _end_ (not top) after including
> all the compatibility crufts.
> 
> We could make the declaration static to path.c, but then nobody
> other than path.c would be able to make use of it in the future,
> and we'll have the same discussion when somebody wants to hoist the
> declaration to git-compat-util.h, no?

I don't have a problem with keeping the declaration in git-compat-util.h (after moving it so that the MinGW and MSVC builds can see it, of course) if you would rather do that.

However, I'm always a little wary when I hear someone say "this may be useful to others in the future, so lets do X to make it easier ...". I have noticed that, much more often than not, that future user never does materialise ... ;-)

Having said that ...

Back in 2011, when I was trying to fix t7606-merge-custom.sh (see commit b8a9733377, "help.c: Fix detection of custom merge strategy on cygwin", 16-06-2011), I had a patch that looked very similar to the solution Torsten has arrived at here! (The main difference was that I called stat() rather than lstat() to get the mode bits).

I decided to go with the simpler solution in commit b8a9733377.

ATB, Ramsay Jones

Junio C Hamano· Apr 30, 2013, 17:00 UTC · re: Ramsay Jones · lore

Re: [PATCH 2/6] path: Make the 'get_st_mode_bits' symbol a file static

Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:
> However, I'm always a little wary when I hear someone say "this may be
> useful to others in the future, so lets do X to make it easier ...".
> I have noticed that, much more often than not, that future user never
> does materialise ... ;-)

I do not think you are reading the reason for the function correctly. It is not "We may find it useful elsewhere".

It is "We knew Windows benefits from having a 'quick, incorrect, but the incorrectness happens not matter to the caller' hack, and we used to use it everywhere. But we identified one location we need to disable the hack for correctness, hence this 'slow-but-correct' function. There may still be other places that needs fixing by calling it".

← back to recent threads