11/*
22 Simple DirectMedia Layer
3- Copyright (C) 1997-2022 Sam Lantinga <[email protected] > 3+ Copyright (C) 1997-2025 Sam Lantinga <[email protected] > 44
55 This software is provided 'as-is', without any express or implied
66 warranty. In no event will the authors be held liable for any damages
2222#ifndef SDL_assert_h_
2323#define SDL_assert_h_
2424
25- #include "SDL_config .h"
25+ #include "SDL_stdinc .h"
2626
2727#include "begin_code.h"
2828/* Set up for C function definitions, even when using C++ */
@@ -51,14 +51,22 @@ assert can have unique static variables associated with it.
5151/* Don't include intrin.h here because it contains C++ code */
5252 extern void __cdecl __debugbreak (void );
5353 #define SDL_TriggerBreakpoint () __debugbreak()
54+ #elif _SDL_HAS_BUILTIN (__builtin_debugtrap )
55+ #define SDL_TriggerBreakpoint () __builtin_debugtrap()
5456#elif ( (!defined(__NACL__ )) && ((defined(__GNUC__ ) || defined(__clang__ )) && (defined(__i386__ ) || defined(__x86_64__ ))) )
5557 #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" )
5660#elif ( defined(__APPLE__ ) && (defined(__arm64__ ) || defined(__aarch64__ )) ) /* this might work on other ARM targets, but this is a known quantity... */
5761 #define SDL_TriggerBreakpoint () __asm__ __volatile__ ( "brk #22\n\t" )
5862#elif defined(__APPLE__ ) && defined(__arm__ )
5963 #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" )
6066#elif defined(__386__ ) && defined(__WATCOMC__ )
61- #define SDL_TriggerBreakpoint () { _asm { int 0x03 } }
67+ #define SDL_TriggerBreakpoint ()
68+ { _asm
69+ { int 0x03 } }
6270#elif defined(HAVE_SIGNAL_H ) && !defined(__WATCOMC__ )
6371 #include <signal.h>
6472 #define SDL_TriggerBreakpoint () raise(SIGTRAP)
@@ -69,7 +77,7 @@ assert can have unique static variables associated with it.
6977
7078#if defined(__STDC_VERSION__ ) && (__STDC_VERSION__ >= 199901L ) /* C99 supports __func__ as a standard. */
7179# define SDL_FUNCTION __func__
72- #elif ((__GNUC__ >= 2 ) || defined(_MSC_VER ) || defined (__WATCOMC__ ))
80+ #elif ((defined( __GNUC__ ) && ( __GNUC__ >= 2 ) ) || defined(_MSC_VER ) || defined (__WATCOMC__ ))
7381# define SDL_FUNCTION __FUNCTION__
7482#else
7583# define SDL_FUNCTION "???"
@@ -123,12 +131,10 @@ typedef struct SDL_AssertData
123131 const struct SDL_AssertData * next ;
124132} SDL_AssertData ;
125133
126- #if (SDL_ASSERT_LEVEL > 0 )
127-
128134/* Never call this directly. Use the SDL_assert* macros. */
129135extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion (SDL_AssertData * ,
130- const char * ,
131- const char * , int )
136+ const char * ,
137+ const char * , int )
132138#if defined(__clang__ )
133139#if __has_feature (attribute_analyzer_noreturn )
134140/* this tells Clang's static analysis that we're a custom assert function,
@@ -148,22 +154,21 @@ extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
148154*/
149155#define SDL_enabled_assert (condition ) \
150156 do { \
151- while ( !(condition) ) { \
152- static struct SDL_AssertData sdl_assert_data = { \
153- 0, 0, #condition, 0, 0, 0, 0 \
154- }; \
157+ while ( !(condition) )
158+ { \
159+ static struct SDL_AssertData sdl_assert_data = { 0 , 0 , #condition , 0 , 0 , 0 , 0 }; \
155160 const SDL_AssertState sdl_assert_state = SDL_ReportAssertion (& sdl_assert_data , SDL_FUNCTION , SDL_FILE , SDL_LINE ); \
156- if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
161+ if (sdl_assert_state == SDL_ASSERTION_RETRY )
162+ { \
157163 continue ; /* go again. */ \
158- } else if (sdl_assert_state == SDL_ASSERTION_BREAK ) { \
164+ } else if (sdl_assert_state == SDL_ASSERTION_BREAK )
165+ { \
159166 SDL_TriggerBreakpoint (); \
160167 } \
161168 break ; /* not retrying. */ \
162169 } \
163170 } while (SDL_NULL_WHILE_LOOP_CONDITION )
164171
165- #endif /* enabled assertions support code */
166-
167172/* Enable various levels of assertions. */
168173#if SDL_ASSERT_LEVEL == 0 /* assertions disabled */
169174# define SDL_assert (condition ) SDL_disabled_assert(condition)
@@ -193,8 +198,8 @@ extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
193198 * A callback that fires when an SDL assertion fails.
194199 *
195200 * \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()
201+ * current assertion.
202+ * \param userdata what was passed as `userdata` to SDL_SetAssertionHandler().
198203 * \returns an SDL_AssertState value indicating how to handle the failure.
199204 */
200205typedef SDL_AssertState (SDLCALL * SDL_AssertionHandler )(
@@ -214,8 +219,8 @@ typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
214219 * This callback is NOT reset to SDL's internal handler upon SDL_Quit()!
215220 *
216221 * \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`
222+ * fails or NULL for the default handler.
223+ * \param userdata a pointer that is passed to `handler`.
219224 *
220225 * \since This function is available since SDL 2.0.0.
221226 *
@@ -256,7 +261,7 @@ extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(void
256261 * data, it is safe to pass a NULL pointer to this function to ignore it.
257262 *
258263 * \param puserdata pointer which is filled with the "userdata" pointer that
259- * was passed to SDL_SetAssertionHandler()
264+ * was passed to SDL_SetAssertionHandler().
260265 * \returns the SDL_AssertionHandler that is called when an assert triggers.
261266 *
262267 * \since This function is available since SDL 2.0.2.
@@ -275,7 +280,8 @@ extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **puse
275280 *
276281 * ```c
277282 * const SDL_AssertData *item = SDL_GetAssertionReport();
278- * while (item) {
283+ * while (item)
284+ {
279285 * printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\\n",
280286 * item->condition, item->function, item->filename,
281287 * item->linenum, item->trigger_count,
@@ -321,4 +327,4 @@ extern DECLSPEC void SDLCALL SDL_ResetAssertionReport(void);
321327
322328#endif /* SDL_assert_h_ */
323329
324- /* vi: set ts=4 sw=4 expandtab: */
330+ /* vi: set ts=4 sw=4 expandtab: */
0 commit comments