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
3dda2c8b
Commit
3dda2c8b
authored
Sep 28, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tcon: more help, for making strmap.
parent
95757f0e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
7 deletions
+39
-7
ccan/tcon/tcon.h
ccan/tcon/tcon.h
+39
-7
No files found.
ccan/tcon/tcon.h
View file @
3dda2c8b
...
...
@@ -61,6 +61,43 @@
#define tcon_check(x, canary, expr) \
(sizeof((x)->_tcon[0].canary == (expr)) ? (x) : (x))
/**
* tcon_check_ptr - typecheck a typed container
* @x: the structure containing the TCON.
* @canary: which canary to check against.
* @expr: the expression whose type must match &TCON (not evaluated)
*
* This macro is used to check that the expression is a pointer to the type
* expected for this structure (note the "useless" sizeof() argument
* which contains this comparison with the type canary), or NULL.
*
* It evaluates to @x so you can chain it.
*/
#define tcon_check_ptr(x, canary, expr) \
(sizeof(&(x)->_tcon[0].canary == (expr)) ? (x) : (x))
/**
* tcon_type - the type within a container (or void *)
* @x: the structure containing the TCON.
* @canary: which canary to check against.
*/
#if HAVE_TYPEOF
#define tcon_type(x, canary) __typeof__((x)->_tcon[0].canary)
#else
#define tcon_type(x, canary) void *
#endif
/**
* tcon_ptr_type - pointer to the type within a container (or void *)
* @x: the structure containing the TCON.
* @canary: which canary to check against.
*/
#if HAVE_TYPEOF
#define tcon_ptr_type(x, canary) __typeof__(&(x)->_tcon[0].canary)
#else
#define tcon_ptr_type(x, canary) void *
#endif
/**
* tcon_cast - cast to a canary type for this container (or void *)
...
...
@@ -72,12 +109,7 @@
* platform doesn't HAVE_TYPEOF, then it casts to void * (which will
* cause a warning if the user doesn't expect a pointer type).
*/
#if HAVE_TYPEOF
#define tcon_cast(x, canary, expr) ((__typeof__((x)->_tcon[0].canary))(expr))
#define tcon_cast_ptr(x, canary, expr) ((__typeof__(&(x)->_tcon[0].canary))(expr))
#else
#define tcon_cast(x, canary, expr) ((void *)(expr))
#define tcon_cast_ptr(x, canary, expr) ((void *)(expr))
#endif
#define tcon_cast(x, canary, expr) ((tcon_type((x), canary))(expr))
#define tcon_cast_ptr(x, canary, expr) ((tcon_ptr_type((x), canary))(expr))
#endif
/* CCAN_TCON_H */
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