Commit a6b5111f authored by Rusty Russell's avatar Rusty Russell

tlist: remove type arg from tlist_top(), tlist_tail()

With the type canary, it's unnecessary.  Though the implementation is
a bit more awkward since they longer map directly through to list_top/tail.
parent c1e57dbf
...@@ -570,7 +570,7 @@ static void free_everything(void) ...@@ -570,7 +570,7 @@ static void free_everything(void)
{ {
struct failtest_call *i; struct failtest_call *i;
while ((i = tlist_top(&history, struct failtest_call, list)) != NULL) while ((i = tlist_top(&history, list)) != NULL)
free_call(i); free_call(i);
failtable_clear(&failtable); failtable_clear(&failtable);
...@@ -755,7 +755,7 @@ static bool should_fail(struct failtest_call *call) ...@@ -755,7 +755,7 @@ static bool should_fail(struct failtest_call *call)
char *failpath; char *failpath;
struct failtest_call *c; struct failtest_call *c;
c = tlist_tail(&history, struct failtest_call, list); c = tlist_tail(&history, list);
diff = time_sub(time_now(), start); diff = time_sub(time_now(), start);
failpath = failpath_string(); failpath = failpath_string();
p = strrchr(c->file, '/'); p = strrchr(c->file, '/');
...@@ -770,8 +770,7 @@ static bool should_fail(struct failtest_call *call) ...@@ -770,8 +770,7 @@ static bool should_fail(struct failtest_call *call)
free(failpath); free(failpath);
} }
/* From here on, we have to clean up! */ /* From here on, we have to clean up! */
our_history_start = tlist_tail(&history, struct failtest_call, our_history_start = tlist_tail(&history, list);
list);
close(control[0]); close(control[0]);
close(output[0]); close(output[0]);
/* Don't swallow stderr if we're tracing. */ /* Don't swallow stderr if we're tracing. */
......
...@@ -214,7 +214,7 @@ enum failtest_result { ...@@ -214,7 +214,7 @@ enum failtest_result {
* static enum failtest_result dont_fail_alloc(struct tlist_calls *history) * static enum failtest_result dont_fail_alloc(struct tlist_calls *history)
* { * {
* struct failtest_call *call; * struct failtest_call *call;
* call = tlist_tail(history, struct failtest_call, list); * call = tlist_tail(history, list);
* if (call->type == FAILTEST_MALLOC * if (call->type == FAILTEST_MALLOC
* || call->type == FAILTEST_CALLOC * || call->type == FAILTEST_CALLOC
* || call->type == FAILTEST_REALLOC) * || call->type == FAILTEST_REALLOC)
......
...@@ -315,7 +315,7 @@ void lbalance_free(struct lbalance *lb) ...@@ -315,7 +315,7 @@ void lbalance_free(struct lbalance *lb)
{ {
struct lbalance_task *task; struct lbalance_task *task;
while ((task = tlist_top(&lb->tasks, struct lbalance_task, list))) { while ((task = tlist_top(&lb->tasks, list))) {
assert(task->lb == lb); assert(task->lb == lb);
tlist_del_from(&lb->tasks, task, list); tlist_del_from(&lb->tasks, task, list);
lb->num_tasks--; lb->num_tasks--;
......
...@@ -72,7 +72,7 @@ block_repeat_failures(struct tlist_calls *history) ...@@ -72,7 +72,7 @@ block_repeat_failures(struct tlist_calls *history)
{ {
const struct failtest_call *last; const struct failtest_call *last;
last = tlist_tail(history, struct failtest_call, list); last = tlist_tail(history, list);
if (failtest_suppress) if (failtest_suppress)
return FAIL_DONT_FAIL; return FAIL_DONT_FAIL;
......
...@@ -16,21 +16,16 @@ int main(int argc, char *argv[]) ...@@ -16,21 +16,16 @@ int main(int argc, char *argv[])
{ {
struct tlist_children children; struct tlist_children children;
struct child child = { "child" }; struct child child = { "child" };
void *c; #ifdef FAIL
struct cousin *c;
#else
struct child *c;
#endif
tlist_init(&children); tlist_init(&children);
tlist_add(&children, &child, list); tlist_add(&children, &child, list);
c = tlist_tail(&children, c = tlist_tail(&children, list);
#ifdef FAIL
#if !HAVE_FLEXIBLE_ARRAY_MEMBER
#error Need flexible array members to check type
#endif
struct cousin,
#else
struct child,
#endif
list);
(void) c; /* Suppress unused-but-set-variable warning. */ (void) c; /* Suppress unused-but-set-variable warning. */
return 0; return 0;
} }
...@@ -16,21 +16,16 @@ int main(int argc, char *argv[]) ...@@ -16,21 +16,16 @@ int main(int argc, char *argv[])
{ {
struct tlist_children children; struct tlist_children children;
struct child child = { "child" }; struct child child = { "child" };
void *c; #ifdef FAIL
struct cousin *c;
#else
struct child *c;
#endif
tlist_init(&children); tlist_init(&children);
tlist_add(&children, &child, list); tlist_add(&children, &child, list);
c = tlist_top(&children, c = tlist_top(&children, list);
#ifdef FAIL
#if !HAVE_FLEXIBLE_ARRAY_MEMBER
#error Need flexible array members to check type
#endif
struct cousin,
#else
struct child,
#endif
list);
(void) c; /* Suppress unused-but-set-variable warning. */ (void) c; /* Suppress unused-but-set-variable warning. */
return 0; return 0;
} }
...@@ -73,10 +73,10 @@ int main(int argc, char *argv[]) ...@@ -73,10 +73,10 @@ int main(int argc, char *argv[])
ok1(tlist_check(&parent.children, NULL)); ok1(tlist_check(&parent.children, NULL));
/* Test tlist_top */ /* Test tlist_top */
ok1(tlist_top(&parent.children, struct child, list) == &c1); ok1(tlist_top(&parent.children, list) == &c1);
/* Test list_tail */ /* Test list_tail */
ok1(tlist_tail(&parent.children, struct child, list) == &c3); ok1(tlist_tail(&parent.children, list) == &c3);
/* Test tlist_for_each. */ /* Test tlist_for_each. */
i = 0; i = 0;
...@@ -141,7 +141,7 @@ int main(int argc, char *argv[]) ...@@ -141,7 +141,7 @@ int main(int argc, char *argv[])
ok1(tlist_empty(&parent.children)); ok1(tlist_empty(&parent.children));
/* Test list_top/list_tail on empty list. */ /* Test list_top/list_tail on empty list. */
ok1(tlist_top(&parent.children, struct child, list) == NULL); ok1(tlist_top(&parent.children, list) == (struct child *)NULL);
ok1(tlist_tail(&parent.children, struct child, list) == NULL); ok1(tlist_tail(&parent.children, list) == (struct child *)NULL);
return exit_status(); return exit_status();
} }
...@@ -178,32 +178,36 @@ ...@@ -178,32 +178,36 @@
/** /**
* tlist_top - get the first entry in a list * tlist_top - get the first entry in a list
* @h: the tlist * @h: the tlist
* @type: the type of the entry
* @member: the list_node member of the type * @member: the list_node member of the type
* *
* If the list is empty, returns NULL. * If the list is empty, returns NULL.
* *
* Example: * Example:
* struct child *first; * struct child *first;
* first = tlist_top(&parent->children, struct child, list); * first = tlist_top(&parent->children, list);
*/ */
#define tlist_top(h, type, member) \ #define tlist_top(h, member) \
list_top(tlist_raw((h), (type *)NULL), type, member) ((tcon_type((h), canary)) \
list_top_(&(h)->raw, \
(char *)(&(h)->_tcon[0].canary->member) - \
(char *)((h)->_tcon[0].canary)))
/** /**
* tlist_tail - get the last entry in a list * tlist_tail - get the last entry in a list
* @h: the tlist * @h: the tlist
* @type: the type of the entry
* @member: the list_node member of the type * @member: the list_node member of the type
* *
* If the list is empty, returns NULL. * If the list is empty, returns NULL.
* *
* Example: * Example:
* struct child *last; * struct child *last;
* last = tlist_tail(&parent->children, struct child, list); * last = tlist_tail(&parent->children, list);
*/ */
#define tlist_tail(h, type, member) \ #define tlist_tail(h, member) \
list_tail(tlist_raw((h), (type *)NULL), type, member) ((tcon_type((h), canary)) \
list_tail_(&(h)->raw, \
(char *)(&(h)->_tcon[0].canary->member) - \
(char *)((h)->_tcon[0].canary)))
/** /**
* tlist_for_each - iterate through a list. * tlist_for_each - iterate through a list.
......
...@@ -48,7 +48,7 @@ static void run_more(void) ...@@ -48,7 +48,7 @@ static void run_more(void)
while (num_running < lbalance_target(lb)) { while (num_running < lbalance_target(lb)) {
int p[2]; int p[2];
c = tlist_top(&pending, struct command, list); c = tlist_top(&pending, list);
if (!c) if (!c)
break; break;
...@@ -189,7 +189,7 @@ void *collect_command(bool *ok, char **output) ...@@ -189,7 +189,7 @@ void *collect_command(bool *ok, char **output)
struct command *c; struct command *c;
const void *ctx; const void *ctx;
while ((c = tlist_top(&done, struct command, list)) == NULL) { while ((c = tlist_top(&done, list)) == NULL) {
if (tlist_empty(&pending) && tlist_empty(&running)) if (tlist_empty(&pending) && tlist_empty(&running))
return NULL; return NULL;
reap_output(); reap_output();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment