From 0b5e01a305bd752dbe476b79271ce8356373d50c Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 1 Oct 2024 11:11:40 -0400
Subject: [PATCH] loadso: library handles are now `SDL_SharedObject*` instead
of `void*`.
Improved the SDL_loadso.h documentation a little, too.
Fixes #11009.
---
docs/README-migration.md | 2 ++
include/SDL3/SDL_loadso.h | 34 +++++++++++++++++++++--
src/audio/aaudio/SDL_aaudio.c | 2 +-
src/audio/alsa/SDL_alsa_audio.c | 2 +-
src/audio/directsound/SDL_directsound.c | 2 +-
src/audio/jack/SDL_jackaudio.c | 2 +-
src/audio/pipewire/SDL_pipewire.c | 2 +-
src/audio/pulseaudio/SDL_pulseaudio.c | 2 +-
src/audio/sndio/SDL_sndioaudio.c | 2 +-
src/camera/pipewire/SDL_camera_pipewire.c | 2 +-
src/core/linux/SDL_dbus.c | 2 +-
src/core/linux/SDL_udev.h | 2 +-
src/dynapi/SDL_dynapi_procs.h | 6 ++--
src/gpu/d3d11/SDL_gpu_d3d11.c | 9 +++---
src/gpu/d3d12/SDL_gpu_d3d12.c | 8 +++---
src/hidapi/SDL_hidapi.c | 2 +-
src/joystick/gdk/SDL_gameinputjoystick.c | 2 +-
src/loadso/dlopen/SDL_sysloadso.c | 8 +++---
src/loadso/dummy/SDL_sysloadso.c | 12 ++++----
src/loadso/windows/SDL_sysloadso.c | 16 +++++------
src/render/direct3d11/SDL_render_d3d11.c | 4 +--
src/render/direct3d12/SDL_render_d3d12.c | 4 +--
src/storage/steam/SDL_steamstorage.c | 2 +-
src/test/SDL_test_memory.c | 2 +-
src/video/SDL_egl.c | 3 +-
src/video/SDL_egl_c.h | 3 +-
src/video/SDL_sysvideo.h | 4 +--
src/video/haiku/SDL_bopengl.cc | 2 +-
src/video/vivante/SDL_vivantevideo.h | 2 +-
src/video/wayland/SDL_waylanddyn.c | 2 +-
src/video/windows/SDL_windowskeyboard.c | 2 +-
src/video/windows/SDL_windowsmodes.c | 2 +-
src/video/windows/SDL_windowsvideo.h | 8 +++---
src/video/windows/SDL_windowswindow.c | 8 +++---
src/video/x11/SDL_x11dyn.c | 2 +-
src/video/x11/SDL_x11opengl.c | 2 +-
src/video/x11/SDL_x11video.h | 2 +-
test/testloadso.c | 2 +-
38 files changed, 102 insertions(+), 73 deletions(-)
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 7c13e0291ded4..27ef83256216e 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1104,6 +1104,8 @@ The following symbols have been renamed:
## SDL_loadso.h
+Shared object handles are now `SDL_SharedObject *`, an opaque type, instead of `void *`. This is just for type-safety and there is no functional difference.
+
SDL_LoadFunction() now returns `SDL_FunctionPointer` instead of `void *`, and should be cast to the appropriate function type. You can define SDL_FUNCTION_POINTER_IS_VOID_POINTER in your project to restore the previous behavior.
## SDL_log.h
diff --git a/include/SDL3/SDL_loadso.h b/include/SDL3/SDL_loadso.h
index ab34a38620beb..14b0b8086653a 100644
--- a/include/SDL3/SDL_loadso.h
+++ b/include/SDL3/SDL_loadso.h
@@ -26,6 +26,14 @@
*
* System-dependent library loading routines.
*
+ * Shared objects are code that is programmatically loadable at runtime.
+ * Windows calls these "DLLs", Linux calls them "shared libraries", etc.
+ *
+ * To use them, build such a library, then call SDL_LoadObject() on it.
+ * Once loaded, you can use SDL_LoadFunction() on that object to find the
+ * address of its exported symbols. When done with the object, call
+ * SDL_UnloadObject() to dispose of it.
+ *
* Some things to keep in mind:
*
* - These functions only work on C function names. Other languages may have
@@ -52,6 +60,17 @@
extern "C" {
#endif
+/**
+ * An opaque datatype that represents a loaded shared object.
+ *
+ * \since This datatype is available since SDL 3.0.0.
+ *
+ * \sa SDL_LoadObject
+ * \sa SDL_LoadFunction
+ * \sa SDL_UnloadObject
+ */
+typedef struct SDL_SharedObject SDL_SharedObject;
+
/**
* Dynamically load a shared object.
*
@@ -59,12 +78,14 @@ extern "C" {
* \returns an opaque pointer to the object handle or NULL on failure; call
* SDL_GetError() for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_LoadFunction
* \sa SDL_UnloadObject
*/
-extern SDL_DECLSPEC void * SDLCALL SDL_LoadObject(const char *sofile);
+extern SDL_DECLSPEC SDL_SharedObject * SDLCALL SDL_LoadObject(const char *sofile);
/**
* Look up the address of the named function in a shared object.
@@ -86,22 +107,29 @@ extern SDL_DECLSPEC void * SDLCALL SDL_LoadObject(const char *sofile);
* \returns a pointer to the function or NULL on failure; call SDL_GetError()
* for more information.
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_LoadObject
*/
-extern SDL_DECLSPEC SDL_FunctionPointer SDLCALL SDL_LoadFunction(void *handle, const char *name);
+extern SDL_DECLSPEC SDL_FunctionPointer SDLCALL SDL_LoadFunction(SDL_SharedObject *handle, const char *name);
/**
* Unload a shared object from memory.
*
+ * Note that any pointers from this object looked up through SDL_LoadFunction()
+ * will no longer be valid.
+ *
* \param handle a valid shared object handle returned by SDL_LoadObject().
*
+ * \threadsafety It is safe to call this function from any thread.
+ *
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_LoadObject
*/
-extern SDL_DECLSPEC void SDLCALL SDL_UnloadObject(void *handle);
+extern SDL_DECLSPEC void SDLCALL SDL_UnloadObject(SDL_SharedObject *handle);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
diff --git a/src/audio/aaudio/SDL_aaudio.c b/src/audio/aaudio/SDL_aaudio.c
index 7d6e5cb0c7d1e..c53157ee070ac 100644
--- a/src/audio/aaudio/SDL_aaudio.c
+++ b/src/audio/aaudio/SDL_aaudio.c
@@ -55,7 +55,7 @@ struct SDL_PrivateAudioData
typedef struct AAUDIO_Data
{
- void *handle;
+ SDL_SharedObject *handle;
#define SDL_PROC(ret, func, params) ret (*func) params;
#include "SDL_aaudiofuncs.h"
} AAUDIO_Data;
diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c
index cf67a42fc18f9..8b804c4b8588e 100644
--- a/src/audio/alsa/SDL_alsa_audio.c
+++ b/src/audio/alsa/SDL_alsa_audio.c
@@ -91,7 +91,7 @@ static int (*ALSA_snd_pcm_chmap_print)(const snd_pcm_chmap_t *map, size_t maxlen
#define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof
static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC;
-static void *alsa_handle = NULL;
+static SDL_SharedObject *alsa_handle = NULL;
static bool load_alsa_sym(const char *fn, void **addr)
{
diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c
index 43864b2cd1bb6..609e1b37aeeef 100644
--- a/src/audio/directsound/SDL_directsound.c
+++ b/src/audio/directsound/SDL_directsound.c
@@ -39,7 +39,7 @@ static bool SupportsIMMDevice = false;
#endif
// DirectX function pointers for audio
-static void *DSoundDLL = NULL;
+static SDL_SharedObject *DSoundDLL = NULL;
typedef HRESULT(WINAPI *fnDirectSoundCreate8)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN);
typedef HRESULT(WINAPI *fnDirectSoundEnumerateW)(LPDSENUMCALLBACKW, LPVOID);
typedef HRESULT(WINAPI *fnDirectSoundCaptureCreate8)(LPCGUID, LPDIRECTSOUNDCAPTURE8 *, LPUNKNOWN);
diff --git a/src/audio/jack/SDL_jackaudio.c b/src/audio/jack/SDL_jackaudio.c
index 958348ed9daff..b590386e90f7d 100644
--- a/src/audio/jack/SDL_jackaudio.c
+++ b/src/audio/jack/SDL_jackaudio.c
@@ -51,7 +51,7 @@ static bool load_jack_syms(void);
#ifdef SDL_AUDIO_DRIVER_JACK_DYNAMIC
static const char *jack_library = SDL_AUDIO_DRIVER_JACK_DYNAMIC;
-static void *jack_handle = NULL;
+static SDL_SharedObject *jack_handle = NULL;
// !!! FIXME: this is copy/pasted in several places now
static bool load_jack_sym(const char *fn, void **addr)
diff --git a/src/audio/pipewire/SDL_pipewire.c b/src/audio/pipewire/SDL_pipewire.c
index 1cfe9a8d1b93b..d803c8d736805 100644
--- a/src/audio/pipewire/SDL_pipewire.c
+++ b/src/audio/pipewire/SDL_pipewire.c
@@ -92,7 +92,7 @@ static int (*PIPEWIRE_pw_properties_setf)(struct pw_properties *, const char *,
#ifdef SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC
static const char *pipewire_library = SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC;
-static void *pipewire_handle = NULL;
+static SDL_SharedObject *pipewire_handle = NULL;
static bool pipewire_dlsym(const char *fn, void **addr)
{
diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c
index 733904362b3cd..0961bdaed2466 100644
--- a/src/audio/pulseaudio/SDL_pulseaudio.c
+++ b/src/audio/pulseaudio/SDL_pulseaudio.c
@@ -134,7 +134,7 @@ static bool load_pulseaudio_syms(void);
#ifdef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
static const char *pulseaudio_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC;
-static void *pulseaudio_handle = NULL;
+static SDL_SharedObject *pulseaudio_handle = NULL;
static bool load_pulseaudio_sym(const char *fn, void **addr)
{
diff --git a/src/audio/sndio/SDL_sndioaudio.c b/src/audio/sndio/SDL_sndioaudio.c
index 91cfe79da6b39..0776a4529fec9 100644
--- a/src/audio/sndio/SDL_sndioaudio.c
+++ b/src/audio/sndio/SDL_sndioaudio.c
@@ -66,7 +66,7 @@ static void (*SNDIO_sio_initpar)(struct sio_par *);
#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
static const char *sndio_library = SDL_AUDIO_DRIVER_SNDIO_DYNAMIC;
-static void *sndio_handle = NULL;
+static SDL_SharedObject *sndio_handle = NULL;
static bool load_sndio_sym(const char *fn, void **addr)
{
diff --git a/src/camera/pipewire/SDL_camera_pipewire.c b/src/camera/pipewire/SDL_camera_pipewire.c
index 2631e640d4780..edbda290326c2 100644
--- a/src/camera/pipewire/SDL_camera_pipewire.c
+++ b/src/camera/pipewire/SDL_camera_pipewire.c
@@ -101,7 +101,7 @@ static int (*PIPEWIRE_pw_properties_setf)(struct pw_properties *, const char *,
#ifdef SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC
static const char *pipewire_library = SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC;
-static void *pipewire_handle = NULL;
+static SDL_SharedObject *pipewire_handle = NULL;
static bool pipewire_dlsym(const char *fn, void **addr)
{
diff --git a/src/core/linux/SDL_dbus.c b/src/core/linux/SDL_dbus.c
index b13d27bfbba60..371e16e0a4a0f 100644
--- a/src/core/linux/SDL_dbus.c
+++ b/src/core/linux/SDL_dbus.c
@@ -26,7 +26,7 @@
#ifdef SDL_USE_LIBDBUS
// we never link directly to libdbus.
static const char *dbus_library = "libdbus-1.so.3";
-static void *dbus_handle = NULL;
+static SDL_SharedObject *dbus_handle = NULL;
static char *inhibit_handle = NULL;
static unsigned int screensaver_cookie = 0;
static SDL_DBusContext dbus;
diff --git a/src/core/linux/SDL_udev.h b/src/core/linux/SDL_udev.h
index d501b385edc9a..c165bfecb6fa0 100644
--- a/src/core/linux/SDL_udev.h
+++ b/src/core/linux/SDL_udev.h
@@ -86,7 +86,7 @@ typedef struct SDL_UDEV_Symbols
typedef struct SDL_UDEV_PrivateData
{
const char *udev_library;
- void *udev_handle;
+ SDL_SharedObject *udev_handle;
struct udev *udev;
struct udev_monitor *udev_mon;
int ref_count;
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index cfaec9dad77e5..214ced1bf6c30 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -654,8 +654,8 @@ SDL_DYNAPI_PROC(SDL_Surface*,SDL_LoadBMP,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_Surface*,SDL_LoadBMP_IO,(SDL_IOStream *a, bool b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_LoadFile,(const char *a, size_t *b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_LoadFile_IO,(SDL_IOStream *a, size_t *b, bool c),(a,b,c),return)
-SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_LoadFunction,(void *a, const char *b),(a,b),return)
-SDL_DYNAPI_PROC(void*,SDL_LoadObject,(const char *a),(a),return)
+SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_LoadFunction,(SDL_SharedObject *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_SharedObject*,SDL_LoadObject,(const char *a),(a),return)
SDL_DYNAPI_PROC(bool,SDL_LoadWAV,(const char *a, SDL_AudioSpec *b, Uint8 **c, Uint32 *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(bool,SDL_LoadWAV_IO,(SDL_IOStream *a, bool b, SDL_AudioSpec *c, Uint8 **d, Uint32 *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(bool,SDL_LockAudioStream,(SDL_AudioStream *a),(a),return)
@@ -973,7 +973,7 @@ SDL_DYNAPI_PROC(bool,SDL_TryWaitSemaphore,(SDL_Semaphore *a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_UCS4ToUTF8,(Uint32 a, char *b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_UnbindAudioStream,(SDL_AudioStream *a),(a),)
SDL_DYNAPI_PROC(void,SDL_UnbindAudioStreams,(SDL_AudioStream **a, int b),(a,b),)
-SDL_DYNAPI_PROC(void,SDL_UnloadObject,(void *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_UnloadObject,(SDL_SharedObject *a),(a),)
SDL_DYNAPI_PROC(bool,SDL_UnlockAudioStream,(SDL_AudioStream *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_UnlockJoysticks,(void),(),)
SDL_DYNAPI_PROC(void,SDL_UnlockMutex,(SDL_Mutex *a),(a),)
diff --git a/src/gpu/d3d11/SDL_gpu_d3d11.c b/src/gpu/d3d11/SDL_gpu_d3d11.c
index 39bbd9e2f1f25..ff3b9370be691 100644
--- a/src/gpu/d3d11/SDL_gpu_d3d11.c
+++ b/src/gpu/d3d11/SDL_gpu_d3d11.c
@@ -737,9 +737,9 @@ struct D3D11Renderer
IDXGIInfoQueue *dxgiInfoQueue;
#endif
- void *d3d11_dll;
- void *dxgi_dll;
- void *dxgidebug_dll;
+ SDL_SharedObject *d3d11_dll;
+ SDL_SharedObject *dxgi_dll;
+ SDL_SharedObject *dxgidebug_dll;
Uint8 debugMode;
BOOL supportsTearing;
@@ -5886,7 +5886,8 @@ static bool D3D11_SupportsTextureFormat(
static bool D3D11_PrepareDriver(SDL_VideoDevice *this)
{
- void *d3d11_dll, *dxgi_dll;
+ SDL_SharedObject *d3d11_dll;
+ SDL_SharedObject *dxgi_dll;
PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc;
D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_1 };
PFN_CREATE_DXGI_FACTORY1 CreateDxgiFactoryFunc;
diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c
index cc002160fa036..31bc048650f9e 100644
--- a/src/gpu/d3d12/SDL_gpu_d3d12.c
+++ b/src/gpu/d3d12/SDL_gpu_d3d12.c
@@ -576,8 +576,8 @@ struct D3D12Renderer
IDXGIInfoQueue *dxgiInfoQueue;
#endif
IDXGIAdapter1 *adapter;
- void *dxgi_dll;
- void *dxgidebug_dll;
+ SDL_SharedObject *dxgi_dll;
+ SDL_SharedObject *dxgidebug_dll;
#endif
ID3D12Debug *d3d12Debug;
bool supportsTearing;
@@ -7762,8 +7762,8 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this)
#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
return true;
#else
- void *d3d12Dll;
- void *dxgiDll;
+ SDL_SharedObject *d3d12Dll;
+ SDL_SharedObject *dxgiDll;
PFN_D3D12_CREATE_DEVICE D3D12CreateDeviceFunc;
PFN_CREATE_DXGI_FACTORY1 CreateDXGIFactoryFunc;
HRESULT res;
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index d40e9a9289381..890bc23475329 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -695,7 +695,7 @@ typedef struct DRIVER_hid_device_ DRIVER_hid_device;
static struct
{
- void *libhandle;
+ SDL_SharedObject *libhandle;
/* *INDENT-OFF* */ // clang-format off
int (LIBUSB_CALL *init)(libusb_context **ctx);
diff --git a/src/joystick/gdk/SDL_gameinputjoystick.c b/src/joystick/gdk/SDL_gameinputjoystick.c
index 77ce854f4715c..8b53f8d60b6c8 100644
--- a/src/joystick/gdk/SDL_gameinputjoystick.c
+++ b/src/joystick/gdk/SDL_gameinputjoystick.c
@@ -60,7 +60,7 @@ typedef struct joystick_hwdata
} GAMEINPUT_InternalJoystickHwdata;
static GAMEINPUT_InternalList g_GameInputList = { NULL };
-static void *g_hGameInputDLL = NULL;
+static SDL_SharedObject *g_hGameInputDLL = NULL;
static IGameInput *g_pGameInput = NULL;
static GameInputCallbackToken g_GameInputCallbackToken = GAMEINPUT_INVALID_CALLBACK_TOKEN_VALUE;
static Uint64 g_GameInputTimestampOffset;
diff --git a/src/loadso/dlopen/SDL_sysloadso.c b/src/loadso/dlopen/SDL_sysloadso.c
index 66c64b12c993d..58bf3e0b63511 100644
--- a/src/loadso/dlopen/SDL_sysloadso.c
+++ b/src/loadso/dlopen/SDL_sysloadso.c
@@ -32,7 +32,7 @@
#include "../../video/uikit/SDL_uikitvideo.h"
#endif
-void *SDL_LoadObject(const char *sofile)
+SDL_SharedObject *SDL_LoadObject(const char *sofile)
{
void *handle;
const char *loaderror;
@@ -49,10 +49,10 @@ void *SDL_LoadObject(const char *sofile)
if (!handle) {
SDL_SetError("Failed loading %s: %s", sofile, loaderror);
}
- return handle;
+ return (SDL_SharedObject *) handle;
}
-SDL_FunctionPointer SDL_LoadFunction(void *handle, const char *name)
+SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)
{
void *symbol = dlsym(handle, name);
if (!symbol) {
@@ -72,7 +72,7 @@ SDL_FunctionPointer SDL_LoadFunction(void *handle, const char *name)
return symbol;
}
-void SDL_UnloadObject(void *handle)
+void SDL_UnloadObject(SDL_SharedObject *handle)
{
if (handle) {
dlclose(handle);
diff --git a/src/loadso/dummy/SDL_sysloadso.c b/src/loadso/dummy/SDL_sysloadso.c
index 34de994b9e5a2..9092f2772d9ae 100644
--- a/src/loadso/dummy/SDL_sysloadso.c
+++ b/src/loadso/dummy/SDL_sysloadso.c
@@ -25,21 +25,19 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// System dependent library loading routines
-void *SDL_LoadObject(const char *sofile)
+SDL_SharedObject *SDL_LoadObject(const char *sofile)
{
- const char *loaderror = "SDL_LoadObject() not implemented";
- SDL_SetError("Failed loading %s: %s", sofile, loaderror);
+ SDL_Unsupported();
return NULL;
}
-SDL_FunctionPointer SDL_LoadFunction(void *handle, const char *name)
+SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)
{
- const char *loaderror = "SDL_LoadFunction() not implemented";
- SDL_SetError("Failed loading %s: %s", name, loaderror);
+ SDL_Unsupported();
return NULL;
}
-void SDL_UnloadObject(void *handle)
+void SDL_UnloadObject(SDL_SharedObject *handle)
{
// no-op.
}
diff --git a/src/loadso/windows/SDL_sysloadso.c b/src/loadso/windows/SDL_sysloadso.c
index b069a9c325580..67fceb0d00185 100644
--- a/src/loadso/windows/SDL_sysloadso.c
+++ b/src/loadso/windows/SDL_sysloadso.c
@@ -27,7 +27,7 @@
#include "../../core/windows/SDL_windows.h"
-void *SDL_LoadObject(const char *sofile)
+SDL_SharedObject *SDL_LoadObject(const char *sofile)
{
if (!sofile) {
SDL_InvalidParamError("sofile");
@@ -35,32 +35,30 @@ void *SDL_LoadObject(const char *sofile)
}
LPWSTR wstr = WIN_UTF8ToStringW(sofile);
- void *handle = (void *)LoadLibrary(wstr);
+ HMODULE handle = LoadLibraryW(wstr);
SDL_free(wstr);
// Generate an error message if all loads failed
if (!handle) {
char errbuf[512];
- SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
- SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
+ SDL_snprintf(errbuf, sizeof (errbuf), "Failed loading %s", sofile);
WIN_SetError(errbuf);
}
- return handle;
+ return (SDL_SharedObject *) handle;
}
-SDL_FunctionPointer SDL_LoadFunction(void *handle, const char *name)
+SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)
{
SDL_FunctionPointer symbol = (SDL_FunctionPointer)GetProcAddress((HMODULE)handle, name);
if (!symbol) {
char errbuf[512];
- SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
- SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
+ SDL_snprintf(errbuf, sizeof (errbuf), "Failed loading %s", name);
WIN_SetError(errbuf);
}
return symbol;
}
-void SDL_UnloadObject(void *handle)
+void SDL_UnloadObject(SDL_SharedObject *handle)
{
if (handle) {
FreeLibrary((HMODULE)handle);
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index 2bb829e046f0e..1d9b291346f11 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -153,8 +153,8 @@ typedef struct
// Private renderer data
typedef struct
{
- void *hDXGIMod;
- void *hD3D11Mod;
+ SDL_SharedObject *hDXGIMod;
+ SDL_SharedObject *hD3D11Mod;
IDXGIFactory2 *dxgiFactory;
IDXGIAdapter *dxgiAdapter;
IDXGIDebug *dxgiDebug;
diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c
index f444505f9eda5..df6e7e417e06a 100644
--- a/src/render/direct3d12/SDL_render_d3d12.c
+++ b/src/render/direct3d12/SDL_render_d3d12.c
@@ -179,8 +179,8 @@ typedef struct
// Private renderer data
typedef struct
{
- void *hDXGIMod;
- void *hD3D12Mod;
+ SDL_SharedObject *hDXGIMod;
+ SDL_SharedObject *hD3D12Mod;
#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
UINT64 frameToken;
#else
diff --git a/src/storage/steam/SDL_steamstorage.c b/src/storage/steam/SDL_steamstorage.c
index 07e5def83b54e..ca0188ee73180 100644
--- a/src/storage/steam/SDL_steamstorage.c
+++ b/src/storage/steam/SDL_steamstorage.c
@@ -32,7 +32,7 @@
typedef struct STEAM_RemoteStorage
{
- void *libsteam_api;
+ SDL_SharedObject *libsteam_api;
#define STEAM_PROC(ret, func, parms) \
steamfntype_##func func;
#include "SDL_steamstorage_proc.h"
diff --git a/src/test/SDL_test_memory.c b/src/test/SDL_test_memory.c
index 524404dc54e77..1b7907263bd8b 100644
--- a/src/test/SDL_test_memory.c
+++ b/src/test/SDL_test_memory.c
@@ -34,7 +34,7 @@ static bool s_unwind_symbol_names = true;
#include <dbghelp.h>
static struct {
- HMODULE module;
+ SDL_SharedObject *module;
BOOL (WINAPI *pSymInitialize)(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess);
BOOL (WINAPI *pSymFromAddr)(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol);
BOOL (WINAPI *pSymGetLineFromAddr64)(HANDLE hProcess, DWORD64 qwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line);
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 53886b989c677..c85c6abc60d65 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -299,7 +299,8 @@ void SDL_EGL_UnloadLibrary(SDL_VideoDevice *_this)
static bool SDL_EGL_LoadLibraryInternal(SDL_VideoDevice *_this, const char *egl_path)
{
- void *egl_dll_handle = NULL, *opengl_dll_handle = NULL;
+ SDL_SharedObject *egl_dll_handle = NULL;
+ SDL_SharedObject *opengl_dll_handle = NULL;
const char *path = NULL;
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
const char *d3dcompiler;
diff --git a/src/video/SDL_egl_c.h b/src/video/SDL_egl_c.h
index e330471c7db7c..05410f62cf44f 100644
--- a/src/video/SDL_egl_c.h
+++ b/src/video/SDL_egl_c.h
@@ -64,7 +64,8 @@ typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSy
typedef struct SDL_EGL_VideoData
{
- void *opengl_dll_handle, *egl_dll_handle;
+ SDL_SharedObject *opengl_dll_handle;
+ SDL_SharedObject *egl_dll_handle;
EGLDisplay egl_display;
EGLConfig egl_config;
int egl_swapinterval;
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index bc3571f0fe2c2..aada061e9b225 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -437,7 +437,7 @@ struct SDL_VideoDevice
int egl_platform;
int driver_loaded;
char driver_path[256];
- void *dll_handle;
+ SDL_SharedObject *dll_handle;
} gl_config;
SDL_EGLAttribArrayCallback egl_platformattrib_callback;
@@ -467,7 +467,7 @@ struct SDL_VideoDevice
SDL_FunctionPointer vkEnumerateInstanceExtensionProperties;
int loader_loaded;
char loader_path[256];
- void *loader_handle;
+ SDL_SharedObject *loader_handle;
} vulkan_config;
/* * * */
diff --git a/src/video/haiku/SDL_bopengl.cc b/src/video/haiku/SDL_bopengl.cc
index e69e08c353647..11235982a3ca6 100644
--- a/src/video/haiku/SDL_bopengl.cc
+++ b/src/video/haiku/SDL_bopengl.cc
@@ -56,7 +56,7 @@ bool HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
if ( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
&location) == B_OK) {
- _this->gl_config.dll_handle = (void *) (addr_t) info.id;
+ _this->gl_config.dll_handle = (SDL_SharedObject *) (addr_t) info.id;
_this->gl_config.driver_loaded = 1;
SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
SDL_arraysize(_this->gl_config.driver_path));
diff --git a/src/video/vivante/SDL_vivantevideo.h b/src/video/vivante/SDL_vivantevideo.h
index e4bd0c9e92015..b24d85ca03a5a 100644
--- a/src/video/vivante/SDL_vivantevideo.h
+++ b/src/video/vivante/SDL_vivantevideo.h
@@ -39,7 +39,7 @@ struct SDL_VideoData
#ifdef SDL_VIDEO_DRIVER_VIVANTE_VDK
vdkPrivate vdk_private;
#else
- void *egl_handle; // EGL shared library handle
+ SDL_SharedObject *egl_handle; // EGL shared library handle
EGLNativeDisplayType(EGLAPIENTRY *fbGetDisplay)(void *context);
EGLNativeDisplayType(EGLAPIENTRY *fbGetDisplayByIndex)(int DisplayIndex);
void(EGLAPIENTRY *fbGetDisplayGeometry)(EGLNativeDisplayType Display, int *Width, int *Height);
diff --git a/src/video/wayland/SDL_waylanddyn.c b/src/video/wayland/SDL_waylanddyn.c
index bee980f06b5f7..ea15da397a698 100644
--- a/src/video/wayland/SDL_waylanddyn.c
+++ b/src/video/wayland/SDL_waylanddyn.c
@@ -30,7 +30,7 @@
typedef struct
{
- void *lib;
+ SDL_SharedObject *lib;
const char *libname;
} waylanddynlib;
diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c
index e494e4502225e..74bb8c15ca770 100644
--- a/src/video/windows/SDL_windowskeyboard.c
+++ b/src/video/windows/SDL_windowskeyboard.c
@@ -606,7 +606,7 @@ static DWORD IME_GetId(SDL_VideoData *videodata, UINT uIndex)
static void IME_SetupAPI(SDL_VideoData *videodata)
{
char ime_file[MAX_PATH + 1];
- void *hime = 0;
+ SDL_SharedObject *hime = 0;
HKL hkl = 0;
videodata->GetReadingString = NULL;
videodata->ShowReadingWindow = NULL;
diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c
index 472c5bf2938f1..221db107a3eda 100644
--- a/src/video/windows/SDL_windowsmodes.c
+++ b/src/video/windows/SDL_windowsmodes.c
@@ -393,7 +393,7 @@ static bool WIN_GetMonitorDESC1(HMONITOR hMonitor, DXGI_OUTPUT_DESC1 *desc)
{
typedef HRESULT (WINAPI * PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc = NULL;
- void *hDXGIMod = NULL;
+ SDL_SharedObject *hDXGIMod = NULL;
bool found = false;
hDXGIMod = SDL_LoadObject("dxgi.dll");
diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h
index 869e8ad3666e8..87eaaaf47e66c 100644
--- a/src/video/windows/SDL_windowsvideo.h
+++ b/src/video/windows/SDL_windowsvideo.h
@@ -389,7 +389,7 @@ struct SDL_VideoData
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) // Xbox doesn't support user32/shcore
// Touch input functions
- void *userDLL;
+ SDL_SharedObject *userDLL;
/* *INDENT-OFF* */ // clang-format off
BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT );
BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int );
@@ -410,7 +410,7 @@ struct SDL_VideoData
LONG (WINAPI *DisplayConfigGetDeviceInfo)( DISPLAYCONFIG_DEVICE_INFO_HEADER*);
/* *INDENT-ON* */ // clang-format on
- void *shcoreDLL;
+ SDL_SharedObject *shcoreDLL;
/* *INDENT-OFF* */ // clang-format off
HRESULT (WINAPI *GetDpiForMonitor)( HMONITOR hmonitor,
MONITOR_DPI_TYPE dpiType,
@@ -421,7 +421,7 @@ struct SDL_VideoData
#endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
#ifdef HAVE_DXGI_H
- void *dxgiDLL;
+ SDL_SharedObject *dxgiDLL;
IDXGIFactory *pDXGIFactory;
#endif
@@ -475,7 +475,7 @@ struct SDL_VideoData
#ifndef SDL_DISABLE_WINDOWS_IME
HKL ime_hkl;
- void *ime_himm32;
+ SDL_SharedObject *ime_himm32;
/* *INDENT-OFF* */ // clang-format off
UINT (WINAPI *GetReadingString)(HIMC himc, UINT uReadingBufLen, LPWSTR lpwReadingBuf, PINT pnErrorIndex, BOOL *pfIsVertical, PUINT puMaxReadingLen);
BOOL (WINAPI *ShowReadingWindow)(HIMC himc, BOOL bShow);
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 9d1d820c49f9c..3954dcc780200 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -740,7 +740,7 @@ bool WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properties
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
// FIXME: does not work on all hardware configurations with different renders (i.e. hybrid GPUs)
if (window->flags & SDL_WINDOW_TRANSPARENT) {
- void *handle = SDL_LoadObject("dwmapi.dll");
+ SDL_SharedObject *handle = SDL_LoadObject("dwmapi.dll");
if (handle) {
DwmEnableBlurBehindWindow_t DwmEnableBlurBehindWindowFunc = (DwmEnableBlurBehindWindow_t)SDL_LoadFunction(handle, "DwmEnableBlurBehindWindow");
if (DwmEnableBlurBehindWindowFunc) {
@@ -1199,7 +1199,7 @@ static DWM_WINDOW_CORNER_PREFERENCE WIN_UpdateCornerRoundingForHWND(HWND hwnd, D
{
DWM_WINDOW_CORNER_PREFERENCE oldPref = DWMWCP_DEFAULT;
- void *handle = SDL_LoadObject("dwmapi.dll");
+ SDL_SharedObject *handle = SDL_LoadObject("dwmapi.dll");
if (handle) {
DwmGetWindowAttribute_t DwmGetWindowAttributeFunc = (DwmGetWindowAttribute_t)SDL_LoadFunction(handle, "DwmGetWindowAttribute");
DwmSetWindowAttribute_t DwmSetWindowAttributeFunc = (DwmSetWindowAttribute_t)SDL_LoadFunction(handle, "DwmSetWindowAttribute");
@@ -1218,7 +1218,7 @@ static COLORREF WIN_UpdateBorderColorForHWND(HWND hwnd, COLORREF colorRef)
{
COLORREF oldPref = DWMWA_COLOR_DEFAULT;
- void *handle = SDL_LoadObject("dwmapi.dll");
+ SDL_SharedObject *handle = SDL_LoadObject("dwmapi.dll");
if (handle) {
DwmGetWindowAttribute_t DwmGetWindowAttributeFunc = (DwmGetWindowAttribute_t)SDL_LoadFunction(handle, "DwmGetWindowAttribute");
DwmSetWindowAttribute_t DwmSetWindowAttributeFunc = (DwmSetWindowAttribute_t)SDL_LoadFunction(handle, "DwmSetWindowAttribute");
@@ -2223,7 +2223,7 @@ bool WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool foc
void WIN_UpdateDarkModeForHWND(HWND hwnd)
{
- void *handle = SDL_LoadObject("dwmapi.dll");
+ SDL_SharedObject *handle = SDL_LoadObject("dwmapi.dll");
if (handle) {
DwmSetWindowAttribute_t DwmSetWindowAttributeFunc = (DwmSetWindowAttribute_t)SDL_LoadFunction(handle, "DwmSetWindowAttribute");
if (DwmSetWindowAttributeFunc) {
diff --git a/src/video/x11/SDL_x11dyn.c b/src/video/x11/SDL_x11dyn.c
index e2220e526e09b..0c73360d48819 100644
--- a/src/video/x11/SDL_x11dyn.c
+++ b/src/video/x11/SDL_x11dyn.c
@@ -34,7 +34,7 @@
typedef struct
{
- void *lib;
+ SDL_SharedObject *lib;
const char *libname;
} x11dynlib;
diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c
index 8230c8d24ec9d..7eb6f467e043d 100644
--- a/src/video/x11/SDL_x11opengl.c
+++ b/src/video/x11/SDL_x11opengl.c
@@ -164,7 +164,7 @@ static void X11_GL_InitExtensions(SDL_VideoDevice *_this);
bool X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
Display *display;
- void *handle;
+ SDL_SharedObject *handle;
if (_this->
(Patch may be truncated, please check the link at the top of this post.)