Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/SDL3/SDL_loadso.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ extern SDL_DECLSPEC SDL_FunctionPointer SDLCALL SDL_LoadFunction(SDL_SharedObjec
* SDL_LoadFunction() will no longer be valid.
*
* \param handle a valid shared object handle returned by SDL_LoadObject().
* \returns a boolean value, where true indicates success and false
* indicates 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.2.0.
*
* \sa SDL_LoadObject
*/
extern SDL_DECLSPEC void SDLCALL SDL_UnloadObject(SDL_SharedObject *handle);
extern SDL_DECLSPEC bool SDLCALL SDL_UnloadObject(SDL_SharedObject *handle);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Expand Down
12 changes: 9 additions & 3 deletions src/loadso/dlopen/SDL_sysloadso.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)
return symbol;
}

void SDL_UnloadObject(SDL_SharedObject *handle)
bool SDL_UnloadObject(SDL_SharedObject *handle)
{
if (handle) {
dlclose(handle);
if (!handle) {
return true;
}
int error_code = dlclose(handle);
if (error_code) {
SDL_SetError("Failed unloading library. Error code: %d. Message: %s
error_code, (const char *)dlerror());
}
return error_code == 0;
}

#endif // SDL_LOADSO_DLOPEN
4 changes: 2 additions & 2 deletions src/loadso/dummy/SDL_sysloadso.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)
return NULL;
}

void SDL_UnloadObject(SDL_SharedObject *handle)
bool SDL_UnloadObject(SDL_SharedObject *handle)
{
// no-op.
return true;
}

#endif // SDL_LOADSO_DUMMY
13 changes: 10 additions & 3 deletions src/loadso/windows/SDL_sysloadso.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle, const char *name)
return symbol;
}

void SDL_UnloadObject(SDL_SharedObject *handle)
bool SDL_UnloadObject(SDL_SharedObject *handle)
{
if (handle) {
FreeLibrary((HMODULE)handle);
if (!handle) {
return true;
}
bool success = FreeLibrary((HMODULE)handle);
if (!success) {
char errbuf[512];
SDL_snprintf(errbuf, sizeof (errbuf), "Failed unloading library");
WIN_SetError(errbuf);
}
return success;
}

#endif // SDL_LOADSO_WINDOWS
6 changes: 5 additions & 1 deletion test/testloadso.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ int main(int argc, char *argv[])
SDL_Log("Unloading library...");
}
}
SDL_UnloadObject(lib);
bool close_success = SDL_UnloadObject(lib);
if (!close_success) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_UnloadObject('%s') failed: %s",
libname, SDL_GetError());
}
}
SDL_Quit();
SDLTest_CommonDestroyState(state);
Expand Down