[RFC 1/3] typecheck: extend typecheck.h with more useful typechecking macros

From: Sasha Levin
Date: Sat Apr 14 2012 - 15:15:48 EST


Add macros to compare multiple parameters to a given type, and macros to
compare multiple parameters between themselves.

Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
---
include/linux/typecheck.h | 42 ++++++++++++++++++++++++++++++++++--------
1 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/include/linux/typecheck.h b/include/linux/typecheck.h
index eb5b74a..a495dcb 100644
--- a/include/linux/typecheck.h
+++ b/include/linux/typecheck.h
@@ -5,20 +5,46 @@
* Check at compile time that something is of a particular type.
* Always evaluates to 1 so you may use it easily in comparisons.
*/
-#define typecheck(type,x) \
-({ type __dummy; \
- typeof(x) __dummy2; \
- (void)(&__dummy == &__dummy2); \
- 1; \
+#define typecheck(type,x) \
+({ type __dummy; \
+ typeof(x) __dummy2; \
+ (void)(&__dummy == &__dummy2); \
+ 1; \
+})
+
+#define typecheck2(type,x,y) \
+({ typecheck(type, x); \
+ typecheck(type, y); \
+ 1; \
+})
+
+#define typecheck3(type,x,y,z) \
+({ typecheck2(type,x,y); \
+ typecheck(type,z); \
+ 1; \
+})
+
+#define typecmp2(x,y) \
+({ typeof(x) __x = (x); \
+ typeof(y) __y = (y); \
+ typecheck(typeof(x),x); \
+ typecheck(typeof(y),y); \
+ (void)(&__x==&__y); \
+ 1; \
+})
+
+#define typecmp3(x,y,z) \
+({ typecmp2((x),(y)); \
+ typecmp2((x),(z)); \
})

/*
* Check at compile time that 'function' is a certain type, or is a pointer
* to that type (needs to use typedef for the function type.)
*/
-#define typecheck_fn(type,function) \
-({ typeof(type) __tmp = function; \
- (void)__tmp; \
+#define typecheck_fn(type,function) \
+({ typeof(type) __tmp = function; \
+ (void)__tmp; \
})

#endif /* TYPECHECK_H_INCLUDED */
--
1.7.8.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/