DRAFT lib: __assert_fail: Update to standard.

* lib/mes/__assert_fail.c (__assert_fail): Add file, line, function
parameters.
* lib/mes/assert_msg.c (assert_msg): Update caller.
* include/assert.h (assert): Update caller.
(__assert_fail): Update prototype.
* include/mes/lib.h (__assert_fail): Likewise.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2022-10-26 21:14:05 +02:00
parent 5b2734a217
commit 4b3c013d25
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
4 changed files with 29 additions and 11 deletions

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -27,8 +27,9 @@
#undef __MES_ASSERT_H
#include_next <assert.h>
#else // ! SYSTEM_LIBC
#define assert(x) ((x) ? (void)0 : __assert_fail (#x))
void __assert_fail (char *s);
#define assert(x) ((x) ? (void)0 : __assert_fail (#x, 0, 0, 0))
void __assert_fail (char const *s, char const *file, unsigned line,
char const *function);
#endif // ! SYSTEM_LIBC
#endif // __MES_ASSERT_H

View File

@ -69,7 +69,8 @@ void *__memset (void *s, int c, size_t n);
int __raise (int signal);
#if !SYSTEM_LIBC
void __assert_fail (char *s);
void __assert_fail (char const *s, char const *file, unsigned line,
char const *function);
ssize_t __buffered_read (int filedes, void *buffer, size_t size);
size_t __buffered_read_clear (int filedes);
void _exit (int code);

View File

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -19,14 +19,30 @@
*/
#include <mes/lib.h>
#include <assert.h>
void
__assert_fail (char *s)
__assert_fail (char const *msg, char const *file, unsigned line,
char const *function)
{
if (file && *file)
{
eputs (file);
eputs (":");
}
if (line)
{
eputs (itoa (line));
eputs (":");
}
if (function && *function)
{
eputs (function);
eputs (":");
}
eputs ("assert fail: ");
eputs (s);
eputs (msg);
eputs ("\n");
char *fail = s;
fail = 0;
char *fail = 0;
fail[0] = 0;
}

View File

@ -1,7 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jeremiah Orians <jeremiah@pdp10.guru>
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -26,5 +26,5 @@ void
assert_msg (int bool, char *msg)
{
if (bool == 0)
__assert_fail (msg);
__assert_fail (msg, 0, 0, 0);
}