[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1334441685-4438-2-git-send-email-levinsasha928@gmail.com>
Date: Sat, 14 Apr 2012 18:14:43 -0400
From: Sasha Levin <levinsasha928@...il.com>
To: torvalds@...ux-foundation.org, akpm@...ux-foundation.org,
peterz@...radead.org, mingo@...e.hu, hpa@...or.com,
tglx@...utronix.de, srivatsa.bhat@...ux.vnet.ibm.com
Cc: linux-kernel@...r.kernel.org, Sasha Levin <levinsasha928@...il.com>
Subject: [RFC 1/3] typecheck: extend typecheck.h with more useful typechecking macros
Add macros to compare multiple parameters to a given type, and macros to
compare multiple parameters between themselves.
Signed-off-by: Sasha Levin <levinsasha928@...il.com>
---
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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists