libsdl-org / sdl2-compat

An SDL2 compatibility layer that uses SDL3 behind the scenes.
zlib License
80 stars 19 forks source link

Updated for latest SDL changes as of 604d0c519ecb4f9ea1c14423e9cb1c2a822ce764 #220

Closed sezero closed 2 months ago

sezero commented 2 months ago

Tests are failing, haven't investigated why (tired.) Please have a look.

sezero commented 2 months ago

I tried using SDL3 _unsafe versions for SDL_getenv and SDL_setenv, like:

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -517,18 +517,6 @@ SDL_ClearHints(void)
     SDL3_ResetHints();
 }

-SDL_DECLSPEC const char * SDLCALL
-SDL_getenv(const char *name)
-{
-    return SDL3_GetEnvironmentVariable(SDL3_GetEnvironment(), name);
-}
-
-SDL_DECLSPEC int SDLCALL
-SDL_setenv(const char *name, const char *value, int overwrite)
-{
-    return SDL3_SetEnvironmentVariable(SDL3_GetEnvironment(), name, value, !!overwrite);
-}
-
 static void
 SDL2Compat_ApplyQuirks(SDL_bool force_x11)
 {
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -742,6 +742,7 @@ SDL3_SYM_PASSTHROUGH(float,floorf,(float a),(a),return)
 SDL3_SYM_PASSTHROUGH(double,fmod,(double a, double b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(float,fmodf,(float a, float b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(void,free,(void *a),(a),)
+SDL3_SYM_RENAMED(const char*,getenv,getenv_unsafe,(const char *a),(a),return)
 SDL3_SYM(void,hid_ble_scan,(SDL_bool a),(a),)
 SDL3_SYM(int,hid_close,(SDL_hid_device *a),(a),return)
 SDL3_SYM_PASSTHROUGH(Uint32,hid_device_change_count,(void),(),return)
@@ -801,6 +802,7 @@ SDL3_SYM_PASSTHROUGH(double,round,(double a),(a),return)
 SDL3_SYM_PASSTHROUGH(float,roundf,(float a),(a),return)
 SDL3_SYM_PASSTHROUGH(double,scalbn,(double a, int b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(float,scalbnf,(float a, int b),(a,b),return)
+SDL3_SYM_RENAMED(int,setenv,setenv_unsafe,(const char *a, const char *b, int c),(a,b,c),return)
 SDL3_SYM_PASSTHROUGH(double,sin,(double a),(a),return)
 SDL3_SYM_PASSTHROUGH(float,sinf,(float a),(a),return)
 SDL3_SYM_PASSTHROUGH(double,sqrt,(double a),(a),return)

... but still failing. More tired...

slouken commented 2 months ago

Thanks for updating this, I'm taking a look.

slouken commented 2 months ago

Fixed in https://github.com/libsdl-org/sdl2-compat/pull/221