gitlab-ci: enable sanitizers for the meson builds
[mesa-waffle.git] / src / waffle / x11 / x11_wrappers.h
blob2012b28efd941ffb9801c389410724f95d535172
1 // SPDX-FileCopyrightText: Copyright 2013 Intel Corporation
2 // SPDX-License-Identifier: BSD-2-Clause
4 /// @file
5 /// @brief Wrappers for Xlib functions
6 ///
7 /// Each wrapper catches any Xlib error emitted by the wrapped function. The
8 /// wrapper's signature matches the wrapped.
9 ///
10 /// All Xlib error generated by Waffle must be caught by Waffle. Otherwise, the
11 /// Xlib error handler installed by the user will catch the error and may
12 /// handle it in a way Waffle doesn't like. Or, even worse, the default Xlib
13 /// error handler will catch it, which exits the process.
15 #pragma once
17 #include <X11/Xlib-xcb.h>
19 #define X11_SAVE_ERROR_HANDLER \
20 int (*old_handler)(Display*, XErrorEvent*) = \
21 XSetErrorHandler(x11_dummy_error_handler);
23 #define X11_RESTORE_ERROR_HANDLER \
24 XSetErrorHandler(old_handler);
26 static inline int
27 x11_dummy_error_handler(Display *dpy, XErrorEvent *err)
29 return 0;
32 static inline Display*
33 wrapped_XOpenDisplay(const char *name)
35 X11_SAVE_ERROR_HANDLER
36 Display *dpy = XOpenDisplay(name);
37 X11_RESTORE_ERROR_HANDLER
38 return dpy;
41 static inline int
42 wrapped_XCloseDisplay(Display *dpy)
44 X11_SAVE_ERROR_HANDLER
45 int error = XCloseDisplay(dpy);
46 X11_RESTORE_ERROR_HANDLER
47 return error;
50 static inline xcb_connection_t*
51 wrapped_XGetXCBConnection(Display *dpy)
53 X11_SAVE_ERROR_HANDLER
54 xcb_connection_t *conn = XGetXCBConnection(dpy);
55 X11_RESTORE_ERROR_HANDLER
56 return conn;