]>
Commit | Line | Data |
---|---|---|
8fe5ef5a SA |
1 | /* |
2 | * Helpful macros for TAP header files. | |
3 | * | |
4 | * This is not, strictly speaking, related to TAP, but any TAP add-on is | |
5 | * probably going to need these macros, so define them in one place so that | |
6 | * everyone can pull them in. | |
7 | * | |
8 | * This file is part of C TAP Harness. The current version plus supporting | |
9 | * documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>. | |
10 | * | |
11 | * Copyright 2008, 2012, 2013, 2015 Russ Allbery <eagle@eyrie.org> | |
12 | * | |
13 | * Permission is hereby granted, free of charge, to any person obtaining a | |
14 | * copy of this software and associated documentation files (the "Software"), | |
15 | * to deal in the Software without restriction, including without limitation | |
16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
17 | * and/or sell copies of the Software, and to permit persons to whom the | |
18 | * Software is furnished to do so, subject to the following conditions: | |
19 | * | |
20 | * The above copyright notice and this permission notice shall be included in | |
21 | * all copies or substantial portions of the Software. | |
22 | * | |
23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
26 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
28 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
29 | * DEALINGS IN THE SOFTWARE. | |
30 | */ | |
31 | ||
32 | #ifndef TAP_MACROS_H | |
33 | #define TAP_MACROS_H 1 | |
34 | ||
35 | /* | |
36 | * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7 | |
37 | * could you use the __format__ form of the attributes, which is what we use | |
38 | * (to avoid confusion with other macros), and only with gcc 2.96 can you use | |
39 | * the attribute __malloc__. 2.96 is very old, so don't bother trying to get | |
40 | * the other attributes to work with GCC versions between 2.7 and 2.96. | |
41 | */ | |
42 | #ifndef __attribute__ | |
43 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) | |
44 | # define __attribute__(spec) /* empty */ | |
45 | # endif | |
46 | #endif | |
47 | ||
48 | /* | |
49 | * We use __alloc_size__, but it was only available in fairly recent versions | |
50 | * of GCC. Suppress warnings about the unknown attribute if GCC is too old. | |
51 | * We know that we're GCC at this point, so we can use the GCC variadic macro | |
52 | * extension, which will still work with versions of GCC too old to have C99 | |
53 | * variadic macro support. | |
54 | */ | |
55 | #if !defined(__attribute__) && !defined(__alloc_size__) | |
56 | # if defined(__GNUC__) && !defined(__clang__) | |
57 | # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) | |
58 | # define __alloc_size__(spec, args...) /* empty */ | |
59 | # endif | |
60 | # endif | |
61 | #endif | |
62 | ||
63 | /* Suppress __warn_unused_result__ if gcc is too old. */ | |
64 | #if !defined(__attribute__) && !defined(__warn_unused_result__) | |
65 | # if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4) | |
66 | # define __warn_unused_result__ /* empty */ | |
67 | # endif | |
68 | #endif | |
69 | ||
70 | /* | |
71 | * LLVM and Clang pretend to be GCC but don't support all of the __attribute__ | |
72 | * settings that GCC does. For them, suppress warnings about unknown | |
73 | * attributes on declarations. This unfortunately will affect the entire | |
74 | * compilation context, but there's no push and pop available. | |
75 | */ | |
76 | #if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__)) | |
77 | # pragma GCC diagnostic ignored "-Wattributes" | |
78 | #endif | |
79 | ||
80 | /* Used for unused parameters to silence gcc warnings. */ | |
81 | #define UNUSED __attribute__((__unused__)) | |
82 | ||
83 | /* | |
84 | * BEGIN_DECLS is used at the beginning of declarations so that C++ | |
85 | * compilers don't mangle their names. END_DECLS is used at the end. | |
86 | */ | |
87 | #undef BEGIN_DECLS | |
88 | #undef END_DECLS | |
89 | #ifdef __cplusplus | |
90 | # define BEGIN_DECLS extern "C" { | |
91 | # define END_DECLS } | |
92 | #else | |
93 | # define BEGIN_DECLS /* empty */ | |
94 | # define END_DECLS /* empty */ | |
95 | #endif | |
96 | ||
97 | #endif /* TAP_MACROS_H */ |