git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] Add strchrnul()

From
Andreas Ericsson <ae@op5.se>
Date
Nov 9, 2007, 13:59 UTC
Message-ID
<473467C4.8020208@op5.se>
In-Reply-To
<fh1o4o$jei$1@ger.gmane.org>
Jakub Narebski wrote:
Show 5 quoted lines
> [Cc: Andreas Ericsson <ae@op5.se>, 
>      René Scharfe <rene.scharfe@lsrfire.ath.cx>, 
>      Junio C Hamano <gitster@pobox.com>,
>      git@vger.kernel.org]
> 

I'm not sure what's up with this, but I didn't see this email on git@vger, so re-adding it to the Cc list now.

Show 27 quoted lines
> 
> Original patch lacked adding appropriate test to configure,
> i.e. something like below to configure.ac
> 
>  #
>  # Define NO_STRCHRNUL if you don't have strchrnul.
>  AC_CHECK_FUNC(strchrnul,
>  [NO_STRCHRNUL=],
>  [NO_STRCHRNUL=YesPlease])
>  AC_SUBST(NO_STRCHRNUL)
>  
> and the following line to config.mak.in
> 
>  NO_STRCHRNUL=@NO_STRCHRNUL@
> 
>> This seems overly complicated. How about this instead?
> [...]
>> I'm fairly much against forcing people to know what library
>> functions they have in order to get software to compile
>> properly. This is, imo, a neater solution, and also inlines
>> the function as suggested by Dscho.
> 
> Wouldn't it be better to add ./configure check instead? See above.
> 
> Although I guess that people using ./configure to set compilation
> options (to generate config.mak.autogen) are minority...
> 

Perhaps. I know I don't anyway, and now it's become standard not to do so for a significant part of the git-tracking world.

Show 16 quoted lines
>> +#if !defined(__GLIBC__) && !__GLIBC_PREREQ(2, 1)
>> +# define strchrnul(s, c) gitstrchrnul(s, c)
>> +static inline char *gitstrchrnul(const char *s, int c)
>> +{
>> +       while (*s && *s != c)
>> +               s++;
>> +
>> +       return (char *)s;
>> +}
>> +#endif
>> +
> 
> This is good solution, although I'm not sure about the check itself.
> What if somebody has libc which is not glibc, but it does have
> strchrnul?
> 

They most likely fall into the minority that get to suffer from using code that's as fast as what's in there today, although a bit more readable. The glibc optimization is really only worthwhile for architectures where strchrnul()-like operations have microcode support, or when it's used on large strings.

YMMV. I suppose rewriting it as

#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 1) # define HAVE_STRCHRNUL #endif

#ifdef HAVE_STRCHRNUL ...

would work too, and will provide an easier way out for other fellas wanting to say "Hey, my favourite solaris libc has this too!". OTOH, that rewrite can be done when the first such case appears.

>> diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
> 
> This IMHO should go to separate patch.
> 
*shrug* Rene had it in his. Monkey see monkey do ;-)
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Previous: Jakub NarebskiNext: Jakub Narebski
Message 6 of 18 in “Add strchrnul()”
  1. 1/2 Add strchrnul()René Scharfe, Nov 9, 2007
  2. Johannes SchindelinNov 9, 2007
  3. Jeff KingNov 9, 2007
  4. Andreas EricssonNov 9, 2007
  5. Jakub NarebskiNov 9, 2007
  6. Andreas EricssonNov 9, 2007
  7. Jakub NarebskiNov 9, 2007
  8. Simplify strchrnul() compat codeRené Scharfe, Nov 10, 2007
  9. Andreas EricssonNov 10, 2007
  10. Junio C HamanoNov 11, 2007
  11. Andreas EricssonNov 11, 2007
  12. David SymondsNov 12, 2007
  13. Johannes SixtNov 12, 2007
  14. David SymondsNov 12, 2007
  15. Johannes SixtNov 12, 2007
  16. David SymondsNov 12, 2007
  17. Jakub NarebskiNov 12, 2007
  18. Fix preprocessor logic that determines the availablity of strchrnul().Johannes Sixt, Nov 12, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.