X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftlist%2Ftlist.h;h=9f62869b2b19c23c3fcb812ed2a6420a45a847a7;hp=82471d67a0bf091869f65df4f2002703d64c27e0;hb=5c559e7df1d31b4c0ddf26451fac972dc8a0c2c9;hpb=c89f34afdc6c2a98c75130470ea0b7f531a3cfe0 diff --git a/ccan/tlist/tlist.h b/ccan/tlist/tlist.h index 82471d67..9f62869b 100644 --- a/ccan/tlist/tlist.h +++ b/ccan/tlist/tlist.h @@ -1,8 +1,9 @@ +/* Licensed under LGPL - see LICENSE file for details */ #ifndef CCAN_TLIST_H #define CCAN_TLIST_H #include +#include -#if HAVE_FLEXIBLE_ARRAY_MEMBER /** * TLIST_TYPE - declare a typed list type (struct tlist) * @suffix: the name to use (struct tlist_@suffix) @@ -26,31 +27,12 @@ * struct list_node list; * }; */ -#define TLIST_TYPE(suffix, type) \ - struct tlist_##suffix { \ - struct list_head raw; \ - const type *tcheck[]; \ +#define TLIST_TYPE(suffix, type) \ + struct tlist_##suffix { \ + struct list_head raw; \ + TCON(type *canary); \ } -/** - * tlist_raw - access the raw list inside a typed list head. - * @h: the head of the typed list (struct tlist_@suffix) - * @test_var: a pointer to the expected element type. - * - * This elaborate macro usually causes the compiler to emit a warning - * if the variable is of an unexpected type. It is used internally - * where we need to access the raw underlying list. - */ -#define tlist_raw(h, test_var) \ - (sizeof((h)->tcheck[0] == (test_var)) ? &(h)->raw : &(h)->raw) -#else -#define TLIST_TYPE(suffix, type) \ - struct tlist_##suffix { \ - struct list_head raw; \ - } -#define tlist_raw(h, test_var) (&(h)->raw) -#endif - /** * TLIST_INIT - initalizer for an empty tlist * @name: the name of the list. @@ -107,6 +89,17 @@ */ #define tlist_init(h) list_head_init(&(h)->raw) +/** + * tlist_raw - unwrap the typed list and check the type + * @h: the tlist + * @expr: the expression to check the type against (not evaluated) + * + * This macro usually causes the compiler to emit a warning if the + * variable is of an unexpected type. It is used internally where we + * need to access the raw underlying list. + */ +#define tlist_raw(h, expr) (&tcon_check((h), canary, (expr))->raw) + /** * tlist_add - add an entry at the start of a linked list. * @h: the tlist to add the node to