Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
assert.cpp
Go to the documentation of this file.
1
29#define _RWSTD_LIB_SRC
30
31
32#include <stdio.h> // for fprintf()
33#include <stdlib.h> // for abort()
34
35#include <rw/_defs.h>
36
37
38#ifdef __HP_aCC
39
40extern "C" void U_STACK_TRACE () _RWSTD_DECLARE_NOTHROW;
41
42# define STACK_TRACE U_STACK_TRACE
43
44#elif defined (__GLIBC__)
45
46# include <execinfo.h>
47
49
50// declare with attribute((nothrow)) since the function calls
51// others that may not be declared nothrow
52static void
53__rw_stack_trace (int fd) _RWSTD_DECLARE_NOTHROW;
54
55
56static void
57__rw_stack_trace (int fd) _RWSTD_DEFINE_NOTHROW
58{
59 // limit stacktrace to the depth of 256 calls
60 void* array [256];
61
62 const int size = backtrace (array, int (sizeof array / sizeof *array));
63
64 backtrace_symbols_fd (array, size, fd);
65}
66
67} // namespace __rw
68
69# define STACK_TRACE() _RW::__rw_stack_trace (2)
70
71#elif defined (_RWSTD_OS_SUNOS) \
72 && (5 < _RWSTD_OS_MAJOR || 5 == _RWSTD_OS_MAJOR && 8 < _RWSTD_OS_MINOR)
73
74// only Solaris 9 and better defines printstack() (in <ucontext.h>)
75// declare the function here instead of including the header to avoid
76// having to #define enabling macros (i.e., __EXTENSIONS__) and deal
77// with the breakage when using a strict compiler such as EDG eccp
78// with the long long extension (used in some system headers) disabled
79extern "C" int printstack (int) _RWSTD_DECLARE_NOTHROW;
80
81# define STACK_TRACE() printstack (2)
82#endif
83
84#ifndef STACK_TRACE
85# define STACK_TRACE() (void)0
86#endif // __HP_aCC
87
88
90
91
93__rw_assert_fail (const char *expr,
94 const char *file, int line, const char *func)
96{
97 // func may be 0 if the compiler doesn't support the ANSI C predefined
98 // identifier `__func__' (see 6.4.2.2 of ISO/IEC 9899:1999) or an
99 // equivalent thereof, such as gcc's __PRETTY_FUNCTION__
100 if (func)
101 fprintf (stderr, "%s:%d: %s: Assertion '%s' failed.\n",
102 file, line, func, expr);
103 else
104 fprintf (stderr, "%s:%d: Assertion '%s' failed.\n",
105 file, line, expr);
106
107 // print stack trace (if available) before aborting
108 STACK_TRACE ();
109
110 abort ();
111}
112
113
114} // namespace __rw
#define line
Definition 17.names.cpp:490
#define stderr
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_DECLARE_NOTHROW
Definition _defs.h:1182
#define _RWSTD_DEFINE_NOTHROW
Definition _defs.h:1183
#define STACK_TRACE()
Definition assert.cpp:85
A TOML array.
Definition array.hpp:258