1 /*
2  * This file is part of brisk-menu.
3  *
4  * Copyright © 2016-2020 Brisk Menu Developers
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11 
12 #pragma once
13 
14 #define _STRINGIFY(x) #x
15 
16 #if defined(__GNUC__)
17 
18 /**
19  * With newer GCC versions, we see compiler warnings simply from including any glib/gtk header.
20  * Many of these make it very hard to debug genuine compiler warnings for the project itself, which
21  * ideally should be completely clear.
22  *
23  * This provides a quick useful macro to wrap around the inclusion of GTK/GLib header files
24  */
25 #define _BRISK_BEGIN_PEDANTIC(COMP)                                                                \
26         _Pragma(_STRINGIFY(COMP diagnostic push))                                                  \
27             _Pragma(_STRINGIFY(COMP diagnostic ignored "-Wpedantic"))
28 
29 /**
30  * End the includes block, i.e. by popping the diagnostic once more
31  */
32 #define _BRISK_END_PEDANTIC(COMP) _Pragma(_STRINGIFY(COMP diagnostic pop))
33 
34 /**
35  * Clang unfortunately also defines __GNUC__ meaning a second level of tests
36  */
37 #if defined(__clang__)
38 
39 /**
40  * Specifically use clang in pragma for older versions of Clang that don't understand
41  * pragma GCC
42  */
43 #define BRISK_BEGIN_PEDANTIC _BRISK_BEGIN_PEDANTIC(clang)
44 #define BRISK_END_PEDANTIC _BRISK_END_PEDANTIC(clang)
45 #else /* __clang__ */
46 
47 /**
48  * Specifically use GCC pragma for GCC
49  */
50 #define BRISK_BEGIN_PEDANTIC _BRISK_BEGIN_PEDANTIC(GCC)
51 #define BRISK_END_PEDANTIC _BRISK_END_PEDANTIC(GCC)
52 #endif
53 
54 #else /* __GNUC__ */
55 /**
56  * Unknown compiler, don't expose the functionality
57  */
58 #define BRISK_BEGIN_PEDANTIC
59 #define BRISK_END_PEDANTIC
60 #endif
61 
62 /* Useful macros */
63 
64 /**
65  * Useful during development to silence compiler warnings
66  */
67 #define __brisk_unused__ __attribute__((unused))
68 
69 /**
70  * All symbols are hidden by default so must be explicitly be made public
71  * to define the ABI
72  */
73 #define __brisk_public__ __attribute__((visibility("default")))
74 
75 /**
76  * Mark the function as a pure function to the compiler
77  */
78 #define __brisk_pure__ __attribute__((pure))
79 
80 /**
81  * Taken out of libnica
82  */
83 #define DEF_AUTOFREE(N, C)                                                                         \
84         static inline void _autofree_func_##N(void *p)                                             \
85         {                                                                                          \
86                 if (p && *(N **)p) {                                                               \
87                         C(*(N **)p);                                                               \
88                         (*(void **)p) = NULL;                                                      \
89                 }                                                                                  \
90         }
91 
92 #define autofree(N) __attribute__((cleanup(_autofree_func_##N))) N
93 
94 /*
95  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
96  *
97  * Local variables:
98  * c-basic-offset: 8
99  * tab-width: 8
100  * indent-tabs-mode: nil
101  * End:
102  *
103  * vi: set shiftwidth=8 tabstop=8 expandtab:
104  * :indentSize=8:tabSize=8:noTabs=true:
105  */
106