Date: Wed, 18 Feb 2004 14:14:00 -0500 From: John Baldwin <jhb@FreeBSD.org> To: Marcel Moolenaar <marcel@xcllnt.net> Cc: Jun Kuriyama <kuriyama@imgsrc.co.jp> Subject: Re: cvs commit: src/sys/alpha/alpha support.s src/sys/i386/i386 swtch.s src/sys/kern kern_shutdown.c src/sys/sys systm.h Message-ID: <200402181414.01381.jhb@FreeBSD.org> In-Reply-To: <20040218174059.GC7878@ns1.xcllnt.net> References: <200401192127.i0JLRBL3041817@repoman.freebsd.org> <200402180839.09285.jhb@FreeBSD.org> <20040218174059.GC7878@ns1.xcllnt.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday 18 February 2004 12:40 pm, Marcel Moolenaar wrote: > On Wed, Feb 18, 2004 at 08:39:09AM -0500, John Baldwin wrote: > > Use MPASS() (macros that came in with SMPng from BSD/OS). MPASS(foo) > > will work much like assert() in userland including file/line number info. > > I use it a lot for simple != NULL tests and the like. > > I like the behaviour of MPASS(), just not its name and the fact it's > defined in lock.h. If we can call it ASSERT and move its definition > to systm.h, then I'm hooked. I have wanted to have a better name for it and it's associated friends (MPASS2, MPASS3, MPASS4). KASSERT() really is a good name, and perhaps what we should do is replace MPASS/KASSERT() with something like this: KASSERT(condition) (just asserts a condition like MPASS does now) KASSERTV(condition, printf args) (verbose assertion, has its own message) These could perhaps output the current file and line, but then you have the problem of things like the mutex code that pass around file and line info to give more relevant file and line numbers (and hence the MPASS3() and MPASS4() macros that BSD/OS provides). If you want to preserve that, perhaps one could add: KASSERTL(condition, file, line) KASSERTLV(condition, file, line, printf args) Thus, you have: #define KASSERT(condition) KASSERTL(condition, __FILE__, __LINE__) #define KASSERTV(condition, ...) KASSERTLV(condition, __FILE__, __LINE__, \ __VA_ARGS__) #define KASSERTL(condition, file, line) KASSERTLV(condition, file, line, \ "%s", __STRING(condition)) #define KASSERTLV(condition, file, line, ...) do { \ if (!(condition)) { \ printf("Assertion \""); \ printf(__VA_ARGS__); \ printf("\" failed at %s:%d\n", file, line); \ } \ } while(0) Even nicer might be to make fixup_filename() from subr_witness.c a global #ifdef INVARIANTS_SUPPORT and have KASSERTLV() use that (it trims any (../)* from the front of a filename to improve readability of messages by just returning a char * pointer farther along in the string). If ASSERT() is preferred to KASSERT() that would certain ease the transition to the different macros. -- John Baldwin <jhb@FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200402181414.01381.jhb>