Blender V5.3
wayland_dynload_client.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <stdlib.h> /* `atexit`. */
12#include <string.h>
13
14#include "wayland_dynload_API.h"
16
17#include "wayland_dynload_client.h" /* Own include. */
18
19/* Public handle. */
21
22static DynamicLibrary lib = NULL;
23
24#define WAYLAND_DYNLOAD_IFACE(symbol) \
25 extern struct wl_interface symbol; \
26 struct wl_interface symbol;
28#undef WAYLAND_DYNLOAD_IFACE
29
30bool wayland_dynload_client_init(const bool verbose)
31{
32 /* NOTE: returning false must call exit to prevent leaking `lib`
33 * once it has been opened. */
34
35 /* Library paths. */
36 const char *paths[] = {
37 "libwayland-client.so.0",
38 "libwayland-client.so",
39 };
40 const int paths_num = sizeof(paths) / sizeof(*paths);
41 int path_found;
42 if (!(lib = dynamic_library_open_array_with_error(paths, paths_num, verbose, &path_found))) {
43 return false;
44 }
45 if (atexit(wayland_dynload_client_exit)) {
47 return false;
48 }
49
50#define WAYLAND_DYNLOAD_IFACE(symbol) \
51 { \
52 const void *symbol_val; \
53 if (!(symbol_val = dynamic_library_find_with_error( \
54 lib, #symbol, paths[path_found], verbose))) \
55 { \
56 wayland_dynload_client_exit(); \
57 return false; \
58 } \
59 memcpy(&symbol, symbol_val, sizeof(symbol)); \
60 }
62#undef WAYLAND_DYNLOAD_IFACE
63
64#define WAYLAND_DYNLOAD_FN(symbol) \
65 if (!(wayland_dynload_client.symbol = dynamic_library_find_with_error( \
66 lib, #symbol, paths[path_found], verbose))) \
67 { \
68 wayland_dynload_client_exit(); \
69 return false; \
70 }
72#undef WAYLAND_DYNLOAD_FN
73
74 return true;
75}
76
78{
79 if (lib != NULL) {
80 dynamic_library_close(lib); /* Ignore errors. */
81 lib = NULL;
82 }
83}
84
85/* Validate local signatures against the original header. */
86#pragma GCC diagnostic push
87#pragma GCC diagnostic ignored "-Wredundant-decls"
88#define WAYLAND_DYNLOAD_VALIDATE
90#pragma GCC diagnostic pop
static DynamicLibrary lib
DynamicLibrary dynamic_library_open_array_with_error(const char **paths, const int paths_num, const bool verbose, int *r_path_index)
#define dynamic_library_close(lib)
void * DynamicLibrary
void wayland_dynload_client_exit(void)
bool wayland_dynload_client_init(bool verbose)
struct WaylandDynload_Client wayland_dynload_client