rwops: Reworked RWops for SDL3.

- SDL_RWops is now an opaque struct.
- SDL_AllocRW is gone. If an app is creating a custom RWops, they pass the
  function pointers to SDL_CreateRW(), which are stored internally.
- SDL_RWclose is gone, there is only SDL_DestroyRW(), which calls the
  implementation's `->close` method before freeing other things.
- There is only one path to create and use RWops now, so we don't have to
  worry about whether `->close` will call SDL_DestroyRW, or if this will
  risk any Properties not being released, etc.
- SDL_RWFrom* still works as expected, for getting a RWops without having
  to supply your own implementation. Objects from these functions are also
  destroyed with SDL_DestroyRW.
- Lots of other cleanup and SDL3ization of the library code.
This commit is contained in:
Ryan C. Gordon
2024-03-12 01:14:38 -04:00
parent 495e432fb9
commit 525919b315
22 changed files with 424 additions and 470 deletions

View File

@@ -55,7 +55,7 @@ rwops_error_quit(unsigned line, SDL_RWops *rwops)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
if (rwops) {
SDL_RWclose(rwops); /* This calls SDL_DestroyRW(rwops); */
SDL_DestroyRW(rwops);
}
cleanup();
SDLTest_CommonDestroyState(state);
@@ -126,25 +126,25 @@ int main(int argc, char *argv[])
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
SDL_RWclose(rwops);
SDL_DestroyRW(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "wb+");
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
SDL_RWclose(rwops);
SDL_DestroyRW(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "ab");
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
SDL_RWclose(rwops);
SDL_DestroyRW(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "ab+");
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
SDL_RWclose(rwops);
SDL_DestroyRW(rwops);
unlink(FBASENAME2);
SDL_Log("test2 OK\n");
@@ -171,7 +171,7 @@ int main(int argc, char *argv[])
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
}
SDL_RWclose(rwops);
SDL_DestroyRW(rwops);
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exist */
if (!rwops) {
@@ -208,7 +208,7 @@ int main(int argc, char *argv[])
RWOP_ERR_QUIT(rwops); /* readonly mode */
}
SDL_RWclose(rwops);
SDL_DestroyRW(rwops);
/* test 3: same with w+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
@@ -258,7 +258,7 @@ int main(int argc, char *argv[])
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
RWOP_ERR_QUIT(rwops);
}
SDL_RWclose(rwops);
SDL_DestroyRW(rwops);
SDL_Log("test3 OK\n");
/* test 4: same in r+ mode */
@@ -309,7 +309,7 @@ int main(int argc, char *argv[])
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
RWOP_ERR_QUIT(rwops);
}
SDL_RWclose(rwops);
SDL_DestroyRW(rwops);
SDL_Log("test4 OK\n");
/* test5 : append mode */
@@ -366,7 +366,7 @@ int main(int argc, char *argv[])
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30) != 0) {
RWOP_ERR_QUIT(rwops);
}
SDL_RWclose(rwops);
SDL_DestroyRW(rwops);
SDL_Log("test5 OK\n");
cleanup();
SDL_Quit();