[376] | 1 | // Copyright (C) 2015 ChaosForge Ltd
|
---|
| 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
[376] | 6 |
|
---|
[410] | 7 | #include "nv/base/common.hh"
|
---|
[403] | 8 | #include "nv/core/logging.hh"
|
---|
[376] | 9 |
|
---|
[403] | 10 | extern "C" {
|
---|
[376] | 11 | #if NV_COMPILER == NV_MSVC
|
---|
[440] | 12 | NV_NORETURN void __cdecl exit( int _Code );
|
---|
[403] | 13 | #else
|
---|
| 14 | void exit( int status_code ) NV_NORETURN;
|
---|
| 15 | #endif
|
---|
| 16 | }
|
---|
[376] | 17 |
|
---|
[403] | 18 | #if NV_DEBUG
|
---|
| 19 | # if NV_COMPILER == NV_MSVC
|
---|
[376] | 20 | extern "C" {
|
---|
| 21 | void __cdecl _wassert( const wchar_t * _Message, const wchar_t *_File, unsigned _Line );
|
---|
| 22 | }
|
---|
| 23 |
|
---|
[403] | 24 | void nv::detail::assert_fail( const wchar_t * message, const wchar_t* file, unsigned line )
|
---|
[376] | 25 | {
|
---|
| 26 | _wassert( message, file, line );
|
---|
| 27 | }
|
---|
[403] | 28 | # else // NV_COMPILER
|
---|
[376] | 29 | # if NV_COMPILER == NV_CLANG
|
---|
[487] | 30 | // extern "C" {
|
---|
| 31 | // extern void __assert(const char *, const char *, unsigned int, const char *) NV_NORETURN;
|
---|
| 32 | // }
|
---|
| 33 |
|
---|
| 34 | int error_here;
|
---|
| 35 | static void __assert( const char *, const char *, unsigned int, const char * ) NV_NORETURN
|
---|
| 36 | {
|
---|
| 37 | //no-op
|
---|
[376] | 38 | }
|
---|
[487] | 39 |
|
---|
[403] | 40 | #define NV_ASSERT_IMPL __assert
|
---|
[376] | 41 | # else
|
---|
[378] | 42 | extern "C" {
|
---|
[403] | 43 | extern void __assert_fail(const char *, const char *, unsigned int, const char *) NV_NORETURN;
|
---|
[378] | 44 | }
|
---|
[403] | 45 | #define NV_ASSERT_IMPL __assert_fail
|
---|
[376] | 46 | # endif
|
---|
[403] | 47 | NV_NORETURN void nv::detail::assert_fail( const char * assertion, const char * file, unsigned int line, const char * function )
|
---|
[376] | 48 | {
|
---|
[403] | 49 | NV_ASSERT_IMPL (assertion, file, line, function );
|
---|
| 50 | }
|
---|
[376] | 51 | # endif
|
---|
[403] | 52 |
|
---|
| 53 | #endif // NV_DEBUG
|
---|
| 54 |
|
---|
| 55 | NV_NORETURN void nv::detail::abort( const char * msg, const char * file, unsigned int line, const char * function )
|
---|
| 56 | {
|
---|
| 57 | NV_LOG_CRITICAL( "Abort called : ", msg );
|
---|
| 58 | NV_LOG_CRITICAL( " in ", file, ":", line, " (", function, ")" );
|
---|
| 59 | NV_LOG_CRITICAL( "Aborting..." );
|
---|
| 60 | exit( 1 );
|
---|
[376] | 61 | }
|
---|
[403] | 62 |
|
---|
| 63 | NV_NORETURN void nv::detail::assert_abort( const char * msg, const char * file, unsigned int line, const char * function )
|
---|
[376] | 64 | {
|
---|
[403] | 65 | NV_LOG_CRITICAL( "Assertion failed: (", msg, ")" );
|
---|
| 66 | NV_LOG_CRITICAL( " in ", file, ":", line, " (", function, ")" );
|
---|
| 67 | NV_LOG_CRITICAL( "Aborting..." );
|
---|
| 68 | exit( 1 );
|
---|
[376] | 69 | }
|
---|
[406] | 70 |
|
---|
| 71 |
|
---|
| 72 | NV_NORETURN void nv::exit( int ret_val )
|
---|
| 73 | {
|
---|
| 74 | ::exit( ret_val );
|
---|
| 75 | }
|
---|