Skip to content

Commit

Permalink
Rwobject SDL3 fixes for 3.1.3 RC
Browse files Browse the repository at this point in the history
  • Loading branch information
Starbuck5 committed Oct 6, 2024
1 parent 4a3b6df commit 7202d48
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src_c/rwobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static size_t
_pg_rw_read(void *, void *, size_t, SDL_IOStatus *);
static size_t
_pg_rw_write(void *, const void *, size_t, SDL_IOStatus *);
static int
static bool
_pg_rw_close(void *);
#else
static Sint64
Expand Down Expand Up @@ -434,25 +434,30 @@ _pg_rw_write(SDL_RWops *context, const void *ptr, size_t size, size_t num)
}

#if SDL_VERSION_ATLEAST(3, 0, 0)
static int
static bool
_pg_rw_close(void *userdata)
{
pgRWHelper *helper = (pgRWHelper *)userdata;
bool retval = true;
#else
static int
_pg_rw_close(SDL_RWops *context)
{
pgRWHelper *helper = (pgRWHelper *)context->hidden.unknown.data1;
int retval = 0;
#endif
PyObject *result;
int retval = 0;
PyGILState_STATE state = PyGILState_Ensure();

if (helper->close) {
result = PyObject_CallNoArgs(helper->close);
if (!result) {
PyErr_Print();
#if SDL_VERSION_ATLEAST(3, 0, 0)
retval = false;
#else
retval = -1;
#endif
}
Py_XDECREF(result);
}
Expand Down Expand Up @@ -515,7 +520,7 @@ pgRWops_FromFileObject(PyObject *obj)
return (SDL_RWops *)RAISE(PyExc_IOError, SDL_GetError());
}

if (SDL_SetBooleanProperty(props, "_pygame_is_file_object", 1) < 0) {
if (!SDL_SetBooleanProperty(props, "_pygame_is_file_object", 1)) {
PyMem_Free(helper);
return (SDL_RWops *)RAISE(PyExc_IOError, SDL_GetError());
}
Expand Down Expand Up @@ -683,7 +688,11 @@ _rwops_from_pystr(PyObject *obj, char **extptr)
/* If out of memory, decref oencoded to be safe, and try
* to close out `rw` as well. */
Py_DECREF(oencoded);
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (!SDL_RWclose(rw)) {
#else
if (SDL_RWclose(rw) < 0) {
#endif
PyErr_SetString(PyExc_IOError, SDL_GetError());
}
return (SDL_RWops *)PyErr_NoMemory();
Expand Down

0 comments on commit 7202d48

Please sign in to comment.