tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Convenience macros to help linting the kernel
We have too much ad-hoc code like
#define KERNEL_LOCK(count, lwp) do {(void)(count); (void)(lwp);} while
(/* CONSTCOND */ 0) /*NOP*/
or
#define mowner_init(m, type) do { } while (/* CONSTCOND */ 0)
and the like. I propose to add the following convenience macros to
sys/cdefs.h so that macros like above can be written uniformly and in
a lint-safe way.
Thoughts?
SY, Uwe
--
uwe%stderr.spb.ru@localhost | Zu Grunde kommen
http://snark.ptc.spbu.ru/~uwe/ | Ist zu Grunde gehen
Index: cdefs.h
===================================================================
RCS file: /cvsroot/src/sys/sys/cdefs.h,v
retrieving revision 1.68
diff -u -u -r1.68 cdefs.h
--- cdefs.h 27 Jun 2008 01:24:52 -0000 1.68
+++ cdefs.h 20 Jul 2008 02:35:01 -0000
@@ -253,6 +253,30 @@
#endif
#endif /* !(__STDC_VERSION__ >= 199901L) */
+/*
+ * Statement that does nothing. Convenient as an expansion for
+ * conditionally defined macros that do nothing under some combination
+ * of defines (e.g. DPRINTF(...) for !DEBUG).
+ */
+#define __NOP__ do {} while (/* CONSTCOND */ 0)
+
+/*
+ * Expression that does nothing. Suitable for comma expressions.
+ * Convenient as an expansion for conditionally defined macros that do
+ * nothing under some combination of defines (e.g. for !DEBUG case of
+ * checks inlined into an expression as lhs of comma operator).
+ */
+#define __NOP_EXPR__ ({ /* LINTED: expression has null effect */ (void) 0; })
+
+/*
+ * Statement that safely consumes something so that if "x" is a
+ * variable it is not considered "unused" by the compiler or lint.
+ */
+#define __USED(x) do { \
+ /* LINTED: expression has null effect */ \
+ (void)(x); \
+ } while (/* CONSTCOND */ 0)
+
#if defined(_KERNEL)
#if defined(NO_KERNEL_RCSIDS)
#undef __KERNEL_RCSID
Home |
Main Index |
Thread Index |
Old Index