| 1 |
/* |
| 2 |
attrs.h - wrapper macros for the gcc __attribute__(()) directive |
| 3 |
|
| 4 |
Copyright (C) 2007, 2008, 2012 Arthur de Jong |
| 5 |
|
| 6 |
This library is free software; you can redistribute it and/or |
| 7 |
modify it under the terms of the GNU Lesser General Public |
| 8 |
License as published by the Free Software Foundation; either |
| 9 |
version 2.1 of the License, or (at your option) any later version. |
| 10 |
|
| 11 |
This library is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
Lesser General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU Lesser General Public |
| 17 |
License along with this library; if not, write to the Free Software |
| 18 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 19 |
02110-1301 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef COMPAT__ATTRS_H |
| 23 |
#define COMPAT__ATTRS_H 1 |
| 24 |
|
| 25 |
/* macro for testing the version of GCC */ |
| 26 |
#define GCC_VERSION(major, minor) \ |
| 27 |
((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
| 28 |
|
| 29 |
/* These are macros to use some gcc-specific flags in case they're available |
| 30 |
and otherwise define them to empty strings. This allows us to give |
| 31 |
the compiler some extra information. |
| 32 |
See http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html |
| 33 |
for a list of attributes supported by gcc */ |
| 34 |
|
| 35 |
/* this is used to flag function parameters that are not used in the function |
| 36 |
body. */ |
| 37 |
#if GCC_VERSION(3, 0) |
| 38 |
#define UNUSED(x) x __attribute__((__unused__)) |
| 39 |
#else |
| 40 |
#define UNUSED(x) x |
| 41 |
#endif |
| 42 |
|
| 43 |
/* this is used to add extra format checking to the function calls as if this |
| 44 |
was a printf()-like function */ |
| 45 |
#if GCC_VERSION(3, 0) |
| 46 |
#define LIKE_PRINTF(format_idx, arg_idx) \ |
| 47 |
__attribute__((__format__(__printf__, format_idx, arg_idx))) |
| 48 |
#else |
| 49 |
#define LIKE_PRINTF(format_idx, arg_idx) /* no attribute */ |
| 50 |
#endif |
| 51 |
|
| 52 |
/* indicates that the function is "pure": its result is purely based on |
| 53 |
the parameters and has no side effects or used static data */ |
| 54 |
#if GCC_VERSION(3, 0) |
| 55 |
#define PURE __attribute__((__pure__)) |
| 56 |
#else |
| 57 |
#define PURE /* no attribute */ |
| 58 |
#endif |
| 59 |
|
| 60 |
/* the function returns a new data structure that has been freshly |
| 61 |
allocated */ |
| 62 |
#if GCC_VERSION(3, 0) |
| 63 |
#define LIKE_MALLOC __attribute__((__malloc__)) |
| 64 |
#else |
| 65 |
#define LIKE_MALLOC /* no attribute */ |
| 66 |
#endif |
| 67 |
|
| 68 |
/* the function's return value should be used by the caller */ |
| 69 |
#if GCC_VERSION(3, 4) |
| 70 |
#define MUST_USE __attribute__((__warn_unused_result__)) |
| 71 |
#else |
| 72 |
#define MUST_USE /* no attribute */ |
| 73 |
#endif |
| 74 |
|
| 75 |
/* the function's return value should be used by the caller */ |
| 76 |
#if GCC_VERSION(2, 5) |
| 77 |
#define NORETURN __attribute__((__noreturn__)) |
| 78 |
#else |
| 79 |
#define NORETURN /* no attribute */ |
| 80 |
#endif |
| 81 |
|
| 82 |
/* define __STRING if it's not yet defined */ |
| 83 |
#ifndef __STRING |
| 84 |
#ifdef __STDC__ |
| 85 |
#define __STRING(x) #x |
| 86 |
#else /* __STDC__ */ |
| 87 |
#define __STRING(x) "x" |
| 88 |
#endif /* not __STDC__ */ |
| 89 |
#endif /* not __STRING */ |
| 90 |
|
| 91 |
#endif /* not COMPAT__ATTRS_H */ |