lib: __assert_fail: Update to standard.

* lib/mes/__assert_fail.c (__assert_fail): Add file, line, function
parameters.
* include/assert.h (assert): Update caller.
(__assert_fail): Update prototype.
* include/mes/lib.h (__assert_fail): Likewise.
* lib/mes/assert_msg.c (assert_msg): Likewise.  Include assert.h.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2022-10-26 21:14:05 +02:00
parent 84fd995f43
commit 25e0c4d119
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
4 changed files with 30 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

@ -67,7 +67,8 @@ extern void (*__call_at_exit) (void);
#define __FILEDES_MAX 512
#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[0])
{
eputs (file);
eputs (":");
}
if (line)
{
eputs (itoa (line));
eputs (":");
}
if (function && function[0])
{
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.
*
@ -20,11 +20,12 @@
*/
#include <mes/lib.h>
#include <assert.h>
#include <stdlib.h>
void
assert_msg (int bool, char *msg)
{
if (bool == 0)
__assert_fail (msg);
__assert_fail (msg, 0, 0, 0);
}