gccmacro.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef foopulsegccmacrohfoo
  2. #define foopulsegccmacrohfoo
  3. /***
  4. This file is part of PulseAudio.
  5. Copyright 2004-2006 Lennart Poettering
  6. PulseAudio is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation; either version 2.1 of the License,
  9. or (at your option) any later version.
  10. PulseAudio is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
  16. ***/
  17. /** \file
  18. * GCC attribute macros */
  19. #if defined(__GNUC__)
  20. #ifdef __MINGW32__
  21. /* libintl overrides printf with a #define. As this breaks this attribute,
  22. * it has a workaround. However the workaround isn't enabled for MINGW
  23. * builds (only cygwin) */
  24. #define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (__printf__, a, b)))
  25. #else
  26. #define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b)))
  27. #endif
  28. #else
  29. /** If we're in GNU C, use some magic for detecting invalid format strings */
  30. #define PA_GCC_PRINTF_ATTR(a,b)
  31. #endif
  32. #if defined(__GNUC__) && (__GNUC__ >= 4)
  33. #define PA_GCC_SENTINEL __attribute__ ((sentinel))
  34. #else
  35. /** Macro for usage of GCC's sentinel compilation warnings */
  36. #define PA_GCC_SENTINEL
  37. #endif
  38. #ifdef __GNUC__
  39. #define PA_GCC_NORETURN __attribute__((noreturn))
  40. #else
  41. /** Macro for no-return functions */
  42. #define PA_GCC_NORETURN
  43. #endif
  44. #ifdef __GNUC__
  45. #define PA_GCC_UNUSED __attribute__ ((unused))
  46. #else
  47. /** Macro for not used function, variable or parameter */
  48. #define PA_GCC_UNUSED
  49. #endif
  50. #ifdef __GNUC__
  51. #define PA_GCC_DESTRUCTOR __attribute__ ((destructor))
  52. #else
  53. /** Call this function when process terminates */
  54. #define PA_GCC_DESTRUCTOR
  55. #endif
  56. #ifndef PA_GCC_PURE
  57. #ifdef __GNUC__
  58. #define PA_GCC_PURE __attribute__ ((pure))
  59. #else
  60. /** This function's return value depends only the arguments list and global state **/
  61. #define PA_GCC_PURE
  62. #endif
  63. #endif
  64. #ifndef PA_GCC_CONST
  65. #ifdef __GNUC__
  66. #define PA_GCC_CONST __attribute__ ((const))
  67. #else
  68. /** This function's return value depends only the arguments list (stricter version of PA_GCC_PURE) **/
  69. #define PA_GCC_CONST
  70. #endif
  71. #endif
  72. #ifndef PA_GCC_DEPRECATED
  73. #ifdef __GNUC__
  74. #define PA_GCC_DEPRECATED __attribute__ ((deprecated))
  75. #else
  76. /** This function is deprecated **/
  77. #define PA_GCC_DEPRECATED
  78. #endif
  79. #endif
  80. #ifndef PA_GCC_PACKED
  81. #ifdef __GNUC__
  82. #define PA_GCC_PACKED __attribute__ ((packed))
  83. #else
  84. /** Structure shall be packed in memory **/
  85. #define PA_GCC_PACKED
  86. #endif
  87. #endif
  88. #ifndef PA_GCC_ALLOC_SIZE
  89. #if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3)
  90. #define PA_GCC_ALLOC_SIZE(x) __attribute__ ((__alloc_size__(x)))
  91. #define PA_GCC_ALLOC_SIZE2(x,y) __attribute__ ((__alloc_size__(x,y)))
  92. #else
  93. /** Macro for usage of GCC's alloc_size attribute */
  94. #define PA_GCC_ALLOC_SIZE(x)
  95. /** Macro for usage of GCC's alloc_size attribute */
  96. #define PA_GCC_ALLOC_SIZE2(x,y)
  97. #endif
  98. #endif
  99. #ifndef PA_GCC_MALLOC
  100. #ifdef __GNUC__
  101. #define PA_GCC_MALLOC __attribute__ ((malloc))
  102. #else
  103. /** Macro for usage of GCC's malloc attribute */
  104. #define PA_GCC_MALLOC
  105. #endif
  106. #endif
  107. #ifndef PA_GCC_WEAKREF
  108. #if defined(__GNUC__) && defined(__ELF__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ > 1)) || (__GNUC__ > 4))
  109. /** Macro for usage of GCC's weakref attribute */
  110. #define PA_GCC_WEAKREF(x) __attribute__((weakref(#x)))
  111. #endif
  112. #endif
  113. #endif