From 801889dafa327f12c0c35523ce1b9c2abd1f9e21 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 23 Oct 2025 16:09:25 -0400 Subject: [PATCH] assert: Allow SDL_FILE (and the new SDL_ASSERT_FILE) to be overridden. This allows changing out `__FILE__` in general and the file path reported in SDL_assert specifically to not leak build machine path info, or just simply not include the absolute path if you swap it out with `FILE_NAME` on Clang/GCC. Fixes #14290. --- include/SDL3/SDL_assert.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/include/SDL3/SDL_assert.h b/include/SDL3/SDL_assert.h index 2ab796a1ae..42fa1fd81e 100644 --- a/include/SDL3/SDL_assert.h +++ b/include/SDL3/SDL_assert.h @@ -176,12 +176,37 @@ extern "C" { # define SDL_FUNCTION "???" #endif +#ifndef SDL_FILE /** * A macro that reports the current file being compiled. * + * This macro is only defined if it isn't already defined, so to override + * it (perhaps with something that doesn't provide path information at all, + * so build machine information doesn't leak into public binaries), apps can + * define this macro before including SDL_assert.h. For example, Clang and GCC + * can define this to `FILE_NAME` to get just the source filename instead of + * the full path. + * * \since This macro is available since SDL 3.2.0. */ #define SDL_FILE __FILE__ +#endif + +#ifndef SDL_ASSERT_FILE +/** + * A macro that reports the current file being compiled, for use in assertions. + * + * This macro is only defined if it isn't already defined, so to override + * it (perhaps with something that doesn't provide path information at all, + * so build machine information doesn't leak into public binaries), apps can + * define this macro before including SDL_assert.h. For example, defining this + * to `""` will make sure no source path information is included in asserts. + * + * \since This macro is available since SDL 3.4.0. + */ +#define SDL_ASSERT_FILE SDL_FILE +#endif + /** * A macro that reports the current line number of the file being compiled. @@ -360,7 +385,7 @@ extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData * do { \ while ( !(condition) ) { \ static struct SDL_AssertData sdl_assert_data = { false, 0, #condition, NULL, 0, NULL, NULL }; \ - const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \ + const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_ASSERT_FILE, SDL_LINE); \ if (sdl_assert_state == SDL_ASSERTION_RETRY) { \ continue; /* go again. */ \ } else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \