From 58766486665f4f508df3c715cb5fbfca1d104794 Mon Sep 17 00:00:00 2001 From: Nintorch <92302738+Nintorch@users.noreply.github.com> Date: Wed, 30 Jul 2025 19:14:49 +0500 Subject: [PATCH] Fix C# environment variables (SDL-related issue) For some reason, these SDL defines mess with C#'s ability to use environment variables --- drivers/sdl/SDL_build_config_private.h | 8 ++- thirdparty/README.md | 1 + .../sdl/patches/0006-fix-cs-environ.patch | 65 +++++++++++++++++++ thirdparty/sdl/stdlib/SDL_getenv.c | 15 +++++ 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 thirdparty/sdl/patches/0006-fix-cs-environ.patch diff --git a/drivers/sdl/SDL_build_config_private.h b/drivers/sdl/SDL_build_config_private.h index 49eca6619a6..7c18933e13f 100644 --- a/drivers/sdl/SDL_build_config_private.h +++ b/drivers/sdl/SDL_build_config_private.h @@ -87,9 +87,11 @@ #ifdef __linux__ #define HAVE_INOTIFY 1 #define HAVE_INOTIFY_INIT1 1 -#define HAVE_GETENV 1 -#define HAVE_SETENV 1 -#define HAVE_UNSETENV 1 +// Don't add these defines, for some reason they mess with C#'s ability +// to use environment variables (see GH-109024) +//#define HAVE_GETENV 1 +//#define HAVE_SETENV 1 +//#define HAVE_UNSETENV 1 #endif #ifdef DBUS_ENABLED diff --git a/thirdparty/README.md b/thirdparty/README.md index bcccb28154d..dc087bbc5e5 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -972,6 +972,7 @@ Patches: - `0003-std-include.patch` (GH-108144) - `0004-errno-include.patch` (GH-108354) - `0005-fix-libudev-dbus.patch` (GH-108373) +- `0006-fix-cs-environ.patch` (GH-109283) The SDL source code folder includes `hidapi` library inside of folder `thirdparty/sdl/hidapi/`. Its version and license is described in this file under `hidapi`. diff --git a/thirdparty/sdl/patches/0006-fix-cs-environ.patch b/thirdparty/sdl/patches/0006-fix-cs-environ.patch new file mode 100644 index 00000000000..0e49b06a176 --- /dev/null +++ b/thirdparty/sdl/patches/0006-fix-cs-environ.patch @@ -0,0 +1,65 @@ +diff --git a/thirdparty/sdl/stdlib/SDL_getenv.c b/thirdparty/sdl/stdlib/SDL_getenv.c +index b4a19224655..e23f8a0ea0d 100644 +--- a/thirdparty/sdl/stdlib/SDL_getenv.c ++++ b/thirdparty/sdl/stdlib/SDL_getenv.c +@@ -50,6 +50,9 @@ extern char **environ; + static char **environ; + #endif + ++#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_FREEBSD) ++#include ++#endif + + struct SDL_Environment + { +@@ -149,6 +152,9 @@ SDL_Environment *SDL_CreateEnvironment(bool populated) + + const char *SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name) + { ++#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_FREEBSD) ++ return getenv(name); ++#else + const char *result = NULL; + + if (!env) { +@@ -168,6 +174,7 @@ const char *SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name) + SDL_UnlockMutex(env->lock); + + return result; ++#endif + } + + typedef struct CountEnvStringsData +@@ -246,6 +253,9 @@ char **SDL_GetEnvironmentVariables(SDL_Environment *env) + + bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite) + { ++#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_FREEBSD) ++ return setenv(name, value, overwrite); ++#else + bool result = false; + + if (!env) { +@@ -281,10 +291,14 @@ bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const ch + SDL_UnlockMutex(env->lock); + + return result; ++#endif + } + + bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name) + { ++#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_FREEBSD) ++ return unsetenv(name); ++#else + bool result = false; + + if (!env) { +@@ -305,6 +319,7 @@ bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name) + SDL_UnlockMutex(env->lock); + + return result; ++#endif + } + + void SDL_DestroyEnvironment(SDL_Environment *env) diff --git a/thirdparty/sdl/stdlib/SDL_getenv.c b/thirdparty/sdl/stdlib/SDL_getenv.c index b4a19224655..e23f8a0ea0d 100644 --- a/thirdparty/sdl/stdlib/SDL_getenv.c +++ b/thirdparty/sdl/stdlib/SDL_getenv.c @@ -50,6 +50,9 @@ extern char **environ; static char **environ; #endif +#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_FREEBSD) +#include +#endif struct SDL_Environment { @@ -149,6 +152,9 @@ SDL_Environment *SDL_CreateEnvironment(bool populated) const char *SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name) { +#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_FREEBSD) + return getenv(name); +#else const char *result = NULL; if (!env) { @@ -168,6 +174,7 @@ const char *SDL_GetEnvironmentVariable(SDL_Environment *env, const char *name) SDL_UnlockMutex(env->lock); return result; +#endif } typedef struct CountEnvStringsData @@ -246,6 +253,9 @@ char **SDL_GetEnvironmentVariables(SDL_Environment *env) bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const char *value, bool overwrite) { +#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_FREEBSD) + return setenv(name, value, overwrite); +#else bool result = false; if (!env) { @@ -281,10 +291,14 @@ bool SDL_SetEnvironmentVariable(SDL_Environment *env, const char *name, const ch SDL_UnlockMutex(env->lock); return result; +#endif } bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name) { +#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_FREEBSD) + return unsetenv(name); +#else bool result = false; if (!env) { @@ -305,6 +319,7 @@ bool SDL_UnsetEnvironmentVariable(SDL_Environment *env, const char *name) SDL_UnlockMutex(env->lock); return result; +#endif } void SDL_DestroyEnvironment(SDL_Environment *env)