diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lists.c | 10 | ||||
-rw-r--r-- | lib/macro.h | 2 | ||||
-rw-r--r-- | lib/tlists.h | 7 |
3 files changed, 13 insertions, 6 deletions
diff --git a/lib/lists.c b/lib/lists.c index 8f95c7c2..cabfddba 100644 --- a/lib/lists.c +++ b/lib/lists.c @@ -35,10 +35,10 @@ check_list(list *l, node *n) if (!l) { ASSERT_DIE(n); + ASSERT_DIE(n->prev); node *nn = n; - while (nn->prev) - nn = nn->prev; + do { nn = nn->prev; } while (nn->prev); l = SKIP_BACK(list, head_node, nn); } @@ -61,7 +61,7 @@ check_list(list *l, node *n) } ASSERT_DIE(cur == &(l->tail_node)); - ASSERT_DIE(!n || (seen == 1) || (n == &l->head_node) || (n == &l->tail_node)); + ASSERT_DIE(!n || (seen == 1)); return 1; } @@ -121,7 +121,7 @@ add_head(list *l, node *n) LIST_INLINE void insert_node(node *n, node *after) { - EXPENSIVE_CHECK(check_list(NULL, after)); + EXPENSIVE_CHECK((after->prev == NULL) || check_list(NULL, after)); ASSUME(n->prev == NULL); ASSUME(n->next == NULL); @@ -142,7 +142,7 @@ insert_node(node *n, node *after) LIST_INLINE void rem_node(node *n) { - EXPENSIVE_CHECK((n == n->prev) && (n == n->next) || check_list(NULL, n)); + EXPENSIVE_CHECK((n->prev == n) && (n->next == n) || check_list(NULL, n)); node *z = n->prev; node *x = n->next; diff --git a/lib/macro.h b/lib/macro.h index 24fc3393..8f5d4b0e 100644 --- a/lib/macro.h +++ b/lib/macro.h @@ -26,6 +26,8 @@ #define MACRO_DROP(...) #define MACRO_UNPAREN(...) __VA_ARGS__ #define MACRO_SEP(a, b, sep) a sep b +#define MACRO_STR(a) #a +#define MACRO_STR_AFTER(a) MACRO_STR(a) /* Aliases for some special chars */ #define MACRO_COMMA , diff --git a/lib/tlists.h b/lib/tlists.h index e1ed79ea..1437e17e 100644 --- a/lib/tlists.h +++ b/lib/tlists.h @@ -147,9 +147,14 @@ static inline void TLIST_NAME(rem_node)(TLIST_LIST_STRUCT *list, TLIST_TYPE *nod #error "You should first include lib/tlists.h without requesting a TLIST" #endif -#define TLIST_NODE(_name, _type) struct _name##_node { _type *next; _type *prev; } +#define TLIST_NODE_CONTENTS(_type) { _type *next; _type *prev; } +#define TLIST_NODE(_name, _type) struct _name##_node TLIST_NODE_CONTENTS(_type) +#define TLIST_DEFAULT_NODE struct MACRO_CONCAT_AFTER(TLIST_PREFIX,_node) \ + TLIST_NODE_CONTENTS(TLIST_TYPE) TLIST_ITEM + #define TLIST_LIST(_name) struct _name##_list + /* Use ->first and ->last to access HEAD and TAIL */ #define THEAD(_name, _list) (_list)->first #define TTAIL(_name, _list) (_list)->last |