Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
be2b5277
Commit
be2b5277
authored
Sep 23, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tlist: use ccan/tcon
No real change for users.
parent
5c451bbb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
29 deletions
+22
-29
ccan/tlist/_info
ccan/tlist/_info
+6
-5
ccan/tlist/tlist.h
ccan/tlist/tlist.h
+16
-24
No files found.
ccan/tlist/_info
View file @
be2b5277
...
...
@@ -9,17 +9,17 @@
* this extends it so you can create list head types which only accomodate
* a specific entry type.
*
* You use TLIST_TYPE() to define the specific struct tlist_<name>, then use
* the tlist_* variants of the various list_* operations.
*
* Example:
* #include <err.h>
* #include <stdio.h>
* #include <stdlib.h>
* #include <ccan/tlist/tlist.h>
*
* // Defines struct tlist_children
* TLIST_TYPE(children, struct child);
* // We could use TLIST_TYPE(children, struct child) to define this.
* struct tlist_children {
* struct list_head raw;
* TCON(struct child *canary);
* };
* struct parent {
* const char *name;
* struct tlist_children children;
...
...
@@ -66,6 +66,7 @@ int main(int argc, char *argv[])
if (strcmp(argv[1], "depends") == 0) {
printf("ccan/list\n");
printf("ccan/tcon\n");
return 0;
}
...
...
ccan/tlist/tlist.h
View file @
be2b5277
...
...
@@ -2,8 +2,8 @@
#ifndef CCAN_TLIST_H
#define CCAN_TLIST_H
#include <ccan/list/list.h>
#include <ccan/tcon/tcon.h>
#if HAVE_FLEXIBLE_ARRAY_MEMBER
/**
* TLIST_TYPE - declare a typed list type (struct tlist)
* @suffix: the name to use (struct tlist_@suffix)
...
...
@@ -27,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.
...
...
@@ -108,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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment