diff --git a/.gitignore b/.gitignore index 98860fa..0ddfeef 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /sdl2-compat-2.30.52.tar.gz +/sdl2-compat-2.32.50.tar.gz diff --git a/2347d5c89752c43107f9a0a8108a6b6ac46bbfa0.patch b/2347d5c89752c43107f9a0a8108a6b6ac46bbfa0.patch new file mode 100644 index 0000000..8b7b791 --- /dev/null +++ b/2347d5c89752c43107f9a0a8108a6b6ac46bbfa0.patch @@ -0,0 +1,27 @@ +From 2347d5c89752c43107f9a0a8108a6b6ac46bbfa0 Mon Sep 17 00:00:00 2001 +From: Ozkan Sezer +Date: Mon, 10 Feb 2025 23:37:14 +0300 +Subject: [PATCH] SDL2Compat_strlen: hack to prevent gcc optimizing the code + into strlen + +making retval volatile prevents gcc optimizing the code into strlen and +defeating the purpose of the procedure. + +Fixes https://github.com/libsdl-org/sdl2-compat/issues/340 +--- + src/sdl2_compat.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c +index fa570c4a..c00ec035 100644 +--- a/src/sdl2_compat.c ++++ b/src/sdl2_compat.c +@@ -251,7 +251,7 @@ SDL2COMPAT_itoa(char *dst, int val) + /* you can use SDL3_strlen once we're past startup. */ + static int SDL2Compat_strlen(const char *str) + { +- int retval = 0; ++ volatile int retval = 0; /* volatile prevents gcc from optimizing this into strlen() */ + while (str[retval]) { + retval++; + } diff --git a/f58c132840b51aac184d17593ab60d41b54c9ba9.patch b/f58c132840b51aac184d17593ab60d41b54c9ba9.patch new file mode 100644 index 0000000..507cb44 --- /dev/null +++ b/f58c132840b51aac184d17593ab60d41b54c9ba9.patch @@ -0,0 +1,111 @@ +From f58c132840b51aac184d17593ab60d41b54c9ba9 Mon Sep 17 00:00:00 2001 +From: Cameron Gutman +Date: Sun, 9 Feb 2025 18:06:00 -0600 +Subject: [PATCH] env: sync environment variables during subsystem init (#339) + +--- + src/sdl2_compat.c | 28 +++++++++++++++++++++++++++- + src/sdl3_syms.h | 5 +++++ + 2 files changed, 32 insertions(+), 1 deletion(-) + +diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c +index 64a85da0..ca9ebaeb 100644 +--- a/src/sdl2_compat.c ++++ b/src/sdl2_compat.c +@@ -5567,10 +5567,31 @@ SDL_RemoveTimer(SDL2_TimerID id) + return SDL3_RemoveTimer((SDL_TimerID)id) ? SDL2_TRUE : SDL2_FALSE; + } + ++static void SynchronizeEnvironmentVariables() ++{ ++ SDL_Environment *env = SDL3_GetEnvironment(); ++ SDL_Environment *fresh_env = SDL3_CreateEnvironment(true); ++ ++ /* Sync any changes to the C environment into SDL3's cached copy */ ++ char **fresh_envp = SDL3_GetEnvironmentVariables(fresh_env); ++ if (fresh_envp) { ++ for (int i = 0; fresh_envp[i]; i++) { ++ char *sep = SDL3_strchr(fresh_envp[i], '='); ++ *sep = '\0'; ++ SDL3_SetEnvironmentVariable(env, fresh_envp[i], sep + 1, true); ++ } ++ ++ SDL3_free(fresh_envp); ++ } ++ ++ SDL3_DestroyEnvironment(fresh_env); ++} + + SDL_DECLSPEC int SDLCALL + SDL_AudioInit(const char *driver_name) + { ++ SynchronizeEnvironmentVariables(); ++ + if (driver_name) { + SDL3_SetHint("SDL_AUDIO_DRIVER", driver_name); + } +@@ -5777,6 +5798,9 @@ SDL_DECLSPEC int SDLCALL + SDL_VideoInit(const char *driver_name) + { + int ret; ++ ++ SynchronizeEnvironmentVariables(); ++ + if (driver_name) { + SDL3_SetHint("SDL_VIDEO_DRIVER", driver_name); + } +@@ -5813,6 +5837,8 @@ SDL_InitSubSystem(Uint32 flags) + return -1; + } + ++ SynchronizeEnvironmentVariables(); ++ + /* Update IME UI hint */ + if (flags & SDL_INIT_VIDEO) { + const char *old_hint; +@@ -6464,7 +6490,7 @@ SDL_OpenAudio(SDL2_AudioSpec *desired2, SDL2_AudioSpec *obtained2) + + /* Start up the audio driver, if necessary. This is legacy behaviour! */ + if (!SDL3_WasInit(SDL_INIT_AUDIO)) { +- if (!SDL3_InitSubSystem(SDL_INIT_AUDIO)) { ++ if (SDL_AudioInit(NULL) < 0) { + return -1; + } + } +diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h +index 3738e55b..16a9ba06 100644 +--- a/src/sdl3_syms.h ++++ b/src/sdl3_syms.h +@@ -139,6 +139,7 @@ SDL3_SYM(SDL_AudioStream*,CreateAudioStream,(const SDL_AudioSpec *a, const SDL_A + SDL3_SYM(SDL_Cursor*,CreateColorCursor,(SDL_Surface *a, int b, int c),(a,b,c),return) + SDL3_SYM_RENAMED(SDL_Condition*,CreateCond,CreateCondition,(void),(),return) + SDL3_SYM_PASSTHROUGH(SDL_Cursor*,CreateCursor,(const Uint8 *a, const Uint8 *b, int c, int d, int e, int f),(a,b,c,d,e,f),return) ++SDL3_SYM(SDL_Environment*,CreateEnvironment,(bool a),(a),return) + SDL3_SYM(int,CreateHapticEffect,(SDL_Haptic *a, const SDL_HapticEffect *b),(a,b),return) + SDL3_SYM_PASSTHROUGH(SDL_Mutex*,CreateMutex,(void),(),return) + SDL3_SYM(SDL_Window*,CreatePopupWindow,(SDL_Window *a, int b, int c, int d, int e, SDL_WindowFlags f),(a,b,c,d,e,f),return) +@@ -159,6 +160,7 @@ SDL3_SYM(void,RemoveHintCallback,(const char *a, SDL_HintCallback b, void *c),(a + SDL3_SYM_PASSTHROUGH(void,Delay,(Uint32 a),(a),) + SDL3_SYM(void,DestroyAudioStream,(SDL_AudioStream *a),(a),) + SDL3_SYM_RENAMED(void,DestroyCond,DestroyCondition,(SDL_Condition *a),(a),) ++SDL3_SYM(void,DestroyEnvironment,(SDL_Environment *a),(a),) + SDL3_SYM_PASSTHROUGH(void,DestroyMutex,(SDL_Mutex *a),(a),) + SDL3_SYM(void,DestroyPalette,(SDL_Palette *a),(a),) + SDL3_SYM(void,DestroyProperties,(SDL_PropertiesID a),(a),) +@@ -273,6 +275,8 @@ SDL3_SYM(SDL_DisplayID,GetDisplayForWindow,(SDL_Window *a),(a),return) + SDL3_SYM(const char*,GetDisplayName,(SDL_DisplayID a),(a),return) + SDL3_SYM(bool,GetDisplayUsableBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return) + SDL3_SYM(SDL_DisplayID*,GetDisplays,(int *a),(a),return) ++SDL3_SYM(SDL_Environment*,GetEnvironment,(void),(),return) ++SDL3_SYM(char**,GetEnvironmentVariables,(SDL_Environment *a),(a),return) + SDL3_SYM_PASSTHROUGH(const char*,GetError,(void),(),return) + SDL3_SYM(bool,GetEventFilter,(SDL_EventFilter *a, void **b),(a,b),) + SDL3_SYM(float,GetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return) +@@ -607,6 +611,7 @@ SDL3_SYM(bool,SetAudioStreamPutCallback,(SDL_AudioStream *a, SDL_AudioStreamCall + SDL3_SYM(bool,SetBooleanProperty,(SDL_PropertiesID a, const char *b, bool c),(a,b,c),return) + SDL3_SYM_PASSTHROUGH_RETCODE(bool,SetClipboardText,(const char *a),(a),return) + SDL3_SYM(bool,SetCursor,(SDL_Cursor *a),(a),return) ++SDL3_SYM(bool,SetEnvironmentVariable,(SDL_Environment *a, const char *b, const char *c, bool d),(a,b,c,d),return) + SDL3_SYM(void,SetEventEnabled,(Uint32 a, bool b),(a,b),) + SDL3_SYM(void,SetEventFilter,(SDL_EventFilter a, void *b),(a,b),) + SDL3_SYM(void,SetGamepadEventsEnabled,(bool a),(a),) diff --git a/sdl2-compat.spec b/sdl2-compat.spec index 48c75c7..6336056 100644 --- a/sdl2-compat.spec +++ b/sdl2-compat.spec @@ -1,4 +1,4 @@ -%global sdl3_minver 3.2.2 +%global sdl3_minver 3.2.4 # Features disabled for RHEL %if 0%{?rhel} @@ -8,7 +8,7 @@ %endif Name: sdl2-compat -Version: 2.30.52 +Version: 2.32.50 Release: 1%{?dist} SourceLicense: Zlib and Apache-2.0 and MIT and BSD-3-Clause Summary: SDL 2.0 runtime compatibility library using SDL 3.0 @@ -20,6 +20,10 @@ Source1: SDL2_config.h Source2: SDL2_revision.h # Backports from upstream (0001~0500) +## Sync env vars properly +Patch0001: f58c132840b51aac184d17593ab60d41b54c9ba9.patch +## Fix strlen +Patch0002: 2347d5c89752c43107f9a0a8108a6b6ac46bbfa0.patch # Proposed patches (0501~1000) @@ -35,7 +39,7 @@ BuildRequires: mesa-libGL-devel BuildRequires: mesa-libGLU-devel # This replaces SDL2 Obsoletes: SDL2 < 2.30.11-2 -Conflicts: SDL2 < 2.30.50~ +Conflicts: SDL2 < 2.32.50~ Provides: SDL2 = %{version} Provides: SDL2%{?_isa} = %{version} # This dlopens SDL3 (?!), so manually depend on it @@ -58,7 +62,7 @@ License: Zlib and Apache-2.0 and MIT and BSD-3-Clause Requires: %{name}%{?_isa} = %{version}-%{release} # This replaces SDL2-devel Obsoletes: SDL2-devel < 2.30.11-2 -Conflicts: SDL2-devel < 2.30.50~ +Conflicts: SDL2-devel < 2.32.50~ Provides: SDL2-devel = %{version} Provides: SDL2-devel%{?_isa} = %{version} %if ! %{with static} @@ -91,7 +95,7 @@ Summary: Static library to develop SDL 2.0 applications using SDL 3.0 Requires: %{name}-devel%{?_isa} = %{version}-%{release} # This replaces SDL2-static Obsoletes: SDL2-static < 2.30.11-2 -Conflicts: SDL2-static < 2.30.50~ +Conflicts: SDL2-static < 2.32.50~ Provides: SDL2-static = %{version} Provides: SDL2-static%{?_isa} = %{version} @@ -166,6 +170,13 @@ install -p -m 644 %{SOURCE2} %{buildroot}%{_includedir}/SDL2/SDL_revision.h %changelog +* Mon Feb 10 2025 Neal Gompa - 2.32.50-1 +- Update to 2.32.50 +- Backport fixes from upstream + + Correctly handle SDL environment variables + + Fix to avoid over optimizing away internal strlen + Resolves: RHEL-77078 + * Mon Feb 10 2025 Wim Taymans - 2.30.52-1 Initial commit on c10s Resolves: RHEL-77078 diff --git a/sources b/sources index 3b3b4cd..3a2311e 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -SHA512 (sdl2-compat-2.30.52.tar.gz) = ddcc99fda3188605367389d6e5908bb3b01ac300aab22aea60e02156b5e51f599b695a950bd3c7f3f2a7c2c1a1fb713ff56d4fb5fe69ea7b38baf45347c7f0ca +SHA512 (sdl2-compat-2.32.50.tar.gz) = fd3ea427d5ed7a4363b6e72d27d5d42daca09e26fd24a9e30c4ca427169b03a21d1f0ae366d2ce19b29e7d3a5ff0dd158321dadb1a362feb4436f0ea8a6b3add