summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-12-01 16:39:47 +1030
committerRusty Russell <rusty@rustcorp.com.au>2011-12-01 16:39:47 +1030
commita6b5111fe6948e51114c33aa34785c9fd0d403e6 (patch)
tree370d407b7856ead68d1d38898ba3d5bbde99cca4
parentc1e57dbfbd00dee590ab0403763796bff0e2eb2e (diff)
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.
-rw-r--r--ccan/failtest/failtest.c7
-rw-r--r--ccan/failtest/failtest.h2
-rw-r--r--ccan/lbalance/lbalance.c2
-rw-r--r--ccan/tdb2/test/failtest_helper.c2
-rw-r--r--ccan/tlist/test/compile_fail-tlist_tail.c17
-rw-r--r--ccan/tlist/test/compile_fail-tlist_top.c17
-rw-r--r--ccan/tlist/test/run.c8
-rw-r--r--ccan/tlist/tlist.h20
-rw-r--r--tools/ccanlint/async.c4
9 files changed, 36 insertions, 43 deletions
diff --git a/ccan/failtest/failtest.c b/ccan/failtest/failtest.c
index 97bcb62c..215ebfab 100644
--- a/ccan/failtest/failtest.c
+++ b/ccan/failtest/failtest.c
@@ -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. */
diff --git a/ccan/failtest/failtest.h b/ccan/failtest/failtest.h
index 5c80bfee..9af56696 100644
--- a/ccan/failtest/failtest.h
+++ b/ccan/failtest/failtest.h
@@ -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)
diff --git a/ccan/lbalance/lbalance.c b/ccan/lbalance/lbalance.c
index d3763a3f..a350c81d 100644
--- a/ccan/lbalance/lbalance.c
+++ b/ccan/lbalance/lbalance.c
@@ -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--;
diff --git a/ccan/tdb2/test/failtest_helper.c b/ccan/tdb2/test/failtest_helper.c
index 3172e3ad..ab79de19 100644
--- a/ccan/tdb2/test/failtest_helper.c
+++ b/ccan/tdb2/test/failtest_helper.c
@@ -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;
diff --git a/ccan/tlist/test/compile_fail-tlist_tail.c b/ccan/tlist/test/compile_fail-tlist_tail.c
index 0a9dabac..48f39444 100644
--- a/ccan/tlist/test/compile_fail-tlist_tail.c
+++ b/ccan/tlist/test/compile_fail-tlist_tail.c
@@ -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;
}
diff --git a/ccan/tlist/test/compile_fail-tlist_top.c b/ccan/tlist/test/compile_fail-tlist_top.c
index d02c3add..21651400 100644
--- a/ccan/tlist/test/compile_fail-tlist_top.c
+++ b/ccan/tlist/test/compile_fail-tlist_top.c
@@ -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;
}
diff --git a/ccan/tlist/test/run.c b/ccan/tlist/test/run.c
index 027028e6..f94438ea 100644
--- a/ccan/tlist/test/run.c
+++ b/ccan/tlist/test/run.c
@@ -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();
}
diff --git a/ccan/tlist/tlist.h b/ccan/tlist/tlist.h
index 3576146c..1ce0b85e 100644
--- a/ccan/tlist/tlist.h
+++ b/ccan/tlist/tlist.h
@@ -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.
diff --git a/tools/ccanlint/async.c b/tools/ccanlint/async.c
index e12e140d..4f51dd62 100644
--- a/tools/ccanlint/async.c
+++ b/tools/ccanlint/async.c
@@ -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();