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

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