[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    Re: kernel assertions
From:       Poul-Henning Kamp <phk () critter ! tfs ! com>
Date:       1996-07-29 13:43:16
[Download RAW message or body]

>Any comments on introducing an assertion macro for kernel code that panics
>if the expression is false and does nothing otherwise.  It would also be
>very cool to preprocess it out with something like a -NDEBUG flag.  It
>could be called KASSERT or KERN_ASSERT.

I like this idea.

How about:

in <sys/cdefs.h> we put:

	#if defined(DIAGNOSTIC) || defined(WITH_ASSERTS)
	#define ASSERT(cond, expl) if (cond) panic expl ; else ;
	#else 
	#define ASSERT(cond, expl) /* nothing */
	#endif


In our code:
	void
	foo(char *buf, int i
	{
		ASSERT(buf,("foo(%p, %d): buf is zero",buf,i));
		...
	}

--
Poul-Henning Kamp           | phk@FreeBSD.ORG       FreeBSD Core-team.
http://www.freebsd.org/~phk | phk@login.dknet.dk    Private mailbox.
whois: [PHK]                | phk@ref.tfs.com       TRW Financial Systems, Inc.
Future will arrive by its own means, progress not so.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic