attributes.h 4.4 KB

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