1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-26 05:29:30 +00:00

Made assert() send SIGABRT when an assertion fails.

A signal handler can catch it, and do anything needed to make stderr work.
This commit is contained in:
Greg King 2019-11-10 12:46:01 -05:00
parent 7f7db01e25
commit ac4866c027
2 changed files with 18 additions and 17 deletions

View File

@ -1,4 +1,4 @@
<!doctype linuxdoc system> <!-- -*- text-mode -*- -->
<!doctype linuxdoc system>
<article>
<title>cc65 function reference
@ -1316,11 +1316,11 @@ disabled.
<quote>
<descrip>
<tag/Function/Terminates a program abnormally.
<tag/Function/Terminate a program abnormally.
<tag/Header/<tt/<ref id="stdlib.h" name="stdlib.h">/
<tag/Declaration/<tt/void abort (void);/
<tag/Description/<tt/abort/ raises <tt/SIGABRT/, writes a termination message
on stderr, then terminates the program with an exit code of 3.
<tag/Description/<tt/abort()/ raises <tt/SIGABRT/, writes a termination message
on <tt/stderr/, then terminates the program with an exit code of 3.
<tag/Availability/ISO 9899
<tag/See also/
<ref id="assert" name="assert">,
@ -1357,19 +1357,20 @@ used in presence of a prototype.
<quote>
<descrip>
<tag/Function/Test a condition and possibly abort.
<tag/Function/Test a condition, and possibly abort.
<tag/Header/<tt/<ref id="assert.h" name="assert.h">/
<tag/Declaration/<tt/void assert (int cond);/
<tag/Description/<tt/assert/ is a macro that expands to an <tt/id/
statement. If the condition evaluates to zero (false), assert prints a message
on stderr and aborts the program.
<tag/Description/<tt/assert()/ is a macro that expands to an <tt/if/ statement.
If the condition evaluates to zero (false), <tt/assert()/ raises <tt/SIGABRT/,
prints a message on <tt/stderr/, then exits the program with an exit code of 2.
<tag/Notes/<itemize>
<item>The function is actually a macro.
</itemize>
<tag/Availability/ISO 9899
<tag/See also/
<ref id="abort" name="abort">,
<ref id="exit" name="exit">
<ref id="exit" name="exit">,
<ref id="raise" name="raise">
<tag/Example/None.
</descrip>
</quote>
@ -5820,18 +5821,19 @@ calling convention.
<tag/Function/Send a signal to the executing program.
<tag/Header/<tt/<ref id="signal.h" name="signal.h">/
<tag/Declaration/<tt/int __fastcall__ raise (int sig);/
<tag/Description/<tt/raise/ sends the given signal to the program. If the
<tag/Description/<tt/raise()/ sends the given signal to the program. If the
program has installed a signal handler for the signal, this signal handler
will be executed. If no handler has been installed, the default action for
the raised signal will be taken. The function returns zero on success,
nonzero otherwise.
non-zero otherwise.
<tag/Notes/<itemize>
<item>The function is only available as fastcall function, so it may only
be used in presence of a prototype.
<item>The function is available only as a fastcall function,
so it may be used only in the presence of a prototype.
</itemize>
<tag/Availability/ISO 9899
<tag/See also/
<ref id="abort" name="abort">,
<ref id="assert" name="assert">,
<ref id="signal" name="signal">
<tag/Example/None.
</descrip>

View File

@ -2,11 +2,12 @@
** _afailed.c
**
** 1998-06-06, Ullrich von Bassewitz
** 2015-03-13, Greg King
** 2019-11-10, Greg King
*/
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -14,9 +15,7 @@
void __fastcall__ _afailed (char* file, unsigned line)
{
raise (SIGABRT);
fprintf (stderr, "ASSERTION FAILED IN %s(%u)\n", file, line);
exit (2);
}