dbus-macros.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
  2. /* dbus-macros.h generic macros
  3. *
  4. * Copyright (C) 2002 Red Hat Inc.
  5. *
  6. * Licensed under the Academic Free License version 2.1
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
  24. #error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
  25. #endif
  26. #ifndef DBUS_MACROS_H
  27. #define DBUS_MACROS_H
  28. #ifdef __cplusplus
  29. # define DBUS_BEGIN_DECLS extern "C" {
  30. # define DBUS_END_DECLS }
  31. #else
  32. # define DBUS_BEGIN_DECLS
  33. # define DBUS_END_DECLS
  34. #endif
  35. #ifndef TRUE
  36. # define TRUE 1
  37. #endif
  38. #ifndef FALSE
  39. # define FALSE 0
  40. #endif
  41. #ifndef NULL
  42. # ifdef __cplusplus
  43. # define NULL (0L)
  44. # else /* !__cplusplus */
  45. # define NULL ((void*) 0)
  46. # endif /* !__cplusplus */
  47. #endif
  48. #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
  49. # define DBUS_DEPRECATED __attribute__ ((__deprecated__))
  50. #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
  51. # define DBUS_DEPRECATED __declspec(deprecated)
  52. #else
  53. # define DBUS_DEPRECATED
  54. #endif
  55. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
  56. # define _DBUS_GNUC_EXTENSION __extension__
  57. #else
  58. # define _DBUS_GNUC_EXTENSION
  59. #endif
  60. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
  61. #define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) \
  62. __attribute__((__format__ (__printf__, format_idx, arg_idx)))
  63. #define _DBUS_GNUC_NORETURN \
  64. __attribute__((__noreturn__))
  65. #define _DBUS_GNUC_UNUSED \
  66. __attribute__((__unused__))
  67. #else /* !__GNUC__ */
  68. #define _DBUS_GNUC_PRINTF( format_idx, arg_idx )
  69. #define _DBUS_GNUC_NORETURN
  70. #define _DBUS_GNUC_UNUSED
  71. #endif /* !__GNUC__ */
  72. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
  73. #define DBUS_MALLOC __attribute__((__malloc__))
  74. #else
  75. #define DBUS_MALLOC
  76. #endif
  77. #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
  78. #define DBUS_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
  79. #define DBUS_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
  80. #else
  81. #define DBUS_ALLOC_SIZE(x)
  82. #define DBUS_ALLOC_SIZE2(x,y)
  83. #endif
  84. #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
  85. #define _DBUS_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  86. #else
  87. #define _DBUS_GNUC_WARN_UNUSED_RESULT
  88. #endif
  89. /** @def _DBUS_GNUC_PRINTF
  90. * used to tell gcc about printf format strings
  91. */
  92. /** @def _DBUS_GNUC_NORETURN
  93. * used to tell gcc about functions that never return, such as _dbus_abort()
  94. */
  95. /** @def _DBUS_GNUC_WARN_UNUSED_RESULT
  96. * used to tell gcc about functions whose result must be used
  97. */
  98. /* Normally docs are in .c files, but there isn't a .c file for this. */
  99. /**
  100. * @defgroup DBusMacros Utility macros
  101. * @ingroup DBus
  102. * @brief #TRUE, #FALSE, #NULL, and so on
  103. *
  104. * Utility macros.
  105. *
  106. * @{
  107. */
  108. /**
  109. * @def DBUS_BEGIN_DECLS
  110. *
  111. * Macro used prior to declaring functions in the D-Bus header
  112. * files. Expands to "extern "C"" when using a C++ compiler,
  113. * and expands to nothing when using a C compiler.
  114. *
  115. * Please don't use this in your own code, consider it
  116. * D-Bus internal.
  117. */
  118. /**
  119. * @def DBUS_END_DECLS
  120. *
  121. * Macro used after declaring functions in the D-Bus header
  122. * files. Expands to "}" when using a C++ compiler,
  123. * and expands to nothing when using a C compiler.
  124. *
  125. * Please don't use this in your own code, consider it
  126. * D-Bus internal.
  127. */
  128. /**
  129. * @def TRUE
  130. *
  131. * Expands to "1"
  132. */
  133. /**
  134. * @def FALSE
  135. *
  136. * Expands to "0"
  137. */
  138. /**
  139. * @def NULL
  140. *
  141. * A null pointer, defined appropriately for C or C++.
  142. */
  143. /**
  144. * @def DBUS_DEPRECATED
  145. *
  146. * Tells the compiler to warn about a function or type if it's used.
  147. * Code marked in this way should also be enclosed in
  148. * @code
  149. * #ifndef DBUS_DISABLE_DEPRECATED
  150. * deprecated stuff here
  151. * #endif
  152. * @endcode
  153. *
  154. * Please don't use this in your own code, consider it
  155. * D-Bus internal.
  156. */
  157. /**
  158. * @def _DBUS_GNUC_EXTENSION
  159. *
  160. * Tells gcc not to warn about extensions to the C standard in the
  161. * following expression, even if compiling with -pedantic. Do not use
  162. * this macro in your own code; please consider it to be internal to libdbus.
  163. */
  164. /*
  165. * @def DBUS_EXPORT
  166. *
  167. * Declare the following symbol as public. This is currently a noop on
  168. * platforms other than Windows.
  169. */
  170. #if defined(DBUS_EXPORT)
  171. /* value forced by compiler command line, don't redefine */
  172. #elif defined(_WIN32)
  173. # if defined(DBUS_STATIC_BUILD)
  174. # define DBUS_EXPORT
  175. # elif defined(dbus_1_EXPORTS)
  176. # define DBUS_EXPORT __declspec(dllexport)
  177. # else
  178. # define DBUS_EXPORT __declspec(dllimport)
  179. # endif
  180. #elif defined(__GNUC__) && __GNUC__ >= 4
  181. # define DBUS_EXPORT __attribute__ ((__visibility__ ("default")))
  182. #else
  183. #define DBUS_EXPORT
  184. #endif
  185. #if defined(DBUS_PRIVATE_EXPORT)
  186. /* value forced by compiler command line, don't redefine */
  187. #elif defined(_WIN32)
  188. # if defined(DBUS_STATIC_BUILD)
  189. # define DBUS_PRIVATE_EXPORT /* no decoration */
  190. # elif defined(dbus_1_EXPORTS)
  191. # define DBUS_PRIVATE_EXPORT __declspec(dllexport)
  192. # else
  193. # define DBUS_PRIVATE_EXPORT __declspec(dllimport)
  194. # endif
  195. #elif defined(__GNUC__) && __GNUC__ >= 4
  196. # define DBUS_PRIVATE_EXPORT __attribute__ ((__visibility__ ("default")))
  197. #else
  198. # define DBUS_PRIVATE_EXPORT /* no decoration */
  199. #endif
  200. /** @} */
  201. #endif /* DBUS_MACROS_H */