-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove more misuse of SDL_GetError in tests #271
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks good, thanks! I haven't verified that it covers all SDL_GetError()
calls, but it's definitely an improvement.
As a general comment, you've added a bunch of SDL_ClearError()
calls that are harmless but probably unnecessary. If you are using the recommended pattern, like this pseudocode:
ret = SDL_Something()
if ret indicates failure:
error "{SDL_GetError()}"
then there's no need to call SDL_ClearError()
before SDL_Something()
. The only time you really need SDL_ClearError()
is when a function doesn't tell you whether it succeeded or not, like this pseudocode:
SDL_ClearError()
SDL_SomeFunctionReturningVoid()
error = SDL_GetError()
if error:
warning "perhaps SDL_SomeFunctionReturningVoid() failed, or perhaps this is harmless, I can't really tell: {error}"
to minimize the chance that the error indicator is still set for some unrelated reason.
@smcv Thanks for the review! Definitely feel more confident I got it right this time with a second set of eyes on it. Re: the added |
You're the maintainer, and if you prefer to do it like this, do it like this. As I said, it's harmless, even if unnecessary. I believe the intention is that if a SDL function fails (not just "returns an empty result" if that's a thing that is possible, but actually fails), then it is guaranteed to set the error indicator, so that if it didn't, that would be considered to be a SDL bug. I'm actually more familiar with GLib and CPython than SDL, and in those C APIs, it is certainly intended to be an API guarantee that: if you call a function in a way that is not already considered to be a programming error (undefined behaviour), and it fails, then the error indicator will be set. Similarly, in the ISO/POSIX C library interface, most functions have it as an API guarantee that if you call the function and it fails, then |
That makes sense, thanks for the explanation! I'll leave the extra ClearErrors in if for now if they're harmless, but now I know that if I ever hit an error return value and it doesn't set a message it's something to report upstream to SDL proper. |
PR Description
Closes #257 (for real this time, I think). This fixes a bunch of assorted unit tests to only check for
SDL_GetError
output when a function's return value indicates a failure, sinceSDL_SetError
is often used internally by SDL2 to set non-fatal warning messages (leading to tests breaking unexpectedly with new SDL releases).Merge Checklist
closes #<issue-number>
to automatically close an issue