qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Re: [PATCH 1/2] Add TAILQ_FOREACH_SAFE


From: Jan Kiszka
Subject: [Qemu-devel] Re: [PATCH 1/2] Add TAILQ_FOREACH_SAFE
Date: Thu, 20 Nov 2008 14:21:59 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

Anthony Liguori wrote:
> Jan Kiszka wrote:
>> Won't fly, next_var can become NULL and would be dereferenced without a
>> prior check. Unless I'm totally blind now, there is no
>> TAILQ_FOREACH_SAFE without "GCC-ism"
> 
> Wouldn't:
> 
> (var) ? ({ (next_var) = ((var)->field.tqe_next); 1;}) :0;
> 
> Be equivalent to:
> 
> (var) ? ((next_var = ((var)->field.tqe_next), var) : var
> 

Yes, indeed. I mixed up that the evaluation order of ,-separated
expressions is not guaranteed, while it is well-defined that the last
operand delivers the result. So let's use this:

---------->

Add TAILQ iterator that allows to safely remove elements while walking
the list.

Signed-off-by: Jan Kiszka <address@hidden>
---

 sys-queue.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/sys-queue.h b/sys-queue.h
index 3d0773e..e2d3ae7 100644
--- a/sys-queue.h
+++ b/sys-queue.h
@@ -210,6 +210,11 @@ struct {                                                   
             \
                 (var);                                                  \

                 (var) = ((var)->field.tqe_next))

 

+#define TAILQ_FOREACH_SAFE(var, head, field, next_var)                  \

+        for ((var) = ((head)->tqh_first);                               \

+                (var) ? ((next_var) = ((var)->field.tqe_next), 1) : 0;  \

+                (var) = (next_var))

+

 #define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \

         for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last));   
 \

                 (var);                                                  \




reply via email to

[Prev in Thread] Current Thread [Next in Thread]