[PATCH 1/2] list.h: Fix list_for_each_entry_safe()
Kristian Høgsberg
krh at bitplanet.net
Mon Jun 14 08:18:58 PDT 2010
On Mon, Jun 14, 2010 at 10:52 AM, Tiago Vignatti
<tiago.vignatti at nokia.com> wrote:
> On Mon, Jun 14, 2010 at 03:25:22PM +0200, ext Kristian H�gsberg wrote:
>> Can't use next as a macro argument since we're accessing the .next field
>> of struct list.
>> ---
>> include/list.h | 6 +++---
>> 1 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/list.h b/include/list.h
>> index 89dc29d..4ce20a8 100644
>> --- a/include/list.h
>> +++ b/include/list.h
>> @@ -94,10 +94,10 @@ list_is_empty(struct list *head)
>> &pos->member != (head); \
>> pos = __container_of(pos->member.next, pos, member))
>>
>> -#define list_for_each_entry_safe(pos, next, head, member) \
>> +#define list_for_each_entry_safe(pos, tmp, head, member) \
>> for (pos = __container_of((head)->next, pos, member), \
>> - next = __container_of(pos->member.next, pos, member); \
>> + tmp = __container_of(pos->member.next, pos, member); \
>> &pos->member != (head); \
>> - pos = next, next = __container_of(next->member.next, next, member))
>> + pos = tmp, tmp = __container_of(pos->member.next, tmp, member))
>>
>> #endif
>
> Kristian, doesn't make sense then to use inline function here instead keep
> juggling with the names?
We can't do that for this macro. If you look closer, you'll see that
it expands to a for statement without the body. You use it like this:
list_for_each_entry_safe(...) {
/* do something with each entry */
}
Kristian
More information about the xorg-devel
mailing list