dbus-macros.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. defined(__clang__)
  62. #define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) \
  63. __attribute__((__format__ (__printf__, format_idx, arg_idx)))
  64. #define _DBUS_GNUC_NORETURN \
  65. __attribute__((__noreturn__))
  66. #define _DBUS_GNUC_UNUSED \
  67. __attribute__((__unused__))
  68. #else /* !__GNUC__ */
  69. #define _DBUS_GNUC_PRINTF( format_idx, arg_idx )
  70. #define _DBUS_GNUC_NORETURN
  71. #define _DBUS_GNUC_UNUSED
  72. #endif /* !__GNUC__ */
  73. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
  74. #define DBUS_MALLOC __attribute__((__malloc__))
  75. #else
  76. #define DBUS_MALLOC
  77. #endif
  78. #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
  79. #define DBUS_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
  80. #define DBUS_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
  81. #else
  82. #define DBUS_ALLOC_SIZE(x)
  83. #define DBUS_ALLOC_SIZE2(x,y)
  84. #endif
  85. #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
  86. #define _DBUS_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  87. #else
  88. #define _DBUS_GNUC_WARN_UNUSED_RESULT
  89. #endif
  90. /** @def _DBUS_GNUC_PRINTF
  91. * used to tell gcc about printf format strings
  92. */
  93. /** @def _DBUS_GNUC_NORETURN
  94. * used to tell gcc about functions that never return, such as _dbus_abort()
  95. */
  96. /** @def _DBUS_GNUC_WARN_UNUSED_RESULT
  97. * used to tell gcc about functions whose result must be used
  98. */
  99. /* Normally docs are in .c files, but there isn't a .c file for this. */
  100. /**
  101. * @defgroup DBusMacros Utility macros
  102. * @ingroup DBus
  103. * @brief #TRUE, #FALSE, #NULL, and so on
  104. *
  105. * Utility macros.
  106. *
  107. * @{
  108. */
  109. /**
  110. * @def DBUS_BEGIN_DECLS
  111. *
  112. * Macro used prior to declaring functions in the D-Bus header
  113. * files. Expands to "extern "C"" when using a C++ compiler,
  114. * and expands to nothing when using a C compiler.
  115. *
  116. * Please don't use this in your own code, consider it
  117. * D-Bus internal.
  118. */
  119. /**
  120. * @def DBUS_END_DECLS
  121. *
  122. * Macro used after declaring functions in the D-Bus header
  123. * files. Expands to "}" when using a C++ compiler,
  124. * and expands to nothing when using a C compiler.
  125. *
  126. * Please don't use this in your own code, consider it
  127. * D-Bus internal.
  128. */
  129. /**
  130. * @def TRUE
  131. *
  132. * Expands to "1"
  133. */
  134. /**
  135. * @def FALSE
  136. *
  137. * Expands to "0"
  138. */
  139. /**
  140. * @def NULL
  141. *
  142. * A null pointer, defined appropriately for C or C++.
  143. */
  144. /**
  145. * @def DBUS_DEPRECATED
  146. *
  147. * Tells the compiler to warn about a function or type if it's used.
  148. * Code marked in this way should also be enclosed in
  149. * @code
  150. * #ifndef DBUS_DISABLE_DEPRECATED
  151. * deprecated stuff here
  152. * #endif
  153. * @endcode
  154. *
  155. * Please don't use this in your own code, consider it
  156. * D-Bus internal.
  157. */
  158. /**
  159. * @def _DBUS_GNUC_EXTENSION
  160. *
  161. * Tells gcc not to warn about extensions to the C standard in the
  162. * following expression, even if compiling with -pedantic. Do not use
  163. * this macro in your own code; please consider it to be internal to libdbus.
  164. */
  165. /*
  166. * @def DBUS_EXPORT
  167. *
  168. * Declare the following symbol as public. This is currently a noop on
  169. * platforms other than Windows.
  170. */
  171. #if defined(DBUS_EXPORT)
  172. /* value forced by compiler command line, don't redefine */
  173. #elif defined(_WIN32)
  174. # if defined(DBUS_STATIC_BUILD)
  175. # define DBUS_EXPORT
  176. # elif defined(dbus_1_EXPORTS)
  177. # define DBUS_EXPORT __declspec(dllexport)
  178. # else
  179. # define DBUS_EXPORT __declspec(dllimport)
  180. # endif
  181. #elif defined(__GNUC__) && __GNUC__ >= 4
  182. # define DBUS_EXPORT __attribute__ ((__visibility__ ("default")))
  183. #else
  184. #define DBUS_EXPORT
  185. #endif
  186. #if defined(DBUS_PRIVATE_EXPORT)
  187. /* value forced by compiler command line, don't redefine */
  188. #elif defined(_WIN32)
  189. # if defined(DBUS_STATIC_BUILD)
  190. # define DBUS_PRIVATE_EXPORT /* no decoration */
  191. # elif defined(dbus_1_EXPORTS)
  192. # define DBUS_PRIVATE_EXPORT __declspec(dllexport)
  193. # else
  194. # define DBUS_PRIVATE_EXPORT __declspec(dllimport)
  195. # endif
  196. #elif defined(__GNUC__) && __GNUC__ >= 4
  197. # define DBUS_PRIVATE_EXPORT __attribute__ ((__visibility__ ("default")))
  198. #else
  199. # define DBUS_PRIVATE_EXPORT /* no decoration */
  200. #endif
  201. /* Implementation for dbus_clear_message() etc. This is not API,
  202. * do not use it directly.
  203. *
  204. * We're using a specific type (T ** and T *) instead of void ** and
  205. * void * partly for type-safety, partly to be strict-aliasing-compliant,
  206. * and partly to keep C++ compilers happy. This code is inlined into
  207. * users of libdbus, so we can't rely on it having dbus' own compiler
  208. * settings. */
  209. #define _dbus_clear_pointer_impl(T, pointer_to_pointer, destroy) \
  210. do { \
  211. T **_pp = (pointer_to_pointer); \
  212. T *_value = *_pp; \
  213. \
  214. *_pp = NULL; \
  215. \
  216. if (_value != NULL) \
  217. destroy (_value); \
  218. } while (0)
  219. /* Not (destroy) (_value) in case destroy() is a function-like macro */
  220. /** @} */
  221. #endif /* DBUS_MACROS_H */