Remove/replace SDL_Read(BE|LE)*
These functions...
Uint32
SDL_ReadLE32(SDL_RWops *src)
{
Uint32 value = 0;
SDL_RWread(src, &value, sizeof(value));
return SDL_SwapLE32(value);
}
...do not report i/o errors, so you might get a byteswapped zero that isn't actually the data you thought it would be, and no way to know it failed.
The Write equivalent of these functions do report errors; they return a size_t that's either 1 or 0 depending on whether the write succeeded. I can live with that, but the size_t seems excessive, and also these functions are two lines each, so perhaps not strictly necessary to be in SDL3.
Should we remove or replace these?
They've been handy for various projects, though I agree the lack of error checking is a problem. The write functions were written before SDL_bool, and should probably be switched to that.
Maybe the read versions should be something like this?
SDL_bool SDL_ReadLE32(SDL_RWops *src, Uint32 *value)
{
Uint32 v;
if (SDL_RWread(src, &v, sizeof(v)) == sizeof(v)) {
if (value) {
*value = SDL_SwapLE32(v);
}
return SDL_TRUE;
}
return SDL_FALSE;
}
Or maybe they should return int, for consistency with the rest of the API?
In c++ and rustland, I've seen uses of try_ variants to allow functions to fail.
So for SDL in c land, have:
SDL_bool SDL_TryReadLE32(SDL_RWops *src, Uint32 *value); // can fail
Uint32 SDL_ReadLE32(SDL_RWops *src); // cannot fail
These would also translate fine to these safe language bindings.
They've been handy for various projects, though I agree the lack of error checking is a problem. The write functions were written before SDL_bool, and should probably be switched to that.
Maybe the read versions should be something like this?
SDL_bool SDL_ReadLE32(SDL_RWops *src, Uint32 *value) { Uint32 v; if (SDL_RWread(src, &v, sizeof(v)) == sizeof(v)) { if (value) { *value = SDL_SwapLE32(v); } return SDL_TRUE; } return SDL_FALSE; }
Looks reasonable to me.
Might go with an int return value (success, failure, this-rwops-is-non-blocking-please-retry-later).
Sam took care of this in b903ccf945a75266ebcba2df68da3b796a71e75d.