Skip to content

Commit 8a6e2f0

Browse files
committed
Use auto to remove long typedefs in dlsym/GetProcAddress calls.
1 parent f8400db commit 8a6e2f0

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

src/_c_internal_utils.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ mpl_xdisplay_is_valid(void)
4141
// than dlopen().
4242
if (getenv("DISPLAY")
4343
&& (libX11 = dlopen("libX11.so.6", RTLD_LAZY))) {
44-
typedef struct Display* (*XOpenDisplay_t)(char const*);
45-
typedef int (*XCloseDisplay_t)(struct Display*);
4644
struct Display* display = nullptr;
47-
XOpenDisplay_t XOpenDisplay = (XOpenDisplay_t)dlsym(libX11, "XOpenDisplay");
48-
XCloseDisplay_t XCloseDisplay = (XCloseDisplay_t)dlsym(libX11, "XCloseDisplay");
45+
auto XOpenDisplay = (struct Display* (*)(char const*))
46+
dlsym(libX11, "XOpenDisplay");
47+
auto XCloseDisplay = (int (*)(struct Display*))
48+
dlsym(libX11, "XCloseDisplay");
4949
if (XOpenDisplay && XCloseDisplay
5050
&& (display = XOpenDisplay(nullptr))) {
5151
XCloseDisplay(display);
@@ -73,13 +73,11 @@ mpl_display_is_valid(void)
7373
void* libwayland_client;
7474
if (getenv("WAYLAND_DISPLAY")
7575
&& (libwayland_client = dlopen("libwayland-client.so.0", RTLD_LAZY))) {
76-
typedef struct wl_display* (*wl_display_connect_t)(char const*);
77-
typedef void (*wl_display_disconnect_t)(struct wl_display*);
7876
struct wl_display* display = nullptr;
79-
wl_display_connect_t wl_display_connect =
80-
(wl_display_connect_t)dlsym(libwayland_client, "wl_display_connect");
81-
wl_display_disconnect_t wl_display_disconnect =
82-
(wl_display_disconnect_t)dlsym(libwayland_client, "wl_display_disconnect");
77+
auto wl_display_connect = (struct wl_display* (*)(char const*))
78+
dlsym(libwayland_client, "wl_display_connect");
79+
auto wl_display_disconnect = (void (*)(struct wl_display*))
80+
dlsym(libwayland_client, "wl_display_disconnect");
8381
if (wl_display_connect && wl_display_disconnect
8482
&& (display = wl_display_connect(nullptr))) {
8583
wl_display_disconnect(display);
@@ -162,25 +160,19 @@ mpl_SetProcessDpiAwareness_max(void)
162160
#ifdef _DPI_AWARENESS_CONTEXTS_
163161
// These functions and options were added in later Windows 10 updates, so
164162
// must be loaded dynamically.
165-
typedef BOOL (WINAPI *IsValidDpiAwarenessContext_t)(DPI_AWARENESS_CONTEXT);
166-
typedef BOOL (WINAPI *SetProcessDpiAwarenessContext_t)(DPI_AWARENESS_CONTEXT);
167-
168163
HMODULE user32 = LoadLibrary("user32.dll");
169-
IsValidDpiAwarenessContext_t IsValidDpiAwarenessContextPtr =
170-
(IsValidDpiAwarenessContext_t)GetProcAddress(
171-
user32, "IsValidDpiAwarenessContext");
172-
SetProcessDpiAwarenessContext_t SetProcessDpiAwarenessContextPtr =
173-
(SetProcessDpiAwarenessContext_t)GetProcAddress(
174-
user32, "SetProcessDpiAwarenessContext");
164+
auto IsValidDpiAwarenessContext = (BOOL (WINAPI *)(DPI_AWARENESS_CONTEXT))
165+
GetProcAddress(user32, "IsValidDpiAwarenessContext");
166+
auto SetProcessDpiAwarenessContext = (BOOL (WINAPI *)(DPI_AWARENESS_CONTEXT))
167+
GetProcAddress(user32, "SetProcessDpiAwarenessContext");
175168
DPI_AWARENESS_CONTEXT ctxs[3] = {
176169
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, // Win10 Creators Update
177170
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE, // Win10
178171
DPI_AWARENESS_CONTEXT_SYSTEM_AWARE}; // Win10
179-
if (IsValidDpiAwarenessContextPtr != NULL
180-
&& SetProcessDpiAwarenessContextPtr != NULL) {
172+
if (IsValidDpiAwarenessContext && SetProcessDpiAwarenessContext) {
181173
for (size_t i = 0; i < sizeof(ctxs) / sizeof(DPI_AWARENESS_CONTEXT); ++i) {
182-
if (IsValidDpiAwarenessContextPtr(ctxs[i])) {
183-
SetProcessDpiAwarenessContextPtr(ctxs[i]);
174+
if (IsValidDpiAwarenessContext(ctxs[i])) {
175+
SetProcessDpiAwarenessContext(ctxs[i]);
184176
break;
185177
}
186178
}

0 commit comments

Comments
 (0)