Mercurial > sdl-ios-xcode
annotate include/SDL_assert.h @ 3661:22b6a0c7ea6e
Handle assertion failures during assertion handler.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 13 Jan 2010 09:13:37 +0000 |
parents | 1cc7f0143c12 |
children | 97114af2f8dc |
rev | line source |
---|---|
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2009 Sam Lantinga |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 #ifndef _SDL_assert_h |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #define _SDL_assert_h |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
26 #include "SDL_config.h" |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
27 |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
28 #include "begin_code.h" |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
29 /* Set up for C function definitions, even when using C++ */ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
30 #ifdef __cplusplus |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
31 /* *INDENT-OFF* */ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
32 extern "C" { |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
33 /* *INDENT-ON* */ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
34 #endif |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
35 |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 #ifndef SDL_ASSERT_LEVEL |
3654
336f3df1578d
Allow configure to override assertion settings, but by default this comes from the build optimization level.
Sam Lantinga <slouken@libsdl.org>
parents:
3653
diff
changeset
|
37 #ifdef SDL_DEFAULT_ASSERT_LEVEL |
336f3df1578d
Allow configure to override assertion settings, but by default this comes from the build optimization level.
Sam Lantinga <slouken@libsdl.org>
parents:
3653
diff
changeset
|
38 #define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL |
336f3df1578d
Allow configure to override assertion settings, but by default this comes from the build optimization level.
Sam Lantinga <slouken@libsdl.org>
parents:
3653
diff
changeset
|
39 #elif defined(_DEBUG) || defined(DEBUG) || \ |
336f3df1578d
Allow configure to override assertion settings, but by default this comes from the build optimization level.
Sam Lantinga <slouken@libsdl.org>
parents:
3653
diff
changeset
|
40 (defined(__GNUC__) && !defined(__OPTIMIZE__)) |
3653
1cd9f7117b98
Automatically figure out the appropriate assertion level
Sam Lantinga <slouken@libsdl.org>
parents:
3652
diff
changeset
|
41 #define SDL_ASSERT_LEVEL 2 |
1cd9f7117b98
Automatically figure out the appropriate assertion level
Sam Lantinga <slouken@libsdl.org>
parents:
3652
diff
changeset
|
42 #else |
1cd9f7117b98
Automatically figure out the appropriate assertion level
Sam Lantinga <slouken@libsdl.org>
parents:
3652
diff
changeset
|
43 #define SDL_ASSERT_LEVEL 1 |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 #endif |
3653
1cd9f7117b98
Automatically figure out the appropriate assertion level
Sam Lantinga <slouken@libsdl.org>
parents:
3652
diff
changeset
|
45 #endif /* SDL_ASSERT_LEVEL */ |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 /* |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
48 These are macros and not first class functions so that the debugger breaks |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
49 on the assertion line and not in some random guts of SDL, and so each |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
50 macro can have unique static variables associated with it. |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
51 */ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
52 |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
53 #if (defined(_MSC_VER) && ((_M_IX86) || (_M_X64))) |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
54 #define SDL_TriggerBreakpoint() __asm { int 3 } |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
55 #elif (defined(__GNUC__) && ((__i386__) || (__x86_64__))) |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
56 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" ) |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
57 #elif defined(HAVE_SIGNAL_H) |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
58 #include <signal.h> |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
59 #define SDL_TriggerBreakpoint() raise(SIGTRAP) |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
60 #else |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
61 /* How do we trigger breakpoints on this platform? */ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
62 #define SDL_TriggerBreakpoint() |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
63 #endif |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
64 |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
65 #if (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
66 # define SDL_FUNCTION __func__ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
67 #elif ((__GNUC__ >= 2) || defined(_MSC_VER)) |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
68 # define SDL_FUNCTION __FUNCTION__ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
69 #else |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
70 # define SDL_FUNCTION "???" |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
71 #endif |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
72 #define SDL_FILE __FILE__ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
73 #define SDL_LINE __LINE__ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
74 |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
75 /* |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 sizeof (x) makes the compiler still parse the expression even without |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 assertions enabled, so the code is always checked at compile time, but |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 doesn't actually generate code for it, so there are no side effects or |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 expensive checks at run time, just the constant size of what x WOULD be, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 which presumably gets optimized out as unused. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 This also solves the problem of... |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 int somevalue = blah(); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 SDL_assert(somevalue == 1); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 ...which would cause compiles to complain that somevalue is unused if we |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 disable assertions. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 #define SDL_disabled_assert(condition) \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 do { (void) sizeof ((condition)); } while (0) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 #if (SDL_ASSERT_LEVEL > 0) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 typedef enum |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 SDL_ASSERTION_RETRY, /**< Retry the assert immediately. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 SDL_ASSERTION_BREAK, /**< Make the debugger trigger a breakpoint. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 SDL_ASSERTION_ABORT, /**< Terminate the program. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 SDL_ASSERTION_IGNORE, /**< Ignore the assert. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 SDL_ASSERTION_ALWAYS_IGNORE, /**< Ignore the assert from now on. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 } SDL_assert_state; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 typedef struct SDL_assert_data |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 int always_ignore; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 unsigned int trigger_count; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 const char *condition; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 const char *filename; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 int linenum; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 const char *function; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 struct SDL_assert_data *next; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 } SDL_assert_data; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
116 extern DECLSPEC SDL_assert_state SDLCALL SDL_ReportAssertion(SDL_assert_data *, |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
117 const char *, |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
118 const char *, int); |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 /* the do {} while(0) avoids dangling else problems: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 if (x) SDL_assert(y); else blah(); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 ... without the do/while, the "else" could attach to this macro's "if". |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 We try to handle just the minimum we need here in a macro...the loop, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 the static vars, and break points. The heavy lifting is handled in |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 SDL_ReportAssertion(), in SDL_assert.c. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 #define SDL_enabled_assert(condition) \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 do { \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 while ( !(condition) ) { \ |
3649
1e74d7984d0b
The config sets the default assertion level so people can override it for their own use in application code.
Sam Lantinga <slouken@libsdl.org>
parents:
3647
diff
changeset
|
130 static struct SDL_assert_data assert_data = { \ |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
131 0, 0, #condition, 0, 0, 0, 0 \ |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 }; \ |
3649
1e74d7984d0b
The config sets the default assertion level so people can override it for their own use in application code.
Sam Lantinga <slouken@libsdl.org>
parents:
3647
diff
changeset
|
133 const SDL_assert_state state = SDL_ReportAssertion(&assert_data, \ |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 SDL_FUNCTION, \ |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
135 SDL_FILE, \ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
136 SDL_LINE); \ |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 if (state == SDL_ASSERTION_RETRY) { \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 continue; /* go again. */ \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 } else if (state == SDL_ASSERTION_BREAK) { \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 SDL_TriggerBreakpoint(); \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 } \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 break; /* not retrying. */ \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 } \ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 } while (0) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 #endif /* enabled assertions support code */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 /* Enable various levels of assertions. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 #if SDL_ASSERT_LEVEL == 0 /* assertions disabled */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 # define SDL_assert(condition) SDL_disabled_assert(condition) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 # define SDL_assert_release(condition) SDL_disabled_assert(condition) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 # define SDL_assert_paranoid(condition) SDL_disabled_assert(condition) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 #elif SDL_ASSERT_LEVEL == 1 /* release settings. */ |
3652
dbd6a29e4b77
Fixed release level assertions
Sam Lantinga <slouken@libsdl.org>
parents:
3650
diff
changeset
|
154 # define SDL_assert(condition) SDL_disabled_assert(condition) |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 # define SDL_assert_release(condition) SDL_enabled_assert(condition) |
3652
dbd6a29e4b77
Fixed release level assertions
Sam Lantinga <slouken@libsdl.org>
parents:
3650
diff
changeset
|
156 # define SDL_assert_paranoid(condition) SDL_disabled_assert(condition) |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 #elif SDL_ASSERT_LEVEL == 2 /* normal settings. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 # define SDL_assert(condition) SDL_enabled_assert(condition) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 # define SDL_assert_release(condition) SDL_enabled_assert(condition) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 # define SDL_assert_paranoid(condition) SDL_disabled_assert(condition) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 #elif SDL_ASSERT_LEVEL == 3 /* paranoid settings. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 # define SDL_assert(condition) SDL_enabled_assert(condition) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 # define SDL_assert_release(condition) SDL_enabled_assert(condition) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 # define SDL_assert_paranoid(condition) SDL_enabled_assert(condition) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 #else |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
166 # error Unknown assertion level. |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
169 /* Ends C function definitions when using C++ */ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
170 #ifdef __cplusplus |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
171 /* *INDENT-OFF* */ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
172 } |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
173 /* *INDENT-ON* */ |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
174 #endif |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
175 #include "close_code.h" |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3654
diff
changeset
|
176 |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 #endif /* _SDL_assert_h */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 /* vi: set ts=4 sw=4 expandtab: */ |