Anthony Liguori | d63c947 | 2013-03-25 10:23:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * GLIB Compatibility Functions |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2013 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Anthony Liguori <aliguori@us.ibm.com> |
Michael Tokarev | 86946a2 | 2014-05-08 12:30:46 +0400 | [diff] [blame] | 8 | * Michael Tokarev <mjt@tls.msk.ru> |
| 9 | * Paolo Bonzini <pbonzini@redhat.com> |
Anthony Liguori | d63c947 | 2013-03-25 10:23:56 -0500 | [diff] [blame] | 10 | * |
| 11 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 12 | * See the COPYING file in the top-level directory. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #ifndef QEMU_GLIB_COMPAT_H |
| 17 | #define QEMU_GLIB_COMPAT_H |
| 18 | |
Daniel P. Berrangé | e71e8cc | 2018-05-04 16:25:00 +0100 | [diff] [blame] | 19 | /* Ask for warnings for anything that was marked deprecated in |
| 20 | * the defined version, or before. It is a candidate for rewrite. |
| 21 | */ |
Daniel P. Berrangé | 00f2cfb | 2018-05-04 15:34:46 +0100 | [diff] [blame] | 22 | #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_48 |
Daniel P. Berrangé | e71e8cc | 2018-05-04 16:25:00 +0100 | [diff] [blame] | 23 | |
| 24 | /* Ask for warnings if code tries to use function that did not |
| 25 | * exist in the defined version. These risk breaking builds |
| 26 | */ |
Daniel P. Berrangé | 00f2cfb | 2018-05-04 15:34:46 +0100 | [diff] [blame] | 27 | #define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_48 |
Daniel P. Berrangé | e71e8cc | 2018-05-04 16:25:00 +0100 | [diff] [blame] | 28 | |
| 29 | #pragma GCC diagnostic push |
| 30 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 31 | |
Anthony Liguori | d63c947 | 2013-03-25 10:23:56 -0500 | [diff] [blame] | 32 | #include <glib.h> |
| 33 | |
Daniel P. Berrangé | e71e8cc | 2018-05-04 16:25:00 +0100 | [diff] [blame] | 34 | /* |
| 35 | * Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allowing |
| 36 | * use of functions from newer GLib via this compat header needs a little |
| 37 | * trickery to prevent warnings being emitted. |
| 38 | * |
| 39 | * Consider a function from newer glib-X.Y that we want to use |
| 40 | * |
| 41 | * int g_foo(const char *wibble) |
| 42 | * |
| 43 | * We must define a static inline function with the same signature that does |
| 44 | * what we need, but with a "_qemu" suffix e.g. |
| 45 | * |
| 46 | * static inline void g_foo_qemu(const char *wibble) |
| 47 | * { |
| 48 | * #if GLIB_CHECK_VERSION(X, Y, 0) |
| 49 | * g_foo(wibble) |
| 50 | * #else |
| 51 | * g_something_equivalent_in_older_glib(wibble); |
| 52 | * #endif |
| 53 | * } |
| 54 | * |
| 55 | * The #pragma at the top of this file turns off -Wdeprecated-declarations, |
| 56 | * ensuring this wrapper function impl doesn't trigger the compiler warning |
| 57 | * about using too new glib APIs. Finally we can do |
| 58 | * |
| 59 | * #define g_foo(a) g_foo_qemu(a) |
| 60 | * |
| 61 | * So now the code elsewhere in QEMU, which *does* have the |
| 62 | * -Wdeprecated-declarations warning active, can call g_foo(...) as normal, |
| 63 | * without generating warnings. |
| 64 | */ |
| 65 | |
Marc-André Lureau | 1706e9d | 2017-01-03 20:19:33 +0100 | [diff] [blame] | 66 | #if defined(_WIN32) && !GLIB_CHECK_VERSION(2, 50, 0) |
Sangho Park | 5a00754 | 2014-05-08 12:47:10 +0400 | [diff] [blame] | 67 | /* |
| 68 | * g_poll has a problem on Windows when using |
| 69 | * timeouts < 10ms, so use wrapper. |
| 70 | */ |
| 71 | #define g_poll(fds, nfds, timeout) g_poll_fixed(fds, nfds, timeout) |
| 72 | gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout); |
Stefan Hajnoczi | f95c967 | 2014-05-02 18:35:56 +0400 | [diff] [blame] | 73 | #endif |
| 74 | |
Daniel P. Berrangé | e71e8cc | 2018-05-04 16:25:00 +0100 | [diff] [blame] | 75 | #pragma GCC diagnostic pop |
| 76 | |
Anthony Liguori | d63c947 | 2013-03-25 10:23:56 -0500 | [diff] [blame] | 77 | #endif |