From 5d2d66ddb609b318987af1bd79018dba9732a07c Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Thu, 13 Mar 2025 17:55:02 +0300
Subject: [PATCH] sync with latest SDL2
---
include/SDL2/SDL_render.h | 2 +-
src/dynapi/SDL_dynapi.c | 19 ++++++++++++-------
src/dynapi/SDL_dynapi.h | 2 ++
test/testautomation_stdlib.c | 12 ++++++++++++
4 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/include/SDL2/SDL_render.h b/include/SDL2/SDL_render.h
index b5a70f35..52741721 100644
--- a/include/SDL2/SDL_render.h
+++ b/include/SDL2/SDL_render.h
@@ -244,7 +244,7 @@ extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
* \since This function is available since SDL 2.0.0.
*
* \sa SDL_CreateRenderer
- * \sa SDL_CreateWindowRenderer
+ * \sa SDL_CreateWindowAndRenderer
* \sa SDL_DestroyRenderer
*/
extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c
index 3070cdf9..f851b4ab 100644
--- a/src/dynapi/SDL_dynapi.c
+++ b/src/dynapi/SDL_dynapi.c
@@ -447,25 +447,30 @@ DynApiExitProcess(int exitcode)
static void SDL_InitDynamicAPILocked(void)
{
+ SDL_DYNAPI_ENTRYFN entry = NULL; /* funcs from here by default. */
+ bool use_internal = true;
+
/* this can't use SDL_getenv_REAL, because the SDL3 version behind the scenes allocates memory before the app can set their allocator */
#if (defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_CYGWIN)) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
/* We've always used LoadLibraryA for this, so this has never worked with Unicode paths on Windows. Sorry. */
char envbuf[512]; /* overflows will just report as environment variable being unset, but LoadLibraryA has a MAX_PATH of 260 anyhow, apparently. */
const DWORD rc = GetEnvironmentVariableA(SDL_DYNAMIC_API_ENVVAR, envbuf, (DWORD) sizeof (envbuf));
- const char *libname = ((rc != 0) && (rc < sizeof (envbuf))) ? envbuf : NULL;
+ char *libname = ((rc != 0) && (rc < sizeof (envbuf))) ? envbuf : NULL;
+#elif defined(SDL_PLATFORM_OS2)
+ char * libname;
+ if (DosScanEnv(SDL_DYNAMIC_API_ENVVAR, &libname) != NO_ERROR) {
+ libname = NULL;
+ }
#else
- const char *libname = getenv(SDL_DYNAMIC_API_ENVVAR);
+ char *libname = getenv(SDL_DYNAMIC_API_ENVVAR);
#endif
- SDL_DYNAPI_ENTRYFN entry = NULL; /* funcs from here by default. */
- bool use_internal = true;
-
if (libname) {
while (*libname && !entry) {
// This is evil, but we're not making any permanent changes...
- char *ptr = (char *)libname;
+ char *ptr = libname;
while (true) {
- char ch = *ptr;
+ const char ch = *ptr;
if ((ch == ',') || (ch == '\0')) {
*ptr = '\0';
entry = (SDL_DYNAPI_ENTRYFN)get_sdlapi_entry(libname, "SDL_DYNAPI_entry");
diff --git a/src/dynapi/SDL_dynapi.h b/src/dynapi/SDL_dynapi.h
index 4390670b..5180cfcf 100644
--- a/src/dynapi/SDL_dynapi.h
+++ b/src/dynapi/SDL_dynapi.h
@@ -57,6 +57,8 @@
#define SDL_DYNAMIC_API 0
#elif defined(SDL_PLATFORM_RISCOS) /* probably not useful on RISC OS, since dlopen() can't be used when using static linking. */
#define SDL_DYNAMIC_API 0
+#elif defined(SDL_PLATFORM_PSP)
+#define SDL_DYNAMIC_API 0
#elif defined(__clang_analyzer__) || defined(SDL_THREAD_SAFETY_ANALYSIS)
#define SDL_DYNAMIC_API 0 /* Turn off for static analysis, so reports are more clear. */
#elif defined(SDL_PLATFORM_VITA)
diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c
index b4979b0d..7393fa6c 100644
--- a/test/testautomation_stdlib.c
+++ b/test/testautomation_stdlib.c
@@ -416,6 +416,7 @@ int stdlib_sscanf(void *arg)
long long long_long_output, expected_long_long_output, long_long_length;
size_t size_output, expected_size_output;
char text[128], text2[128];
+ unsigned int r = 0, g = 0, b = 0;
expected_output = output = 123;
expected_result = -1;
@@ -451,6 +452,17 @@ int stdlib_sscanf(void *arg)
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
SDLTest_AssertCheck(length == 1, "Check length, expected: 1, got: %i", length);
+ expected_result = 3;
+ result = SDL_sscanf("#026", "#%1x%1x%1x", &r, &g, &b);
+ SDLTest_AssertPass("Call to SDL_sscanf(\"#026\", \"#%%1x%%1x%%1x\", &r, &g, &b)");
+ expected_output = 0;
+ SDLTest_AssertCheck(r == expected_output, "Check output for r, expected: %i, got: %i", expected_output, r);
+ expected_output = 2;
+ SDLTest_AssertCheck(g == expected_output, "Check output for g, expected: %i, got: %i", expected_output, g);
+ expected_output = 6;
+ SDLTest_AssertCheck(b == expected_output, "Check output for b, expected: %i, got: %i", expected_output, b);
+ SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
+
#define SIZED_TEST_CASE(type, var, printf_specifier, scanf_specifier) \
var##_output = 123; \
var##_length = 0; \