[vlc-commits] [Git][videolan/vlc][master] 2 commits: win32: don't cast GetProcAddress to void *

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Feb 4 10:08:53 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
77f7adb9 by Steve Lhomme at 2025-02-04T09:47:56+00:00
win32: don't cast GetProcAddress to void *

>From https://code.videolan.org/videolan/vlc/-/merge_requests/6750#note_470781

> the C standard doesn't guarantee that you can cast a function pointer into a
> void* it only guarantees you that you can cast a function pointer to another
> function pointer.

It requires an extension C17 N2176 J.5.7:

> A pointer to an object or to void may be cast to a pointer to a function,
> allowing data to be invoked as a function (6.5.4).

> A pointer to a function may be cast to a pointer to an object or to void,
> allowing a function to be inspected or modified (for example, by a debugger) (6.5.4)

- - - - -
62d32ff5 by Steve Lhomme at 2025-02-04T09:47:56+00:00
win32: cast the GetProcAddress return to the proper function signature

- - - - -


5 changed files:

- modules/video_output/win32/direct3d9.c
- modules/video_output/win32/wgl.c
- src/win32/plugin.c
- src/win32/thread.c
- src/win32/timer.c


Changes:

=====================================
modules/video_output/win32/direct3d9.c
=====================================
@@ -667,7 +667,7 @@ static int Direct3D9CompileShader(vout_display_t *vd, const char *shader_source,
 {
     vout_display_sys_t *sys = vd->sys;
 
-    HRESULT (WINAPI * OurD3DXCompileShader)(
+    typedef HRESULT (WINAPI * OurD3DXCompileShader_ptr)(
             LPCSTR pSrcData,
             UINT srcDataLen,
             const D3DXMACRO *pDefines,
@@ -679,7 +679,8 @@ static int Direct3D9CompileShader(vout_display_t *vd, const char *shader_source,
             LPD3DXBUFFER *ppErrorMsgs,
             LPD3DXCONSTANTTABLE *ppConstantTable);
 
-    OurD3DXCompileShader = (void*)GetProcAddress(sys->hxdll, "D3DXCompileShader");
+    OurD3DXCompileShader_ptr OurD3DXCompileShader;
+    OurD3DXCompileShader = (OurD3DXCompileShader_ptr)GetProcAddress(sys->hxdll, "D3DXCompileShader");
     if (!OurD3DXCompileShader) {
         msg_Warn(vd, "Cannot locate reference to D3DXCompileShader; pixel shading will be disabled");
         return VLC_EGENERIC;


=====================================
modules/video_output/win32/wgl.c
=====================================
@@ -271,11 +271,11 @@ static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
     vout_display_sys_t *sys = gl->sys;
 
     /* See https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions */
-    void *f= (void *)wglGetProcAddress(name);
+    PROC f= wglGetProcAddress(name);
     if(f == 0 || (f == (void*)0x1) || (f == (void*)0x2) ||
       (f == (void*)0x3) || (f == (void*)-1) )
     {
-        f = (void *)GetProcAddress(sys->hOpengl, name);
+        f = GetProcAddress(sys->hOpengl, name);
     }
     return f;
 }


=====================================
src/win32/plugin.c
=====================================
@@ -88,5 +88,5 @@ int vlc_dlclose(void *handle)
 
 void *vlc_dlsym(void *handle, const char *psz_function)
 {
-    return (void *)GetProcAddress(handle, psz_function);
+    return GetProcAddress(handle, psz_function);
 }


=====================================
src/win32/thread.c
=====================================
@@ -174,13 +174,17 @@ retry:
 }
 
 /*** Futeces^WAddress waits ***/
-static HRESULT (WINAPI *SetThreadDescription_)(HANDLE, PCWSTR);
+typedef HRESULT (WINAPI *SetThreadDescription_ptr)(HANDLE, PCWSTR);
+static SetThreadDescription_ptr SetThreadDescription_;
 #if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
-static BOOL (WINAPI *WaitOnAddress_)(VOID volatile *, PVOID, SIZE_T, DWORD);
+typedef BOOL (WINAPI *WaitOnAddress_ptr)(VOID volatile *, PVOID, SIZE_T, DWORD);
+static WaitOnAddress_ptr WaitOnAddress_;
 #define WaitOnAddress (*WaitOnAddress_)
-static VOID (WINAPI *WakeByAddressAll_)(PVOID);
+typedef VOID (WINAPI *WakeByAddressAll_ptr)(PVOID);
+static WakeByAddressAll_ptr WakeByAddressAll_;
 #define WakeByAddressAll (*WakeByAddressAll_)
-static VOID (WINAPI *WakeByAddressSingle_)(PVOID);
+typedef VOID (WINAPI *WakeByAddressSingle_ptr)(PVOID);
+static WakeByAddressSingle_ptr WakeByAddressSingle_;
 #define WakeByAddressSingle (*WakeByAddressSingle_)
 
 static struct wait_addr_bucket
@@ -704,7 +708,7 @@ void vlc_threads_setup(libvlc_int_t *vlc)
 #endif
 }
 
-#define LOOKUP(s) (((s##_) = (void *)GetProcAddress(h, #s)) != NULL)
+#define LOOKUP(s) (((s##_) = (s##_ptr)GetProcAddress(h, #s)) != NULL)
 
 int __stdcall DllMain (void *hinstDll, unsigned long fdwReason, void *lpvReserved)
 {


=====================================
src/win32/timer.c
=====================================
@@ -47,7 +47,8 @@ static VOID CALLBACK timer_callback(PTP_CALLBACK_INSTANCE instance,
 
 #if _WIN32_WINNT < _WIN32_WINNT_WIN8
 static vlc_once_t TIMER_INIT_FUNC = VLC_STATIC_ONCE;
-static void (WINAPI *SystemTimeAsFileTime_)(LPFILETIME);
+typedef void (WINAPI *SystemTimeAsFileTime_ptr)(LPFILETIME);
+static SystemTimeAsFileTime_ptr SystemTimeAsFileTime_;
 #endif // _WIN32_WINNT < _WIN32_WINNT_WIN8
 
 int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data)
@@ -57,7 +58,7 @@ int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data)
 #if _WIN32_WINNT < _WIN32_WINNT_WIN8
     if (unlikely(!vlc_once_begin(&TIMER_INIT_FUNC))) {
         HMODULE h = GetModuleHandle(TEXT("kernel32.dll"));
-        SystemTimeAsFileTime_ = (void*)GetProcAddress(h, "GetSystemTimePreciseAsFileTime");
+        SystemTimeAsFileTime_ = (SystemTimeAsFileTime_ptr)GetProcAddress(h, "GetSystemTimePreciseAsFileTime");
         if (unlikely(SystemTimeAsFileTime_ == NULL)) // win7
             SystemTimeAsFileTime_ = GetSystemTimeAsFileTime;
         vlc_once_complete(&TIMER_INIT_FUNC);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f2f31340bb5e6718fbf3a73361e2f2e3503a5399...62d32ff578b095fd758dbb297e93d85fa53b441d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f2f31340bb5e6718fbf3a73361e2f2e3503a5399...62d32ff578b095fd758dbb297e93d85fa53b441d
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list