]> git.sesse.net Git - ffmpeg/blob - libavutil/attributes.h
Merge commit 'cc320296ab438dfe3178f0e1f775af955fe6c064'
[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 #    define AV_GCC_VERSION_AT_MOST(x,y)  (__GNUC__ < (x) || __GNUC__ == (x) && __GNUC_MINOR__ <= (y))
32 #else
33 #    define AV_GCC_VERSION_AT_LEAST(x,y) 0
34 #    define AV_GCC_VERSION_AT_MOST(x,y)  0
35 #endif
36
37 #ifndef av_always_inline
38 #if AV_GCC_VERSION_AT_LEAST(3,1)
39 #    define av_always_inline __attribute__((always_inline)) inline
40 #elif defined(_MSC_VER)
41 #    define av_always_inline __forceinline
42 #else
43 #    define av_always_inline inline
44 #endif
45 #endif
46
47 #ifndef av_extern_inline
48 #if defined(__ICL) && __ICL >= 1210 || defined(__GNUC_STDC_INLINE__)
49 #    define av_extern_inline extern inline
50 #else
51 #    define av_extern_inline inline
52 #endif
53 #endif
54
55 #if AV_GCC_VERSION_AT_LEAST(3,1)
56 #    define av_noinline __attribute__((noinline))
57 #elif defined(_MSC_VER)
58 #    define av_noinline __declspec(noinline)
59 #else
60 #    define av_noinline
61 #endif
62
63 #if AV_GCC_VERSION_AT_LEAST(3,1)
64 #    define av_pure __attribute__((pure))
65 #else
66 #    define av_pure
67 #endif
68
69 #if AV_GCC_VERSION_AT_LEAST(2,6)
70 #    define av_const __attribute__((const))
71 #else
72 #    define av_const
73 #endif
74
75 #if AV_GCC_VERSION_AT_LEAST(4,3)
76 #    define av_cold __attribute__((cold))
77 #else
78 #    define av_cold
79 #endif
80
81 #if AV_GCC_VERSION_AT_LEAST(4,1) && !defined(__llvm__)
82 #    define av_flatten __attribute__((flatten))
83 #else
84 #    define av_flatten
85 #endif
86
87 #if AV_GCC_VERSION_AT_LEAST(3,1)
88 #    define attribute_deprecated __attribute__((deprecated))
89 #elif defined(_MSC_VER)
90 #    define attribute_deprecated __declspec(deprecated)
91 #else
92 #    define attribute_deprecated
93 #endif
94
95 /**
96  * Disable warnings about deprecated features
97  * This is useful for sections of code kept for backward compatibility and
98  * scheduled for removal.
99  */
100 #ifndef AV_NOWARN_DEPRECATED
101 #if AV_GCC_VERSION_AT_LEAST(4,6)
102 #    define AV_NOWARN_DEPRECATED(code) \
103         _Pragma("GCC diagnostic push") \
104         _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
105         code \
106         _Pragma("GCC diagnostic pop")
107 #elif defined(_MSC_VER)
108 #    define AV_NOWARN_DEPRECATED(code) \
109         __pragma(warning(push)) \
110         __pragma(warning(disable : 4996)) \
111         code; \
112         __pragma(warning(pop))
113 #else
114 #    define AV_NOWARN_DEPRECATED(code) code
115 #endif
116 #endif
117
118
119 #if defined(__GNUC__)
120 #    define av_unused __attribute__((unused))
121 #else
122 #    define av_unused
123 #endif
124
125 /**
126  * Mark a variable as used and prevent the compiler from optimizing it
127  * away.  This is useful for variables accessed only from inline
128  * assembler without the compiler being aware.
129  */
130 #if AV_GCC_VERSION_AT_LEAST(3,1)
131 #    define av_used __attribute__((used))
132 #else
133 #    define av_used
134 #endif
135
136 #if AV_GCC_VERSION_AT_LEAST(3,3)
137 #   define av_alias __attribute__((may_alias))
138 #else
139 #   define av_alias
140 #endif
141
142 #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
143 #    define av_uninit(x) x=x
144 #else
145 #    define av_uninit(x) x
146 #endif
147
148 #ifdef __GNUC__
149 #    define av_builtin_constant_p __builtin_constant_p
150 #    define av_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos)))
151 #else
152 #    define av_builtin_constant_p(x) 0
153 #    define av_printf_format(fmtpos, attrpos)
154 #endif
155
156 #if AV_GCC_VERSION_AT_LEAST(2,5)
157 #    define av_noreturn __attribute__((noreturn))
158 #else
159 #    define av_noreturn
160 #endif
161
162 #endif /* AVUTIL_ATTRIBUTES_H */