From: Sasha Levin <levinsasha928@gmail.com>
To: torvalds@linux-foundation.org, akpm@linux-foundation.org,
peterz@infradead.org, mingo@elte.hu, hpa@zytor.com,
tglx@linutronix.de, srivatsa.bhat@linux.vnet.ibm.com
Cc: linux-kernel@vger.kernel.org, Sasha Levin <levinsasha928@gmail.com>
Subject: [RFC 1/3] typecheck: extend typecheck.h with more useful typechecking macros
Date: Sat, 14 Apr 2012 18:14:43 -0400 [thread overview]
Message-ID: <1334441685-4438-2-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1334441685-4438-1-git-send-email-levinsasha928@gmail.com>
Add macros to compare multiple parameters to a given type, and macros to
compare multiple parameters between themselves.
Signed-off-by: Sasha Levin <levinsasha928@gmail.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
next prev parent reply other threads:[~2012-04-14 19:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-14 22:14 [RFC 0/3] Extend type checking macros Sasha Levin
2012-04-14 21:02 ` Peter Zijlstra
2012-04-14 21:18 ` Srivatsa S. Bhat
2012-04-14 22:31 ` Srivatsa S. Bhat
2012-04-14 22:14 ` Sasha Levin [this message]
2012-04-14 21:12 ` [RFC 1/3] typecheck: extend typecheck.h with more useful typechecking macros Linus Torvalds
2012-04-14 22:14 ` [RFC 2/3] sched: add type checks to for_each_cpu_mask() Sasha Levin
2012-04-14 21:15 ` Linus Torvalds
2012-04-20 22:33 ` Andrew Morton
2012-04-14 22:14 ` [RFC 3/3] kernel.h: use new typechecking macros in min()/max() and friends Sasha Levin
2012-04-14 21:01 ` Peter Zijlstra
2012-04-14 21:17 ` Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1334441685-4438-2-git-send-email-levinsasha928@gmail.com \
--to=levinsasha928@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome