From 3473e6bd7b268deb4314659009512d846a75b368 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 27 Jun 2007 12:44:41 +0000 Subject: Support __func__ in assert, as required by C99. * libc/stdlib/assert.c (__assert_func): New function. (__assert): Use __assert_func. * libc/include/assert.h (assert) [!NDEBUG]: Use __assert_func when possible. --- newlib/libc/stdlib/assert.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'newlib/libc/stdlib/assert.c') diff --git a/newlib/libc/stdlib/assert.c b/newlib/libc/stdlib/assert.c index c9887da5c..2da329815 100644 --- a/newlib/libc/stdlib/assert.c +++ b/newlib/libc/stdlib/assert.c @@ -9,11 +9,6 @@ ANSI_SYNOPSIS #include void assert(int <[expression]>); -TRAD_SYNOPSIS - #include - assert(<[expression]>) - int <[expression]>; - DESCRIPTION Use this macro to embed debuggging diagnostic statements in your programs. The argument <[expression]> should be an @@ -24,7 +19,11 @@ DESCRIPTION calls <>, after first printing a message showing what failed and where: -. Assertion failed: <[expression]>, file <[filename]>, line <[lineno]> +. Assertion failed: <[expression]>, file <[filename]>, line <[lineno]>, function: <[func]> + + If the name of the current function is not known (for example, + when using a C89 compiler that does not understand __func__), + the function location is omitted. The macro is defined to permit you to turn off all uses of <> at compile time by defining <> as a @@ -48,15 +47,28 @@ Supporting OS subroutines required (only if enabled): <>, <>, #include #include +/* func can be NULL, in which case no function information is given. */ void -_DEFUN (__assert, (file, line, failedexpr), +_DEFUN (__assert_func, (file, line, func, failedexpr), const char *file _AND int line _AND + const char *func _AND const char *failedexpr) { - (void)fiprintf(stderr, - "assertion \"%s\" failed: file \"%s\", line %d\n", - failedexpr, file, line); + fiprintf(stderr, + "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", + failedexpr, file, line, + func ? ", function: " : "", func ? func : ""); abort(); /* NOTREACHED */ } + +void +_DEFUN (__assert, (file, line, failedexpr), + const char *file _AND + int line _AND + const char *failedexpr) +{ + __assert_func (file, line, NULL, failedexpr); + /* NOTREACHED */ +} -- cgit v1.2.3