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)
{
struct failtest_call *i;
while ((i = tlist_top(&history, struct failtest_call, list)) != NULL)
while ((i = tlist_top(&history, list)) != NULL)
free_call(i);
failtable_clear(&failtable);
......@@ -755,7 +755,7 @@ static bool should_fail(struct failtest_call *call)
char *failpath;
struct failtest_call *c;
c = tlist_tail(&history, struct failtest_call, list);
c = tlist_tail(&history, list);
diff = time_sub(time_now(), start);
failpath = failpath_string();
p = strrchr(c->file, '/');
......@@ -770,8 +770,7 @@ static bool should_fail(struct failtest_call *call)
free(failpath);
}
/* From here on, we have to clean up! */
our_history_start = tlist_tail(&history, struct failtest_call,
list);
our_history_start = tlist_tail(&history, list);
close(control[0]);
close(output[0]);
/* Don't swallow stderr if we're tracing. */
......
......@@ -214,7 +214,7 @@ enum failtest_result {
* static enum failtest_result dont_fail_alloc(struct tlist_calls *history)
* {
* struct failtest_call *call;
* call = tlist_tail(history, struct failtest_call, list);
* call = tlist_tail(history, list);
* if (call->type == FAILTEST_MALLOC
* || call->type == FAILTEST_CALLOC
* || call->type == FAILTEST_REALLOC)
......
......@@ -315,7 +315,7 @@ void lbalance_free(struct lbalance *lb)
{
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);
tlist_del_from(&lb->tasks, task, list);
lb->num_tasks--;
......
......@@ -72,7 +72,7 @@ block_repeat_failures(struct tlist_calls *history)
{
const struct failtest_call *last;
last = tlist_tail(history, struct failtest_call, list);
last = tlist_tail(history, list);
if (failtest_suppress)
return FAIL_DONT_FAIL;
......
......@@ -16,21 +16,16 @@ int main(int argc, char *argv[])
{
struct tlist_children children;
struct child child = { "child" };
void *c;
#ifdef FAIL
struct cousin *c;
#else
struct child *c;
#endif
tlist_init(&children);
tlist_add(&children, &child, list);
c = tlist_tail(&children,
#ifdef FAIL
#if !HAVE_FLEXIBLE_ARRAY_MEMBER
#error Need flexible array members to check type
#endif
struct cousin,
#else
struct child,
#endif
list);
c = tlist_tail(&children, list);
(void) c; /* Suppress unused-but-set-variable warning. */
return 0;
}
......@@ -16,21 +16,16 @@ int main(int argc, char *argv[])
{
struct tlist_children children;
struct child child = { "child" };
void *c;
#ifdef FAIL
struct cousin *c;
#else
struct child *c;
#endif
tlist_init(&children);
tlist_add(&children, &child, list);
c = tlist_top(&children,
#ifdef FAIL
#if !HAVE_FLEXIBLE_ARRAY_MEMBER
#error Need flexible array members to check type
#endif
struct cousin,
#else
struct child,
#endif
list);
c = tlist_top(&children, list);
(void) c; /* Suppress unused-but-set-variable warning. */
return 0;
}
......@@ -73,10 +73,10 @@ int main(int argc, char *argv[])
ok1(tlist_check(&parent.children, NULL));
/* Test tlist_top */
ok1(tlist_top(&parent.children, struct child, list) == &c1);
ok1(tlist_top(&parent.children, list) == &c1);
/* Test list_tail */
ok1(tlist_tail(&parent.children, struct child, list) == &c3);
ok1(tlist_tail(&parent.children, list) == &c3);
/* Test tlist_for_each. */
i = 0;
......@@ -141,7 +141,7 @@ int main(int argc, char *argv[])
ok1(tlist_empty(&parent.children));
/* Test list_top/list_tail on empty list. */
ok1(tlist_top(&parent.children, struct child, list) == NULL);
ok1(tlist_tail(&parent.children, struct child, list) == NULL);
ok1(tlist_top(&parent.children, list) == (struct child *)NULL);
ok1(tlist_tail(&parent.children, list) == (struct child *)NULL);
return exit_status();
}
......@@ -178,32 +178,36 @@
/**
* tlist_top - get the first entry in a list
* @h: the tlist
* @type: the type of the entry
* @member: the list_node member of the type
*
* If the list is empty, returns NULL.
*
* Example:
* struct child *first;
* first = tlist_top(&parent->children, struct child, list);
* first = tlist_top(&parent->children, list);
*/
#define tlist_top(h, type, member) \
list_top(tlist_raw((h), (type *)NULL), type, member)
#define tlist_top(h, 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
* @h: the tlist
* @type: the type of the entry
* @member: the list_node member of the type
*
* If the list is empty, returns NULL.
*
* Example:
* struct child *last;
* last = tlist_tail(&parent->children, struct child, list);
* last = tlist_tail(&parent->children, list);
*/
#define tlist_tail(h, type, member) \
list_tail(tlist_raw((h), (type *)NULL), type, member)
#define tlist_tail(h, 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.
......
......@@ -48,7 +48,7 @@ static void run_more(void)
while (num_running < lbalance_target(lb)) {
int p[2];
c = tlist_top(&pending, struct command, list);
c = tlist_top(&pending, list);
if (!c)
break;
......@@ -189,7 +189,7 @@ void *collect_command(bool *ok, char **output)
struct command *c;
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))
return NULL;
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