1
1
/*
2
2
Simple DirectMedia Layer
3
- Copyright (C) 1997-2022 Sam Lantinga <[email protected] >
3
+ Copyright (C) 1997-2025 Sam Lantinga <[email protected] >
4
4
5
5
This software is provided 'as-is', without any express or implied
6
6
warranty. In no event will the authors be held liable for any damages
22
22
#ifndef SDL_assert_h_
23
23
#define SDL_assert_h_
24
24
25
- #include <SDL2/SDL_config .h>
25
+ #include <SDL2/SDL_stdinc .h>
26
26
27
27
#include <SDL2/begin_code.h>
28
28
/* Set up for C function definitions, even when using C++ */
@@ -51,12 +51,18 @@ assert can have unique static variables associated with it.
51
51
/* Don't include intrin.h here because it contains C++ code */
52
52
extern void __cdecl __debugbreak (void );
53
53
#define SDL_TriggerBreakpoint () __debugbreak()
54
+ #elif _SDL_HAS_BUILTIN (__builtin_debugtrap )
55
+ #define SDL_TriggerBreakpoint () __builtin_debugtrap()
54
56
#elif ( (!defined(__NACL__ )) && ((defined(__GNUC__ ) || defined(__clang__ )) && (defined(__i386__ ) || defined(__x86_64__ ))) )
55
57
#define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "int $3\n\t" )
58
+ #elif (defined(__GNUC__ ) || defined(__clang__ )) && defined(__riscv )
59
+ #define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "ebreak\n\t" )
56
60
#elif ( defined(__APPLE__ ) && (defined(__arm64__ ) || defined(__aarch64__ )) ) /* this might work on other ARM targets, but this is a known quantity... */
57
61
#define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "brk #22\n\t" )
58
62
#elif defined(__APPLE__ ) && defined(__arm__ )
59
63
#define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "bkpt #22\n\t" )
64
+ #elif defined(_WIN32 ) && ((defined(__GNUC__ ) || defined(__clang__ )) && (defined(__arm64__ ) || defined(__aarch64__ )) )
65
+ #define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "brk #0xF000\n\t" )
60
66
#elif defined(__386__ ) && defined(__WATCOMC__ )
61
67
#define SDL_TriggerBreakpoint () { _asm { int 0x03 } }
62
68
#elif defined(HAVE_SIGNAL_H ) && !defined(__WATCOMC__ )
@@ -69,7 +75,7 @@ assert can have unique static variables associated with it.
69
75
70
76
#if defined(__STDC_VERSION__ ) && (__STDC_VERSION__ >= 199901L ) /* C99 supports __func__ as a standard. */
71
77
# define SDL_FUNCTION __func__
72
- #elif ((__GNUC__ >= 2 ) || defined(_MSC_VER ) || defined (__WATCOMC__ ))
78
+ #elif ((defined( __GNUC__ ) && ( __GNUC__ >= 2 ) ) || defined(_MSC_VER ) || defined (__WATCOMC__ ))
73
79
# define SDL_FUNCTION __FUNCTION__
74
80
#else
75
81
# define SDL_FUNCTION "???"
@@ -123,12 +129,10 @@ typedef struct SDL_AssertData
123
129
const struct SDL_AssertData * next ;
124
130
} SDL_AssertData ;
125
131
126
- #if (SDL_ASSERT_LEVEL > 0 )
127
-
128
132
/* Never call this directly. Use the SDL_assert* macros. */
129
133
extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion (SDL_AssertData * ,
130
- const char * ,
131
- const char * , int )
134
+ const char * ,
135
+ const char * , int )
132
136
#if defined(__clang__ )
133
137
#if __has_feature (attribute_analyzer_noreturn )
134
138
/* this tells Clang's static analysis that we're a custom assert function,
@@ -149,9 +153,7 @@ extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
149
153
#define SDL_enabled_assert (condition ) \
150
154
do { \
151
155
while ( !(condition) ) { \
152
- static struct SDL_AssertData sdl_assert_data = { \
153
- 0, 0, #condition, 0, 0, 0, 0 \
154
- }; \
156
+ static struct SDL_AssertData sdl_assert_data = { 0, 0, #condition, 0, 0, 0, 0 }; \
155
157
const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
156
158
if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
157
159
continue; /* go again. */ \
@@ -162,8 +164,6 @@ extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
162
164
} \
163
165
} while (SDL_NULL_WHILE_LOOP_CONDITION )
164
166
165
- #endif /* enabled assertions support code */
166
-
167
167
/* Enable various levels of assertions. */
168
168
#if SDL_ASSERT_LEVEL == 0 /* assertions disabled */
169
169
# define SDL_assert (condition ) SDL_disabled_assert(condition)
@@ -193,8 +193,8 @@ extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
193
193
* A callback that fires when an SDL assertion fails.
194
194
*
195
195
* \param data a pointer to the SDL_AssertData structure corresponding to the
196
- * current assertion
197
- * \param userdata what was passed as `userdata` to SDL_SetAssertionHandler()
196
+ * current assertion.
197
+ * \param userdata what was passed as `userdata` to SDL_SetAssertionHandler().
198
198
* \returns an SDL_AssertState value indicating how to handle the failure.
199
199
*/
200
200
typedef SDL_AssertState (SDLCALL * SDL_AssertionHandler )(
@@ -214,8 +214,8 @@ typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
214
214
* This callback is NOT reset to SDL's internal handler upon SDL_Quit()!
215
215
*
216
216
* \param handler the SDL_AssertionHandler function to call when an assertion
217
- * fails or NULL for the default handler
218
- * \param userdata a pointer that is passed to `handler`
217
+ * fails or NULL for the default handler.
218
+ * \param userdata a pointer that is passed to `handler`.
219
219
*
220
220
* \since This function is available since SDL 2.0.0.
221
221
*
@@ -256,7 +256,7 @@ extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(void
256
256
* data, it is safe to pass a NULL pointer to this function to ignore it.
257
257
*
258
258
* \param puserdata pointer which is filled with the "userdata" pointer that
259
- * was passed to SDL_SetAssertionHandler()
259
+ * was passed to SDL_SetAssertionHandler().
260
260
* \returns the SDL_AssertionHandler that is called when an assert triggers.
261
261
*
262
262
* \since This function is available since SDL 2.0.2.
0 commit comments