Re: [PATCH] *(int*)0 = 0 & variations

Stefan Monnier (monnier+lists/linux/kernel/news/@tequila.cs.yale.edu)
24 Jun 1999 14:06:12 -0400


>>>>> "Jeff" == Jeff Garzik <jgarzik@pobox.com> writes:
> AC posted in this thread, saying that assert code already exists in the
> kernel, in the networking code (grep for BUG_TRAP). Guess what? It
> evaluates to null. In fact, grepping around, every assert macro I could
> find in the kernel (not many, granted) evaluates to null in its
> non-debug form.

I completely agree. The only reason why people want the expr to be evaluated
in the no-debug case is that some broken kasserts might have side effects.
This argument is specious: fix the asserts. One way to make such
broken asserts a bit easier to find is to do something like

#define kassert(cond) \
if ((cond) && ((cond) == (cond))) {} else {burp}

It doesn't catch all cases, far from that, but has the advantage of only
slowing down the debug case. There could be several kassert behaviors (even
changeable at run time):

- default: just do the check and print any error
- no debug: replace kassert with (void)0
- debug asserts: use the multiple-eval trick above to increase the chances
of catching buggy asserts.

and orthogonal to that, you could choose whether to oops/panic/donothing
in case of an actual failure.

Stefan

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