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

Re: [RFC PATCH] hashmap API: introduce for_each_hashmap_entry() helper macro

From
Alexander Kuleshov <kuleshovmail@gmail.com>
Date
Mar 16, 2016, 18:39 UTC
Message-ID
<CANCZXo4uePVvk8_h2KuZQe4UFcFS1C76JvOfugK2nH3oH7TOsw@mail.gmail.com>
In-Reply-To
<xmqq37rq5m79.fsf@gitster.mtv.corp.google.com>
Hello Junio,
On Thu, Mar 17, 2016 at 12:09 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 26 quoted lines
> Alexander Kuleshov <kuleshovmail@gmail.com> writes:
>
>> diff --git a/hashmap.h b/hashmap.h
>> index ab7958a..b8b158c 100644
>> --- a/hashmap.h
>> +++ b/hashmap.h
>> @@ -95,4 +95,11 @@ static inline const char *strintern(const char *string)
>>       return memintern(string, strlen(string));
>>  }
>>
>> +#define for_each_hashmap_entry(map, type)            \
>> +     struct type *entry;                             \
>> +     struct hashmap_iter iter;                       \
>> +                                                     \
>> +     hashmap_iter_init(map, &iter);                  \
>> +     while ((entry = hashmap_iter_next(&iter)))
>> +
>
> This is an easy way to introduce decl-after-statement, i.e. needs an
> extra pair of {} around the thing.  It also forbids the callers from
> defining "entry" and "iter" as their own identifier outside the
> scope of this macro and use them inside the block that is iterated
> over by shadowing these two variables.
>
> Other than that, it looks like a good concept.  The syntax however
> needs more thought because of the above two issues, I think.
Thanks for feedback. Will fix first issue and think about second.
Previous: Junio C HamanoNext: Karsten Blees
Message 3 of 4 in “hashmap API: introduce for_each_hashmap_entry() helper macro”
  1. hashmap API: introduce for_each_hashmap_entry() helper macroAlexander Kuleshov, Mar 16, 2016
  2. Junio C HamanoMar 16, 2016
  3. Alexander KuleshovMar 16, 2016
  4. Karsten BleesMar 16, 2016

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.