Skip to content

Add an invalid #define for SDL_ThreadID() to SDL_oldnames.h - v2#15822

Open
DanielGibson wants to merge 3 commits into
libsdl-org:mainfrom
DanielGibson:threadid-warning-header-v2
Open

Add an invalid #define for SDL_ThreadID() to SDL_oldnames.h - v2#15822
DanielGibson wants to merge 3 commits into
libsdl-org:mainfrom
DanielGibson:threadid-warning-header-v2

Conversation

@DanielGibson

@DanielGibson DanielGibson commented Jun 13, 2026

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

see #15801

(In short, SDL_ThreadID() was a function in SDL2 but SDL_ThreadID is a type in SDL3, so it can't easily be handled with automatic renaming and SDL_ThreadID() still compiles fine in C++ code using SDL3 because it's just a default constructor)

Additionally I put #ifndef SDL_ThreadID around the define so it doesn't clash with user hacks defining it, like sdl2-compat does.

NOTE that this still has edge cases where it breaks valid SDL3 code!
That only affects rare edge cases and can be worked around though (in the user code) and is for the greater good (detecting subtly broken code), see the long comment I added to SDL_oldnames.h.

…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).
If user code (like sdl2-compat) does its own #define SDL_ThreadID ...
hacks, don't define it in SDL_oldnames.h to get out of their way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant