attributes.h 4.1 KB

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