[57f408e] | 1 | // |
---|
[1cb2282] | 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. |
---|
[57f408e] | 6 | // |
---|
| 7 | // Assert.cc -- |
---|
| 8 | // |
---|
[1cb2282] | 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Thu Aug 18 13:26:59 2016 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[e6955b1] | 12 | // Last Modified On : Fri Aug 19 17:07:08 2016 |
---|
| 13 | // Update Count : 10 |
---|
[57f408e] | 14 | // |
---|
[1cb2282] | 15 | |
---|
[bf2438c] | 16 | #include <cstdarg> // for va_end, va_list, va_start |
---|
| 17 | #include <cstdio> // for fprintf, stderr, vfprintf |
---|
| 18 | #include <cstdlib> // for abort |
---|
[1cb2282] | 19 | |
---|
| 20 | extern const char * __progname; // global name of running executable (argv[0]) |
---|
| 21 | |
---|
[b3c36f4] | 22 | #define CFA_ASSERT_FMT "*CFA assertion error* \"%s\" from program \"%s\" in \"%s\" at line %d in file \"%s\"" |
---|
[1cb2282] | 23 | |
---|
| 24 | // called by macro assert in assert.h |
---|
| 25 | void __assert_fail( const char *assertion, const char *file, unsigned int line, const char *function ) { |
---|
[b3c36f4] | 26 | fprintf( stderr, CFA_ASSERT_FMT ".\n", assertion, __progname, function, line, file ); |
---|
[e6955b1] | 27 | abort(); |
---|
[1cb2282] | 28 | } |
---|
| 29 | |
---|
| 30 | // called by macro assertf |
---|
| 31 | void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) { |
---|
[b3c36f4] | 32 | fprintf( stderr, CFA_ASSERT_FMT ": ", assertion, __progname, function, line, file ); |
---|
[1cb2282] | 33 | va_list args; |
---|
| 34 | va_start( args, fmt ); |
---|
| 35 | vfprintf( stderr, fmt, args ); |
---|
[57f408e] | 36 | va_end( args ); |
---|
| 37 | fprintf( stderr, "\n" ); |
---|
[e6955b1] | 38 | abort(); |
---|
[1cb2282] | 39 | } |
---|
| 40 | |
---|
[6a625de] | 41 | void abort(const char *fmt, ... ) noexcept __attribute__((noreturn, format(printf, 1, 2))); |
---|
| 42 | void abort(const char *fmt, ... ) noexcept { |
---|
| 43 | va_list args; |
---|
| 44 | va_start( args, fmt ); |
---|
| 45 | vfprintf( stderr, fmt, args ); |
---|
| 46 | va_end( args ); |
---|
| 47 | fprintf( stderr, "\n" ); |
---|
| 48 | abort(); |
---|
| 49 | } |
---|
| 50 | |
---|
[1cb2282] | 51 | // Local Variables: // |
---|
| 52 | // tab-width: 4 // |
---|
| 53 | // mode: c++ // |
---|
| 54 | // compile-command: "make install" // |
---|
| 55 | // End: // |
---|