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

Re: [PATCH] string-list.h: Add STRING_LIST_INIT macro and make use of it.

From
Alex Riesen <raa.lkml@gmail.com>
Date
Jun 29, 2010, 08:33 UTC
Message-ID
<AANLkTinXCkX2tXFTlOSLShXMpsnpaNX0LoYGaml0sgN5@mail.gmail.com>
In-Reply-To
<7v4ogmcs1u.fsf@alter.siamese.dyndns.org>
On Tue, Jun 29, 2010 at 07:43, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
>>>
>>>    #define STRING_LIST_INIT(pleasedup) { NULL, 0, 0, (pleasedup) }
>>
>> This begs for using strdup(string-to-dup) in the macro argument, which
>> will not compile with ancient compilers which don't allow code in an
>> initializer.
>
> Err, one of us must be confused.
>
> I was suggesting to rewrite things like these, found in builtin/remote.c
> (add and rm):
>
>        struct string_list track = { NULL, 0, 0, 0 };
>        struct string_list branches = { NULL, 0, 0, 1 };
>

That must be me, again. Didn't bother to check the string_list definition and naively assumed the pleasedup was for an initialization string. I thought that depending on usage the caller may wish to either copy it or leave the string_list referncing the original. Which cannot be the case with string_list, indeed.

BTW, now that I took a look at it... The iteration over string_list items looks a little overengineered. At least from the point of view of the existing users of the feature. Wouldn't a simple loop be just as simple to use (if not simplier) and faster (no uninlineable function calls and argument preparation and passing needed)?

#define string_list_foreach(item,list) \
	for (item = (list)->items; item < (list)->items + (list)->nr; ++item)
Previous: Peter KjellerstedtNext: Thiago Farina
Message 11 of 21 in “string-list.h: Add STRING_LIST_INIT macro and make use of it.”
  1. string-list.h: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jun 26, 2010
  2. Sverre RabbelierJun 26, 2010
  3. Jonathan NiederJun 26, 2010
  4. Thiago FarinaJun 26, 2010
  5. string-list.h: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jun 26, 2010
  6. string-list.h: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jun 26, 2010
  7. Junio C HamanoJun 27, 2010
  8. Alex RiesenJun 28, 2010
  9. Junio C HamanoJun 29, 2010
  10. Peter KjellerstedtJun 29, 2010
  11. Alex RiesenJun 29, 2010
  12. string_list: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jul 2, 2010
  13. Jonathan NiederJul 2, 2010
  14. Thiago FarinaJul 2, 2010
  15. Jonathan NiederJul 2, 2010
  16. string_list: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jul 4, 2010
  17. Jonathan NiederJul 7, 2010
  18. Junio C HamanoJul 7, 2010
  19. Thiago FarinaJul 10, 2010
  20. Jonathan NiederJul 10, 2010
  21. Thiago FarinaAug 19, 2010

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.