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
51711449
Commit
51711449
authored
Sep 30, 2009
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
typesafe_cb: more support for typesafe compare functions.
parent
f66bb62a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
ccan/typesafe_cb/typesafe_cb.h
ccan/typesafe_cb/typesafe_cb.h
+46
-0
No files found.
ccan/typesafe_cb/typesafe_cb.h
View file @
51711449
...
...
@@ -63,6 +63,28 @@ __builtin_choose_expr(__builtin_types_compatible_p(typeof(1?(expr):0), oktype),
rtype (*)(typeof(arg)), \
rtype (*)(void *))
/**
* typesafe_cb_const - cast a const callback function if it matches the arg
* @rtype: the return type of the callback function
* @fn: the callback function to cast
* @arg: the (pointer) argument to hand to the callback function.
*
* If a callback function takes a single argument, this macro does appropriate
* casts to a function which takes a single const void * argument if the
* callback provided matches the @arg.
*
* It is assumed that @arg is of pointer type: usually @arg is passed
* or assigned to a void * elsewhere anyway.
*
* Example:
* void _register_callback(void (*fn)(const void *arg), const void *arg);
* #define register_callback(fn, arg) \
* _register_callback(typesafe_cb_const(void, (fn), (arg)), (arg))
*/
#define typesafe_cb_const(rtype, fn, arg) \
cast_if_type((fn), \
rtype (*)(const typeof(*arg)*), rtype (*)(const void *))
/**
* typesafe_cb_preargs - cast a callback function if it matches the arg
* @rtype: the return type of the callback function
...
...
@@ -117,4 +139,28 @@ __builtin_choose_expr(__builtin_types_compatible_p(typeof(1?(expr):0), oktype),
rtype (*)(typeof(arg), __VA_ARGS__), \
rtype (*)(void *, __VA_ARGS__))
/**
* typesafe_cb_cmp - cast a compare function if it matches the arg
* @rtype: the return type of the callback function
* @fn: the callback function to cast
* @arg: the (pointer) argument(s) to hand to the compare function.
*
* If a callback function takes two matching-type arguments, this macro does
* appropriate casts to a function which takes two const void * arguments if
* the callback provided takes two a const pointers to @arg.
*
* It is assumed that @arg is of pointer type: usually @arg is passed
* or assigned to a void * elsewhere anyway.
*
* Example:
* void _my_qsort(void *base, size_t nmemb, size_t size,
* int (*cmp)(const void *, const void *));
* #define my_qsort(base, nmemb, cmpfn) \
* _my_qsort((base), (nmemb), sizeof(*(base)), \
* typesafe_cb_cmp(int, (cmpfn), (base)), (arg))
*/
#define typesafe_cb_cmp(rtype, cmpfn, arg) \
cast_if_type((cmpfn), \
rtype (*)(const typeof(*arg)*, const typeof(*arg)*), \
rtype (*)(const void *, const void *))
#endif
/* CCAN_CAST_IF_TYPE_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