]> git.sesse.net Git - ffmpeg/blob - libavutil/attributes.h
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavutil / attributes.h
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * Macro definitions for various function/variable attributes
24  */
25
26 #ifndef AVUTIL_ATTRIBUTES_H
27 #define AVUTIL_ATTRIBUTES_H
28
29 #ifdef __GNUC__
30 #    define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
31 #else
32 #    define AV_GCC_VERSION_AT_LEAST(x,y) 0
33 #endif
34
35 #ifndef av_always_inline
36 #if AV_GCC_VERSION_AT_LEAST(3,1)
37 #    define av_always_inline __attribute__((always_inline)) inline
38 #else
39 #    define av_always_inline inline
40 #endif
41 #endif
42
43 #ifndef av_extern_inline
44 #    define av_extern_inline inline
45 #endif
46
47 #ifndef av_noreturn
48 #if AV_GCC_VERSION_AT_LEAST(2,5)
49 #    define av_noreturn __attribute__((noreturn))
50 #else
51 #    define av_noreturn
52 #endif
53 #endif
54
55 #ifndef av_noinline
56 #if AV_GCC_VERSION_AT_LEAST(3,1)
57 #    define av_noinline __attribute__((noinline))
58 #else
59 #    define av_noinline
60 #endif
61 #endif
62
63 #ifndef av_pure
64 #if AV_GCC_VERSION_AT_LEAST(3,1)
65 #    define av_pure __attribute__((pure))
66 #else
67 #    define av_pure
68 #endif
69 #endif
70
71 #ifndef av_const
72 #if AV_GCC_VERSION_AT_LEAST(2,6)
73 #    define av_const __attribute__((const))
74 #else
75 #    define av_const
76 #endif
77 #endif
78
79 #ifndef av_cold
80 #if AV_GCC_VERSION_AT_LEAST(4,3)
81 #    define av_cold __attribute__((cold))
82 #else
83 #    define av_cold
84 #endif
85 #endif
86
87 #ifndef av_flatten
88 #if AV_GCC_VERSION_AT_LEAST(4,1)
89 #    define av_flatten __attribute__((flatten))
90 #else
91 #    define av_flatten
92 #endif
93 #endif
94
95 #ifndef attribute_deprecated
96 #if AV_GCC_VERSION_AT_LEAST(3,1)
97 #    define attribute_deprecated __attribute__((deprecated))
98 #else
99 #    define attribute_deprecated
100 #endif
101 #endif
102
103 /**
104  * Disable warnings about deprecated features
105  * This is useful for sections of code kept for backward compatibility and
106  * scheduled for removal.
107  */
108 #ifndef AV_NOWARN_DEPRECATED
109 #if AV_GCC_VERSION_AT_LEAST(4,6)
110 #    define AV_NOWARN_DEPRECATED(code) \
111         _Pragma("GCC diagnostic push") \
112         _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
113         code \
114         _Pragma("GCC diagnostic pop")
115 #else
116 #    define AV_NOWARN_DEPRECATED(code) code
117 #endif
118 #endif
119
120
121 #ifndef av_unused
122 #if defined(__GNUC__)
123 #    define av_unused __attribute__((unused))
124 #else
125 #    define av_unused
126 #endif
127 #endif
128
129 /**
130  * Mark a variable as used and prevent the compiler from optimizing it
131  * away.  This is useful for variables accessed only from inline
132  * assembler without the compiler being aware.
133  */
134 #ifndef av_used
135 #if AV_GCC_VERSION_AT_LEAST(3,1)
136 #    define av_used __attribute__((used))
137 #else
138 #    define av_used
139 #endif
140 #endif
141
142 #ifndef av_alias
143 #if AV_GCC_VERSION_AT_LEAST(3,3)
144 #   define av_alias __attribute__((may_alias))
145 #else
146 #   define av_alias
147 #endif
148 #endif
149
150 #ifndef av_uninit
151 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
152 #    define av_uninit(x) x=x
153 #else
154 #    define av_uninit(x) x
155 #endif
156 #endif
157
158 #ifdef __GNUC__
159 #    define av_builtin_constant_p __builtin_constant_p
160 #    define av_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos)))
161 #else
162 #    define av_builtin_constant_p(x) 0
163 #    define av_printf_format(fmtpos, attrpos)
164 #endif
165
166 #endif /* AVUTIL_ATTRIBUTES_H */