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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 12, 2013, 18:35 UTC
Message-ID
<xmqqd2odq45y.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20130912182057.GB32069@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 18 quoted lines
> On Thu, Sep 12, 2013 at 08:37:08AM -0700, Junio C Hamano wrote:
>
>> > I wonder if GCC has changed it's behaviour to more closely match C99.
>> > Clang as a compatibility article about this sort of issue:
>> >
>> >     http://clang.llvm.org/compatibility.html#inline
>> 
>> Interesting.  The ways the page suggests as fixes are
>> 
>>  - change it to a "statis inline";
>>  - remove "inline" from the definition;
>>  - provide an external (non-inline) def somewhere else;
>>  - compile with gnu899 dialect.
>
> 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?

That is exactly my point when I said that the third one is nonsense for a definition in the standard header file.

I think we would want something like below.
-- >8 --
Subject: [PATCH] mailmap: work around implementations with pure inline strcasecmp

On some systems, string.h has _only_ inline definition of strcasecmp without supplying a non-inline implementation anywhere, which is, eh, "unusual"; we cannot take an address of such a function to store it in namemap.cmp. Work it around by introducing our own level of indirection.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 mailmap.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/mailmap.c b/mailmap.c
index 44614fc..8863e23 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -52,6 +52,19 @@ static void free_mailmap_entry(void *p, const char *s)
 	string_list_clear_func(&me->namemap, free_mailmap_info);
 }
 
+/*
+ * On some systems, string.h has _only_ inline definition of strcasecmp
+ * without supplying a non-inline implementation anywhere, which is, eh,
+ * "unusual"; we cannot take an address of such a function to store it in
+ * namemap.cmp.  This is here as a workaround---do not assign strcasecmp
+ * directly to namemap.cmp until we know no systems that matter have such
+ * an "unusual" string.h.
+ */
+static int namemap_cmp(const char *a, const char *b)
+{
+	return strcasecmp(a, b);
+}
+
 static void add_mapping(struct string_list *map,
 			char *new_name, char *new_email,
 			char *old_name, char *old_email)
@@ -75,7 +88,7 @@ static void add_mapping(struct string_list *map,
 		item = string_list_insert_at_index(map, index, old_email);
 		me = xcalloc(1, sizeof(struct mailmap_entry));
 		me->namemap.strdup_strings = 1;
-		me->namemap.cmp = strcasecmp;
+		me->namemap.cmp = namemap_cmp;
 		item->util = me;
 	}
 
@@ -241,7 +254,7 @@ int read_mailmap(struct string_list *map, char **repo_abbrev)
 	int err = 0;
 
 	map->strdup_strings = 1;
-	map->cmp = strcasecmp;
+	map->cmp = namemap_cmp;
 
 	if (!git_mailmap_blob && is_bare_repository())
 		git_mailmap_blob = "HEAD:.mailmap";
-- 
1.8.4-485-gec42fe2
Previous: Jeff KingNext: Jonathan Nieder
Message 11 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.