Add an invalid #define for SDL_ThreadID() to SDL_oldnames.h#15801
Conversation
…dl-org#15749 in SDL2 SDL_ThreadID() was a function that's now SDL_GetCurrentThreadID(), but in SDL3 SDL_ThreadID is a type, so in C++ `x = SDL_ThreadID()` is valid code (default constructor which in case of integers means 0), so that's a massive footgun. See the big comment in SDL_oldnames.h for more details. Added `#undef SDL_ThreadID` in SDL_dynapi.c because it has one of the (quite rare) cases where "SDL_ThreadID" followed by a "(" is actually correct and necessary (function pointer returning SDL_ThreadID).
|
The failing GDK/MSVC test says BTW: I'm currently adding information about this to README-migration.md |
Yes, totally unrelated. The GDK version we're using on ci does not support Visual Studio 2026. |
|
Merged, thanks! I'm putting this in 3.6.0 so we can catch any more unexpected fallout from this. |
|
Here is the fallout: https://github.com/libsdl-org/sdl2-compat/actions/runs/27378527337/job/81120423041 |
…15801)" This reverts commit b04d026. This caused problems building sdl2-compat: https://github.com/libsdl-org/sdl2-compat/actions/runs/27378527337/job/81120423041
|
Yup, I went ahead and reverted this. |
|
Why did the CI builds triggered by the PR not catch this? |
|
Ah, the fallout is just in sdl2-compat.. Have you considered at least giving me a chance to fix such things before reverting the merged PR? :-p |
|
The solution is probably the same as what I did in SDL_dynapi.c in this PR: #ifdef SDL_ThreadID
/* prevent the SDL_ThreadID() define from conflicting
with the SDL_ThreadID() implementation here */
#undef SDL_ThreadID
#endif |
|
Or, maybe guard your define with |
|
Why would I leak SDL2-compat implementation details into SDL3? I clearly documented that this can lead to false positives in rare edge cases and showed up ways to work around those issues. I really don't get why the reaction to the first edge case having a problem (and implementing SDL2 with SDL3 definitely is an edge case) is to revert this instead of working around it in the edge case. |
The only purpose of |
|
Perhaps more generally useful (in case other projects want to do hacks with their own SDL_ThreadID defines) would be #ifndef SDL_ThreadID
#define SDL_ThreadID() SDL_ThreadID_is_a_type_now_function_is_SDL_GetCurrentThreadID
#endif |
|
Can't we disable |
good point, a anyway, next try (that should also solve the sdl2-compat problem): #15822 |
I haven't looked at this specific case, but we tend to revert breaks right away; it's not personal, fixes can be reapplied when ready, but until then the build is broken for everyone that might want to push unrelated fixes. It's not meant to be a rejection of the original concept or anything. |
I get this when the break happens in this repo, but elsewhere? And as I said, this change is expected to break edge cases, for the greater good of showing up (presumably much more common) broken code that uses Now my additional change fixes the specific edge case of sdl2-compat, but there are still other edge cases that can't be worked around here (but can relatively easy be worked around in user code).. |
Add
#define SDL_ThreadID() SDL_ThreadID_is_a_type_now_function_is_SDL_GetCurrentThreadIDto SDL_oldnames.h to make sure people don't accidentally useSDL_ThreadID()whenSDL_GetCurrentThreadID()was intended.As
SDL_ThreadIDis a type in SDL3, it can't be handled with a simple renaming macro.I added a long explanation about this in SDL_oldnames.h that people will find when running into this compiler error. It includes specific instructions what to do in different situations.
Description
In SDL2, SDL_ThreadID() was a function that's now SDL_GetCurrentThreadID(), but in SDL3 SDL_ThreadID is a type, so in C++
x = SDL_ThreadID()is valid code (default constructor which in case of integers means 0), so that's a massive footgun.While there is no good reason to use
SDL_ThreadID()in SDL3, the#definealso causes compiler errors for any code whereSDL_ThreadIDis followed by(, like function pointer definitions for functions returningSDL_ThreadID- in SDL itself it caused problems in SDL_dynapi.c, that I fixed with an#undefin that file.These cases should be pretty rare and having to work around them is weighted out (?) by catching the mistake of not renaming
SDL_ThreadID()toSDL_GetCurrentThreadID().By the way,
rename_symbols.pyso far does not do this rename[*], so it's likely that this is a common issue.I personally ran into it in dhewm3.
See the big comment in SDL_oldnames.h for more details
[*] and doing so in a way that doesn't cause breakage when running
rename_symbols.pytwice is non-trivialExisting Issue(s)
fixes #15749