From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26190 invoked from network); 26 Nov 2023 22:39:37 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 26 Nov 2023 22:39:37 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 9front; Sun Nov 26 17:36:33 -0500 2023 Received: from abbatoir (pool-108-6-24-2.nycmny.fios.verizon.net [108.6.24.2]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 7f8b7115 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Sun, 26 Nov 2023 14:36:30 -0800 (PST) Message-ID: <56683B0AF4B13786B312FE99958B452B@eigenstate.org> To: 9front@9front.org Date: Sun, 26 Nov 2023 17:36:28 -0500 From: ori@eigenstate.org In-Reply-To: <904397cf-6c3f-46c4-9139-7f80823ec064@invalid.invalid> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: progressive generic framework blockchain shader Subject: Re: [9front] [PATCH] Fix assert macro to not break on commas Reply-To: 9front@9front.org Precedence: bulk Quoth Blue-Maned_Hawk : > This is a pair of patches that changes the assert macro to be variadic, > allowing expressions with commas in them to be used without needing a > spare pair of parentheses, and updates the manpage accordingly. Alternative proposal. This prints the pid, which means you can now get a full stack trace trivially with: lstk $pid and plumb the paths into your editor, instead of getting a pretty dumb context-free copy of the expression that failed. diff 276c090a9536c0165d10d908862a93e743d3b344 uncommitted --- a/sys/include/libc.h +++ b/sys/include/libc.h @@ -3,7 +3,6 @@ #define nelem(x) (sizeof(x)/sizeof((x)[0])) #define offsetof(s, m) (ulong)(&(((s*)0)->m)) -#define assert(x) if(x){}else _assert("x") /* * mem routines @@ -384,7 +383,7 @@ PNGROUP = 2, }; -extern void _assert(char*); +extern void assert(int); extern int abs(int); extern int atexit(void(*)(void)); extern void atexitdont(void(*)(void)); --- a/sys/man/2/assert +++ b/sys/man/2/assert @@ -6,17 +6,12 @@ .br .B #include .PP -.B -#define assert(cond) if(cond);else _assert("cond") +.B void assert(int cond) .PP .B -void _assert(char* cond) .SH DESCRIPTION .I Assert -is a preprocessor macro that -(via -.IR _assert ) -prints a message and calls +is a function that prints the current process id and calls .I abort when .I cond --- a/sys/src/libc/port/_assert.c +++ b/sys/src/libc/port/_assert.c @@ -1,13 +1,13 @@ #include #include -void (*__assert)(char*); +void (*__assert)(int); void -_assert(char *s) +assert(int cond) { - if(__assert) - (*__assert)(s); - fprint(2, "assert failed: %s\n", s); + if(cond) + return; + fprint(2, "pid %d: assert failed\n", getpid()); abort(); } --- a/sys/src/libthread/debug.c +++ b/sys/src/libthread/debug.c @@ -29,10 +29,3 @@ fmtprint(&f, "\n"); fmtfdflush(&f); } - -void -_threadassert(char *s) -{ - _threadprint("%s: assertion failed", s); - abort(); -}