Functions which return function pointers now return SDL_FunctionPointer instead of void*

This fixes the clang warning "Cast between pointer-to-function and pointer-to-object is an extension"

You can define SDL_FUNCTION_POINTER_IS_VOID_POINTER in your project to restore the previous behavior.

Fixes https://github.com/libsdl-org/SDL/issues/2866
This commit is contained in:
Sam Lantinga
2023-01-09 14:55:12 -08:00
parent 7275b2b352
commit e9b86eebf3
43 changed files with 272 additions and 356 deletions

View File

@@ -89,8 +89,8 @@ extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile);
* \sa SDL_LoadObject
* \sa SDL_UnloadObject
*/
extern DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle,
const char *name);
extern DECLSPEC SDL_FunctionPointer SDL_LoadFunction(void *handle,
const char *name);
/**
* Unload a shared object from memory.

View File

@@ -738,6 +738,13 @@ SDL_FORCE_INLINE int SDL_size_add_overflow_builtin (size_t a,
#define SDL_size_add_overflow(a, b, ret) (SDL_size_add_overflow_builtin(a, b, ret))
#endif
/* This is a generic function pointer which should be cast to the type you expect */
#ifdef SDL_FUNCTION_POINTER_IS_VOID_POINTER
typedef void *SDL_FunctionPointer;
#else
typedef void (*SDL_FunctionPointer)(void);
#endif
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}

View File

@@ -1723,7 +1723,7 @@ extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path);
* \sa SDL_GL_LoadLibrary
* \sa SDL_GL_UnloadLibrary
*/
extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
extern DECLSPEC SDL_FunctionPointer SDLCALL SDL_GL_GetProcAddress(const char *proc);
/**
* Get an EGL library function by name.
@@ -1740,7 +1740,7 @@ extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
*
* \sa SDL_GL_GetCurrentEGLDisplay
*/
extern DECLSPEC void *SDLCALL SDL_EGL_GetProcAddress(const char *proc);
extern DECLSPEC SDL_FunctionPointer SDLCALL SDL_EGL_GetProcAddress(const char *proc);
/**
* Unload the OpenGL library previously loaded by SDL_GL_LoadLibrary().

View File

@@ -111,11 +111,17 @@ extern DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
* This should be called after either calling SDL_Vulkan_LoadLibrary() or
* creating an SDL_Window with the `SDL_WINDOW_VULKAN` flag.
*
* The actual type of the returned function pointer is PFN_vkGetInstanceProcAddr,
* but that isn't available because the Vulkan headers are not included here. You
* should cast the return value of this function to that type, e.g.
*
* `vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_Vulkan_GetVkGetInstanceProcAddr();`
*
* \returns the function pointer for `vkGetInstanceProcAddr` or NULL on error.
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC void *SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
extern DECLSPEC SDL_FunctionPointer SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
/**
* Unload the Vulkan library previously loaded by SDL_Vulkan_LoadLibrary()