SDL_CreateRenderer changes errno

Hi,

I’ve noticed while using recent RCs of SDL2 (SDL2-2.0.0.tar.gz under current Ubuntu x86-64) that errno gets set multiple times during a call to SDL_CreateRenderer. The function seems to succeed just fine and the SDL error state is clear.

Some details:
-The code which calls SDL_CreateRenderer is in a slightly modified version of this file (https://code.google.com/p/crag/source/browse/src/core/app.cpp?spec=svnbef1e55fae41edbe1391f8c0a651c4e2b407513b&name=windows&r=bef1e55fae41edbe1391f8c0a651c4e2b407513b).
-Setting flags to zero doesn’t make a difference.
-The SDL function in which the calls are made is: X11_GL_CreateContext from SDL_x11opengl.c.
-In particular, two calls to Xsync cause errno to be set to: 11 ‘Resource temporarily unavailable’. This is the value that errno is left with on exit.
-Additionally, a call to glXCreateContext sets it to 19 (don’t have the error string for this one but I can get it if you like)
I’m wondering if this is known about and whether it’s par for the course for SDL calls to be leaving errno set. I’m guessing not because it means I have to reset it after SDL calls in order to reliably use it elsewhere.

Thanks,
John

Quoth jmcfarlane , on 2013-06-25 18:58:19 -0700:

I’m wondering if this is known about and whether it’s par for the
course for SDL calls to be leaving errno set. I’m guessing not
because it means I have to reset it after SDL calls in order to
reliably use it elsewhere.

No, it means you have to reset it before a specific other call that is
documented to use errno if that’s the only way you intend to test for
errors afterwards, which is usually indicative of doing something
wrong. Almost any function call can trample errno in C. The main
time it’s guaranteed to correspond to anything in particular is after
a call that fails (which is tested by some other mechanism, such as
return value) and is documented to use errno as its error reporting
strategy (which the SDL functions generally don’t).

Consider what would happen if this weren’t true. Anyone writing
libraries would have to remember to do ? errno = 0; ? after every
gettimeofday() or similar.

Thanks,
John

—> Drake Wilson

Yes, you are correct that I could clear errno ahead of every test, but I prefer not to - a choice which I mistakenly decided to pass over for brevity’s sake. Mostly, I wanted to make sure that there isn’t a problem with the X11 implementation and to understand what to expect from SDL with respect to errno. Thank you for clearing up the second bit.

John McFarlane

Note that this problem seems to have gone away with recent updates.