summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJosh Bailey <joshb@google.com>2012-03-21 10:00:07 -0700
committerAvneesh Sachdev <avneesh@opensourcerouting.org>2012-04-07 13:52:23 -0700
commit54dd61227352dd1dd4db4fe76dbf7d2e92522e74 (patch)
treeda320cdec867ca81748f3b85b772422b386bf376 /lib
parent8ced4e82e6f417b13f4bfc09018fc51fd31058e2 (diff)
lib: Tweaks to linked list macros
* lib/linklist.h - Change the listnextnode, listhead and listtail macros so that they allow the list pointer to be NULL. - Modify the ALL_LIST_ELEMENTS* macros such that they clear the data pointer at the beginning and end of the loop. From: Josh Bailey <joshb@google.com> Signed-off-by: Avneesh Sachdev <avneesh@opensourcerouting.org> Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/linklist.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/linklist.h b/lib/linklist.h
index cc6867cd..f0ae3625 100644
--- a/lib/linklist.h
+++ b/lib/linklist.h
@@ -54,9 +54,9 @@ struct list
void (*del) (void *val);
};
-#define listnextnode(X) ((X)->next)
-#define listhead(X) ((X)->head)
-#define listtail(X) ((X)->tail)
+#define listnextnode(X) ((X) ? ((X)->next) : NULL)
+#define listhead(X) ((X) ? ((X)->head) : NULL)
+#define listtail(X) ((X) ? ((X)->tail) : NULL)
#define listcount(X) ((X)->count)
#define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL)
#define listgetdata(X) (assert((X)->data != NULL), (X)->data)
@@ -88,10 +88,10 @@ extern void list_add_list (struct list *, struct list *);
* It is safe to delete the listnode using this macro.
*/
#define ALL_LIST_ELEMENTS(list,node,nextnode,data) \
- (node) = listhead(list); \
+ (node) = listhead(list), ((data) = NULL); \
(node) != NULL && \
((data) = listgetdata(node),(nextnode) = listnextnode(node), 1); \
- (node) = (nextnode)
+ (node) = (nextnode), ((data) = NULL)
/* read-only list iteration macro.
* Usage: as per ALL_LIST_ELEMENTS, but not safe to delete the listnode Only
@@ -100,9 +100,9 @@ extern void list_add_list (struct list *, struct list *);
* of previous macro.
*/
#define ALL_LIST_ELEMENTS_RO(list,node,data) \
- (node) = listhead(list); \
+ (node) = listhead(list), ((data) = NULL);\
(node) != NULL && ((data) = listgetdata(node), 1); \
- (node) = listnextnode(node)
+ (node) = listnextnode(node), ((data) = NULL)
/* these *do not* cleanup list nodes and referenced data, as the functions
* do - these macros simply {de,at}tach a listnode from/to a list.