[f773f67] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
| 7 | // assert.c --
|
---|
| 8 | //
|
---|
| 9 | // Author : Thierry Delisle
|
---|
| 10 | // Created On : Mon Nov 28 12:27:26 2016
|
---|
[91c389a] | 11 | // Last Modified By : Peter A. Buhr
|
---|
[e3fea42] | 12 | // Last Modified On : Tue Feb 4 13:00:18 2020
|
---|
| 13 | // Update Count : 6
|
---|
[f773f67] | 14 | //
|
---|
| 15 |
|
---|
[91c389a] | 16 | #include <assert.h>
|
---|
| 17 | #include <stdarg.h> // varargs
|
---|
| 18 | #include <stdio.h> // fprintf
|
---|
[1c40091] | 19 | #include <unistd.h> // STDERR_FILENO
|
---|
[73abe95] | 20 | #include "bits/debug.hfa"
|
---|
[032234bd] | 21 | #include "bits/defs.hfa"
|
---|
[9d944b2] | 22 |
|
---|
[f773f67] | 23 | extern "C" {
|
---|
| 24 | extern const char * __progname; // global name of running executable (argv[0])
|
---|
| 25 |
|
---|
[f5883bd] | 26 | #define CFA_ASSERT_FMT "Cforall Assertion error \"%s\" from program \"%s\" in \"%s\" at line %d in file \"%s\""
|
---|
[77125cc] | 27 | #define CFA_WARNING_FMT "Cforall Assertion warning \"%s\" from program \"%s\" in \"%s\" at line %d in file \"%s\""
|
---|
[f773f67] | 28 |
|
---|
| 29 | // called by macro assert in assert.h
|
---|
[032234bd] | 30 | // would be cool to remove libcfa_public but it's needed for libcfathread
|
---|
| 31 | void __assert_fail( const char assertion[], const char file[], unsigned int line, const char function[] ) libcfa_public {
|
---|
[1c40091] | 32 | __cfaabi_bits_print_safe( STDERR_FILENO, CFA_ASSERT_FMT ".\n", assertion, __progname, function, line, file );
|
---|
[f773f67] | 33 | abort();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | // called by macro assertf
|
---|
[032234bd] | 37 | // would be cool to remove libcfa_public but it's needed for libcfathread
|
---|
| 38 | void __assert_fail_f( const char assertion[], const char file[], unsigned int line, const char function[], const char fmt[], ... ) libcfa_public {
|
---|
[1c40091] | 39 | __cfaabi_bits_acquire();
|
---|
| 40 | __cfaabi_bits_print_nolock( STDERR_FILENO, CFA_ASSERT_FMT ": ", assertion, __progname, function, line, file );
|
---|
[9d944b2] | 41 |
|
---|
[f773f67] | 42 | va_list args;
|
---|
| 43 | va_start( args, fmt );
|
---|
[1c40091] | 44 | __cfaabi_bits_print_vararg( STDERR_FILENO, fmt, args );
|
---|
[57f408e] | 45 | va_end( args );
|
---|
[9d944b2] | 46 |
|
---|
[1c40091] | 47 | __cfaabi_bits_print_nolock( STDERR_FILENO, "\n" );
|
---|
| 48 | __cfaabi_bits_release();
|
---|
[f773f67] | 49 | abort();
|
---|
| 50 | }
|
---|
[77125cc] | 51 |
|
---|
| 52 | // called by macro warnf
|
---|
| 53 | // would be cool to remove libcfa_public but it's needed for libcfathread
|
---|
| 54 | void __assert_warn_f( const char assertion[], const char file[], unsigned int line, const char function[], const char fmt[], ... ) libcfa_public {
|
---|
| 55 | __cfaabi_bits_acquire();
|
---|
| 56 | __cfaabi_bits_print_nolock( STDERR_FILENO, CFA_WARNING_FMT ": ", assertion, __progname, function, line, file );
|
---|
| 57 |
|
---|
| 58 | va_list args;
|
---|
| 59 | va_start( args, fmt );
|
---|
| 60 | __cfaabi_bits_print_vararg( STDERR_FILENO, fmt, args );
|
---|
| 61 | va_end( args );
|
---|
| 62 |
|
---|
| 63 | __cfaabi_bits_print_nolock( STDERR_FILENO, "\n" );
|
---|
| 64 | __cfaabi_bits_release();
|
---|
| 65 | }
|
---|
[f773f67] | 66 | }
|
---|
| 67 |
|
---|
| 68 | // Local Variables: //
|
---|
| 69 | // mode: c //
|
---|
| 70 | // tab-width: 4 //
|
---|
| 71 | // End: //
|
---|