From 6f0091981e38210e36ee830694f61cb695f2b99b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 30 Jan 2024 12:49:28 -0500 Subject: list: Return the next cursor from SLIST_INSERT() --- src/list.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/list.h') diff --git a/src/list.h b/src/list.h index 02a7ba2..61d0e5b 100644 --- a/src/list.h +++ b/src/list.h @@ -275,6 +275,8 @@ * The item to insert. * @param node (optional) * If specified, use item->node.next rather than item->next. + * @return + * A cursor for the next item. */ #define SLIST_INSERT(list, cursor, ...) \ SLIST_INSERT_(list, cursor, __VA_ARGS__, ) @@ -282,11 +284,12 @@ #define SLIST_INSERT_(list, cursor, item, ...) \ SLIST_INSERT__((list), (cursor), (item), LIST_NEXT_(__VA_ARGS__)) -#define SLIST_INSERT__(list, cursor, item, next) LIST_VOID_( \ - bfs_assert(!SLIST_ATTACHED__(list, item, next)), \ - item->next = *cursor, \ - *cursor = item, \ - list->tail = item->next ? list->tail : &item->next) +#define SLIST_INSERT__(list, cursor, item, next) \ + (bfs_assert(!SLIST_ATTACHED__(list, item, next)), \ + item->next = *cursor, \ + *cursor = item, \ + list->tail = item->next ? list->tail : &item->next, \ + &item->next) /** * Add an item to the tail of a singly-linked list. @@ -302,7 +305,7 @@ SLIST_APPEND_(list, __VA_ARGS__, ) #define SLIST_APPEND_(list, item, ...) \ - SLIST_INSERT_(list, (list)->tail, item, __VA_ARGS__) + LIST_VOID_(SLIST_INSERT_(list, (list)->tail, item, __VA_ARGS__)) /** * Add an item to the head of a singly-linked list. @@ -318,7 +321,7 @@ SLIST_PREPEND_(list, __VA_ARGS__, ) #define SLIST_PREPEND_(list, item, ...) \ - SLIST_INSERT_(list, &(list)->head, item, __VA_ARGS__) + LIST_VOID_(SLIST_INSERT_(list, &(list)->head, item, __VA_ARGS__)) /** * Add an entire singly-linked list to the tail of another. -- cgit v1.2.3