9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: Re: [9front] [PATCH] Fix assert macro to not break on commas
Date: Sun, 26 Nov 2023 17:36:28 -0500	[thread overview]
Message-ID: <56683B0AF4B13786B312FE99958B452B@eigenstate.org> (raw)
In-Reply-To: <904397cf-6c3f-46c4-9139-7f80823ec064@invalid.invalid>

Quoth Blue-Maned_Hawk <bluemanedhawk@gmail.com>:
> 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 <libc.h>
 .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 <u.h>
 #include <libc.h>
 
-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();
-}


      parent reply	other threads:[~2023-11-26 22:39 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22 23:11 Blue-Maned_Hawk
2023-11-23  4:20 ` Jacob Moody
2023-11-25  0:27   ` Blue-Maned_Hawk
2023-11-25  1:09     ` Jacob Moody
2023-11-25  4:34     ` ori
2023-11-25 12:09       ` Blue-Maned_Hawk
2023-11-25 18:46         ` Kurt H Maier
2023-11-25 20:06           ` Steve Simon
2023-11-25 20:39             ` Dan Cross
2023-11-25 22:47               ` Steve Simon
2023-11-26  2:22               ` Kurt H Maier
2023-11-26 17:31                 ` Blue-Maned_Hawk
2023-11-26 18:13                   ` ori
2023-11-26 22:39                     ` Blue-Maned_Hawk
2023-11-26 22:52                       ` ori
2023-11-26 23:30                         ` Blue-Maned_Hawk
2023-11-27  0:00                           ` ori
2023-11-27 11:20                             ` Blue-Maned_Hawk
2023-11-27 15:38                               ` ori
2023-11-27 15:59                                 ` Dan Cross
2023-11-27 22:21                                 ` Blue-Maned_Hawk
2023-11-27 23:59                                   ` ori
2023-11-28  0:30                                     ` Blue-Maned_Hawk
2023-11-28  0:34                                       ` ori
2023-11-29  9:14                                         ` Blue-Maned_Hawk
2023-11-26 19:58                   ` Kurt H Maier
2023-11-26 22:37                     ` Blue-Maned_Hawk
2023-11-25  4:49     ` ori
2023-11-26 18:59     ` Amavect
     [not found]       ` <7025e6e9-fca5-4648-aaea-a80260c35739@sirjofri.de>
2023-11-26 21:11         ` sirjofri
2023-11-26 22:41       ` Blue-Maned_Hawk
2023-11-27 15:44         ` Amavect
2023-11-26 22:36 ` ori [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56683B0AF4B13786B312FE99958B452B@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).