Add an invalid #define for SDL_ThreadID() to SDL_oldnames.h - v2#15822
Open
DanielGibson wants to merge 3 commits into
Open
Add an invalid #define for SDL_ThreadID() to SDL_oldnames.h - v2#15822DanielGibson wants to merge 3 commits into
DanielGibson wants to merge 3 commits into
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).
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.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
see #15801
(In short,
SDL_ThreadID()was a function in SDL2 butSDL_ThreadIDis a type in SDL3, so it can't easily be handled with automatic renaming andSDL_ThreadID()still compiles fine in C++ code using SDL3 because it's just a default constructor)Additionally I put
#ifndef SDL_ThreadIDaround 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.