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

Re: [PATCH] git-compat-util: Avoid strcasecmp() being inlined

From
Jeff King <peff@peff.net>
Date
Sep 12, 2013, 20:22 UTC
Message-ID
<20130912202246.GF32069@sigill.intra.peff.net>
In-Reply-To
<CAHGBnuPzzokV7YMrx0gAL1VACcmaLwFoaB3n6bX8Y-UDHs7S8A@mail.gmail.com>
On Thu, Sep 12, 2013 at 09:46:51PM +0200, Sebastian Schuberth wrote:
Show 17 quoted lines
> > Right, option 3 seems perfectly reasonable to me, as we must be prepared
> > to cope with a decision not to inline the function, and there has to be
> > _some_ linked implementation. But shouldn't libc be providing an
> > external, linkable strcasecmp in this case?
> 
> MinGW / GCC is not linking against libc, but against MSVCRT, Visual
> Studio's C runtime. And in fact MSVCRT has a non-inline implementation
> of a "case-insensitive string comparison for up to the first n
> characters"; it just happens to be called "_strnicmp", not
> "strncasecmp". Which is why I still think just having a "#define
> strncasecmp _strnicmp" is the most elegant solution to the problem.
> And that's exactly what defining __NO_INLINE__ does. Granted, defining
> __NO_INLINE__ in the scope of string.h will also add a "#define
> strcasecmp _stricmp"; but despite it's name, defining __NO_INLINE__
> does not imply a performance hit due to functions not being inlined
> because it's just the "strncasecmp" wrapper around "_strnicmp" that's
> being inlined, not "_strnicmp" itself.

Ah, thanks, that explains what is going on. I do think the environment is probably in violation of C99, but I dug in the mingw history, and it looks like it has been this way for over 10 years.

So it is probably worth working around, but it would be nice if the damage could be contained to just the affected platform.

I think there are basically three classes of solution:
  1. Declare __NO_INLINE__ everywhere. I'd worry this might affect other
     environments, who would then not inline and lose performance (but
     since it's a non-standard macro, we don't really know what it will
     do in other places; possibly nothing).
  2. Declare __NO_INLINE__ on mingw. Similar to above, but we know it
     only affects mingw, and we know the meaning of NO_INLINE there.
  3. Try to impact only the uses as a function pointer (e.g., by using
     a wrapper function as suggested in the thread).

Your patch does (1), I believe. Junio's patch does (3), but is a maintenance burden in that any new callsites will need to remember to do the same trick.

But your argument (and reading the mingw header, I agree) is that there is no performance difference at all between (2) and (3). And (2) does not have the maintenance burden. So it does seem like the right path to me.

-Peff
Previous: Sebastian SchuberthNext: Junio C Hamano
Message 21 of 48 in “git-compat-util: Avoid strcasecmp() being inlined”
  1. git-compat-util: Avoid strcasecmp() being inlinedSebastian Schuberth, Sep 11, 2013
  2. Jonathan NiederSep 11, 2013
  3. Jeff KingSep 11, 2013
  4. Piotr KrukowieckiSep 19, 2013
  5. Sebastian SchuberthSep 11, 2013
  6. Jeff KingSep 11, 2013
  7. Sebastian SchuberthSep 12, 2013
  8. John KeepingSep 12, 2013
  9. Junio C HamanoSep 12, 2013
  10. Jeff KingSep 12, 2013
  11. Junio C HamanoSep 12, 2013
  12. Jonathan NiederSep 12, 2013
  13. Sebastian SchuberthSep 12, 2013
  14. Junio C HamanoSep 12, 2013
  15. Sebastian SchuberthSep 13, 2013
  16. Junio C HamanoSep 13, 2013
  17. Sebastian SchuberthSep 13, 2013
  18. Jonathan NiederSep 12, 2013
  19. Jeff KingSep 12, 2013
  20. Sebastian SchuberthSep 12, 2013
  21. Jeff KingSep 12, 2013
  22. Junio C HamanoSep 12, 2013
  23. Sebastian SchuberthSep 13, 2013
  24. Junio C HamanoSep 13, 2013
  25. Sebastian SchuberthSep 13, 2013
  26. Linus TorvaldsSep 13, 2013
  27. Sebastian SchuberthSep 13, 2013
  28. Junio C HamanoSep 13, 2013
  29. Sebastian SchuberthSep 13, 2013
  30. Junio C HamanoSep 13, 2013
  31. Junio C HamanoSep 13, 2013
  32. Sebastian SchuberthSep 15, 2013
  33. Junio C HamanoSep 17, 2013
  34. Sebastian SchuberthSep 17, 2013
  35. Junio C HamanoSep 17, 2013
  36. Sebastian SchuberthSep 18, 2013
  37. Linus TorvaldsSep 18, 2013
  38. Jonathan NiederSep 12, 2013
  39. Sebastian SchuberthSep 19, 2013
  40. Junio C HamanoSep 11, 2013
  41. Piotr KrukowieckiSep 19, 2013
  42. Jeff KingSep 19, 2013
  43. Junio C HamanoSep 19, 2013
  44. Jeff KingSep 19, 2013
  45. Junio C HamanoSep 19, 2013
  46. Jeff KingSep 20, 2013
  47. Piotr KrukowieckiSep 20, 2013
  48. Jeff KingSep 24, 2013

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.