{"thread":{"id":"30265","subject":"test-mergesort conflict with stdlib.h","startedAt":"2012-04-17T17:25:48Z","lastAt":"2012-04-17T18:09:15Z","messageCount":5,"participants":["Brian Gernhardt","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"189536","messageId":"E6D295C2-C35E-4ECF-990D-FCF8407C2429@gernhardtsoftware.com","threadId":"30265","inReplyTo":null,"subject":"test-mergesort conflict with stdlib.h","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2012-04-17T17:25:48Z","receivedAt":"2012-04-17T17:25:48Z","isPatch":false,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"On OS X 10.7.3, I get the following error attempting to build next:\n\n    CC test-mergesort.o\nIn file included from test-mergesort.c:2:\n./mergesort.h:4:7: error: conflicting types for 'mergesort'\nvoid *mergesort(void *list,\n      ^\n/usr/include/stdlib.h:306:6: note: previous declaration is here\nint      mergesort(void *, size_t, size_t,\n         ^\n\nThis appears to be due to the fact that 0db71e0: \"add mergesort() for linked lists\" added a mergesort implementation with a different signature than a mergesort implemented by OS X's standard library.  Perhaps git could use a less generic name like 'llist_mergesort'?\n\n~~ Brian Gernhardt\n"},{"id":"189537","messageId":"7vd376ntem.fsf@alter.siamese.dyndns.org","threadId":"30265","inReplyTo":"E6D295C2-C35E-4ECF-990D-FCF8407C2429@gernhardtsoftware.com","subject":"Re: test-mergesort conflict with stdlib.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-04-17T17:46:09Z","receivedAt":"2012-04-17T17:46:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brian Gernhardt <brian@gernhardtsoftware.com> writes:\n\n> On OS X 10.7.3, I get the following error attempting to build next:\n>\n>     CC test-mergesort.o\n> In file included from test-mergesort.c:2:\n> ./mergesort.h:4:7: error: conflicting types for 'mergesort'\n> void *mergesort(void *list,\n>       ^\n> /usr/include/stdlib.h:306:6: note: previous declaration is here\n> int      mergesort(void *, size_t, size_t,\n>          ^\n>\n> This appears to be due to the fact that 0db71e0: \"add mergesort() for\n> linked lists\" added a mergesort implementation with a different\n> signature than a mergesort implemented by OS X's standard library.\n\nUnfortunate.  OS X shouldn't contaminate the user namespace by adding such\nnames in stdlib.h (which incidentally has qsort()), but the damage is done\nalready, so I am not opposed to rename it to llist_mergesort() or something.\n"},{"id":"189541","messageId":"D6A62F9A-EB46-4736-BFDA-0044A993443E@gernhardtsoftware.com","threadId":"30265","inReplyTo":"7vd376ntem.fsf@alter.siamese.dyndns.org","subject":"Re: test-mergesort conflict with stdlib.h","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2012-04-17T17:55:40Z","receivedAt":"2012-04-17T17:55:40Z","isPatch":false,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"\nOn Apr 17, 2012, at 1:46 PM, Junio C Hamano wrote:\n\n> Unfortunate.  OS X shouldn't contaminate the user namespace by adding such\n> names in stdlib.h (which incidentally has qsort()), but the damage is done\n> already, so I am not opposed to rename it to llist_mergesort() or something.\n\nThis seems to be inherited from BSD's userspace which also has a mergesort (radixsort as well).  I'll make a patch to rename it and if anyone doesn't like llist_mergesort, they can repaint the bikeshed themselves.\n\n~~ Brian Gernhardt\n"},{"id":"189542","messageId":"7v8vhunsg5.fsf@alter.siamese.dyndns.org","threadId":"30265","inReplyTo":"7vd376ntem.fsf@alter.siamese.dyndns.org","subject":"Re: test-mergesort conflict with stdlib.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-04-17T18:06:50Z","receivedAt":"2012-04-17T18:06:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Unfortunate.  OS X shouldn't contaminate the user namespace by adding such\n> names in stdlib.h (which incidentally has qsort()), but the damage is done\n> already, so I am not opposed to rename it to llist_mergesort() or something.\n\nSomething like this.  While we are touching the code, let's add some\ndocumentation to the header.\n\n commit.c         |    4 ++--\n mergesort.c      |    8 ++++----\n mergesort.h      |   16 ++++++++++++----\n test-mergesort.c |    2 +-\n 4 files changed, 19 insertions(+), 11 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 0759b2c..84304c0 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -429,8 +429,8 @@ static void commit_list_set_next(void *a, void *next)\n \n void commit_list_sort_by_date(struct commit_list **list)\n {\n-\t*list = mergesort(*list, commit_list_get_next, commit_list_set_next,\n-\t\t\t  commit_list_compare_by_date);\n+\t*list = llist_mergesort(*list, commit_list_get_next, commit_list_set_next,\n+\t\t\t\tcommit_list_compare_by_date);\n }\n \n struct commit *pop_most_recent_commit(struct commit_list **list,\ndiff --git a/mergesort.c b/mergesort.c\nindex d084c60..e5fdf2e 100644\n--- a/mergesort.c\n+++ b/mergesort.c\n@@ -23,10 +23,10 @@ static void *pop_item(struct mergesort_sublist *l,\n \treturn p;\n }\n \n-void *mergesort(void *list,\n-\t\tvoid *(*get_next_fn)(const void *),\n-\t\tvoid (*set_next_fn)(void *, void *),\n-\t\tint (*compare_fn)(const void *, const void *))\n+void *llist_mergesort(void *list,\n+\t\t      void *(*get_next_fn)(const void *),\n+\t\t      void (*set_next_fn)(void *, void *),\n+\t\t      int (*compare_fn)(const void *, const void *))\n {\n \tunsigned long l;\n \ndiff --git a/mergesort.h b/mergesort.h\nindex d6e5f4a..644cff1 100644\n--- a/mergesort.h\n+++ b/mergesort.h\n@@ -1,9 +1,17 @@\n #ifndef MERGESORT_H\n #define MERGESORT_H\n \n-void *mergesort(void *list,\n-\t\tvoid *(*get_next_fn)(const void *),\n-\t\tvoid (*set_next_fn)(void *, void *),\n-\t\tint (*compare_fn)(const void *, const void *));\n+/*\n+ * Sort linked list in place.\n+ * - get_next_fn() returns the next element given an element of a linked list.\n+ * - set_next_fn() takes two elements A and B, and makes B the \"next\" element\n+ *   of A on the list.\n+ * - compare_fn() takes two elements A and B, and returns negative, 0, positive\n+ *   as the same sign as \"subtracting\" B from A.\n+ */\n+void *llist_mergesort(void *list,\n+\t\t      void *(*get_next_fn)(const void *),\n+\t\t      void (*set_next_fn)(void *, void *),\n+\t\t      int (*compare_fn)(const void *, const void *));\n \n #endif\ndiff --git a/test-mergesort.c b/test-mergesort.c\nindex 1dd82fd..3f388b4 100644\n--- a/test-mergesort.c\n+++ b/test-mergesort.c\n@@ -42,7 +42,7 @@ int main(int argc, const char **argv)\n \t\tp = line;\n \t}\n \n-\tlines = mergesort(lines, get_next, set_next, compare_strings);\n+\tlines = llist_mergesort(lines, get_next, set_next, compare_strings);\n \n \twhile (lines) {\n \t\tprintf(\"%s\", lines->text);\n"},{"id":"189543","messageId":"341E3693-9E1A-4356-A632-F5703E2829E8@gernhardtsoftware.com","threadId":"30265","inReplyTo":"7v8vhunsg5.fsf@alter.siamese.dyndns.org","subject":"Re: test-mergesort conflict with stdlib.h","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2012-04-17T18:09:15Z","receivedAt":"2012-04-17T18:09:15Z","isPatch":false,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"\nOn Apr 17, 2012, at 2:06 PM, Junio C Hamano wrote:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n>> Unfortunate.  OS X shouldn't contaminate the user namespace by adding such\n>> names in stdlib.h (which incidentally has qsort()), but the damage is done\n>> already, so I am not opposed to rename it to llist_mergesort() or something.\n> \n> Something like this.  While we are touching the code, let's add some\n> documentation to the header.\n> \n> commit.c         |    4 ++--\n> mergesort.c      |    8 ++++----\n> mergesort.h      |   16 ++++++++++++----\n> test-mergesort.c |    2 +-\n> 4 files changed, 19 insertions(+), 11 deletions(-)\n\nThis is basically identical to what I was going to send and it does, in fact, fix my build problem.\n\nThanks,\n~~ Brian Gernhardt\n"}]}