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

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

From
Sebastian Schuberth <sschuberth@gmail.com>
Date
Sep 18, 2013, 09:43 UTC
Message-ID
<CAHGBnuMh9wqe6mhLyqbPAGJUEEH7cA2LZPuCQK8VD=NU2ix3Pg@mail.gmail.com>
In-Reply-To
<xmqqsix3w27t.fsf@gitster.dls.corp.google.com>
On Tue, Sep 17, 2013 at 11:46 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
>> I don't think people on other platforms seeing the ugliness is really
>> an issue. After all, the file is called git-*compat*-util.h;
>
> Well, judging from the way Linus reacted to the patch, I'd have to
> disagree.  After all, that argument leads to the position that
> nothing is needed in compat/, no?

My feeling is that Linus' reaction was more about that this work-around is even necessary (and MinGW is buggy) rather than applying it to git-compat-util.h and not elsewhere.

Show 6 quoted lines
> One ugliness (lack of sane strcasecmp definition whose address can
> be taken) specific to mingw is worked around in compat/mingw.h, and
> another ugliness that some people may use compilers without include_next
> may need help from another configuration in the Makefile to tell it
> where the platform string.h resides.  I am not sure why you see it
> as a problem.

I just don't like that the ugliness is spreading out and requires a change to config.mak.uname now, too. Also, I regard the change to config.mak.uname by itself as ugly, mainly because you would have to set SYSTEM_STRING_H_HEADER to some path, but that path might differ from system to system, depending on where MinGW is installed on Windows.

Show 5 quoted lines
>> I do insist to avoid GCC-ism in C files,...
>
> To that I tend to agree.  Unconditionally killing inlining for any
> mingw compilation in compat/mingw.h may be the simplest (albeit it
> may be less than optimal) solution.

I tried to put the __NO_INLINE__ stuff in compat/mingw.h but failed, it involved the need to shuffle includes in git-compat-util.h around because winsock2.h already seems to include string.h, and I did not find a working include order. So I came up with the following, do you like that better?

diff --git a/compat/string_no_inline.h b/compat/string_no_inline.h
new file mode 100644
index 0000000..51eed52
--- /dev/null
+++ b/compat/string_no_inline.h
@@ -0,0 +1,25 @@
+#ifndef STRING_NO_INLINE_H
+#define STRING_NO_INLINE_H
+
+#ifdef __MINGW32__
+#ifdef __NO_INLINE__
+#define __NO_INLINE_ALREADY_DEFINED
+#else
+#define __NO_INLINE__ /* do not inline strcasecmp() */
+#endif
+#endif
+
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h> /* for strcasecmp() */
+#endif
+
+#ifdef __MINGW32__
+#ifdef __NO_INLINE_ALREADY_DEFINED
+#undef __NO_INLINE_ALREADY_DEFINED
+#else
+#undef __NO_INLINE__
+#endif
+#endif
+
+#endif
diff --git a/git-compat-util.h b/git-compat-util.h
index db564b7..348dd55 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -85,6 +85,8 @@
 #define _NETBSD_SOURCE 1
 #define _SGI_SOURCE 1

+#include "compat/string_no_inline.h"
+
 #ifdef WIN32 /* Both MinGW and MSVC */
 #ifndef _WIN32_WINNT
 #define _WIN32_WINNT 0x0502
@@ -101,10 +103,6 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdarg.h>
-#include <string.h>
-#ifdef HAVE_STRINGS_H
-#include <strings.h> /* for strcasecmp() */
-#endif
 #include <errno.h>
 #include <limits.h>
 #ifdef NEEDS_SYS_PARAM_H
-- 
1.8.3.mingw.1.dirty

-- 
Sebastian Schuberth
Previous: Junio C HamanoNext: Linus Torvalds
Message 36 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.