ruby-changes:35495
From: normal <ko1@a...>
Date: Sun, 14 Sep 2014 08:49:29 +0900 (JST)
Subject: [ruby-changes:35495] normal:r47577 (trunk): ccan/list: new list_{del, node}_init functions
normal 2014-09-14 08:49:15 +0900 (Sun, 14 Sep 2014) New Revision: 47577 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47577 Log: ccan/list: new list_{del,node}_init functions * ccan/list/list.h (list_del_init, list_node_init): new functions for multiple list_del() calls [ccan ec8654d94d3c5c47aa5f82698f7e8048c79765b1] (Rusty Russell) Modified files: trunk/ChangeLog trunk/ccan/list/list.h Index: ChangeLog =================================================================== --- ChangeLog (revision 47576) +++ ChangeLog (revision 47577) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Sep 14 08:41:44 2014 Eric Wong <e@8...> + + * ccan/list/list.h (list_del_init, list_node_init): new functions + for multiple list_del() calls + [ccan ec8654d94d3c5c47aa5f82698f7e8048c79765b1] (Rusty Russell) + Sat Sep 13 22:19:26 2014 Bernard Potocki <bernard.potocki@i...> * hash.c (rb_hash_aset): fix misleading example which may suggest Index: ccan/list/list.h =================================================================== --- ccan/list/list.h (revision 47576) +++ ccan/list/list.h (revision 47577) @@ -92,6 +92,18 @@ static inline void list_head_init(struct https://github.com/ruby/ruby/blob/trunk/ccan/list/list.h#L92 } /** + * list_node_init - initialize a list_node + * @n: the list_node to link to itself. + * + * You don't need to use this normally! But it lets you list_del(@n) + * safely. + */ +static inline void list_node_init(struct list_node *n) +{ + n->next = n->prev = n; +} + +/** * list_add - add an entry at the start of a linked list. * @h: the list_head to add the node to * @n: the list_node to add to the list. @@ -183,7 +195,7 @@ static inline int list_empty_nodebug(con https://github.com/ruby/ruby/blob/trunk/ccan/list/list.h#L195 * another list, but not deleted again. * * See also: - * list_del_from() + * list_del_from(), list_del_init() * * Example: * list_del(&child->list); @@ -202,6 +214,27 @@ static inline void list_del_(struct list https://github.com/ruby/ruby/blob/trunk/ccan/list/list.h#L214 } /** + * list_del_init - delete a node, and reset it so it can be deleted again. + * @n: the list_node to be deleted. + * + * list_del(@n) or list_del_init() again after this will be safe, + * which can be useful in some cases. + * + * See also: + * list_del_from(), list_del() + * + * Example: + * list_del_init(&child->list); + * parent->num_children--; + */ +#define list_del_init(n) list_del_init_(n, LIST_LOC) +static inline void list_del_init_(struct list_node *n, const char *abortstr) +{ + list_del_(n, abortstr); + list_node_init(n); +} + +/** * list_del_from - delete an entry from a known linked list. * @h: the list_head the node is in. * @n: the list_node to delete from the list. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/