loadso: library handles are now SDL_SharedObject* instead of void*.

Improved the SDL_loadso.h documentation a little, too.

Fixes #11009.
This commit is contained in:
Ryan C. Gordon
2024-10-01 11:11:40 -04:00
parent f351395c46
commit 0b5e01a305
38 changed files with 102 additions and 73 deletions

View File

@@ -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);

View File

@@ -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.
}

View File

@@ -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);