gmacros.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. /* GLIB - Library of useful routines for C programming
  2. * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*
  18. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  19. * file for a list of people on the GLib Team. See the ChangeLog
  20. * files for a list of changes. These files are distributed with
  21. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  22. */
  23. /* This file must not include any other glib header file and must thus
  24. * not refer to variables from glibconfig.h
  25. */
  26. #ifndef __G_MACROS_H__
  27. #define __G_MACROS_H__
  28. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  29. #error "Only <glib.h> can be included directly."
  30. #endif
  31. /* We include stddef.h to get the system's definition of NULL
  32. */
  33. #include <stddef.h>
  34. #ifdef __GNUC__
  35. #define G_GNUC_CHECK_VERSION(major, minor) \
  36. ((__GNUC__ > (major)) || \
  37. ((__GNUC__ == (major)) && \
  38. (__GNUC_MINOR__ >= (minor))))
  39. #else
  40. #define G_GNUC_CHECK_VERSION(major, minor) 0
  41. #endif
  42. /* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
  43. * where this is valid. This allows for warningless compilation of
  44. * "long long" types even in the presence of '-ansi -pedantic'.
  45. */
  46. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
  47. #define G_GNUC_EXTENSION __extension__
  48. #else
  49. #define G_GNUC_EXTENSION
  50. #endif
  51. /* Every compiler that we target supports inlining, but some of them may
  52. * complain about it if we don't say "__inline". If we have C99, or if
  53. * we are using C++, then we can use "inline" directly. Unfortunately
  54. * Visual Studio does not support __STDC_VERSION__, so we need to check
  55. * whether we are on Visual Studio 2013 or earlier to see that we need to
  56. * say "__inline" in C mode.
  57. * Otherwise, we say "__inline" to avoid the warning.
  58. */
  59. #define G_CAN_INLINE
  60. #ifndef __cplusplus
  61. # ifdef _MSC_VER
  62. # if (_MSC_VER < 1900)
  63. # define G_INLINE_DEFINE_NEEDED
  64. # endif
  65. # elif !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199900)
  66. # define G_INLINE_DEFINE_NEEDED
  67. # endif
  68. #endif
  69. #ifdef G_INLINE_DEFINE_NEEDED
  70. # undef inline
  71. # define inline __inline
  72. #endif
  73. #undef G_INLINE_DEFINE_NEEDED
  74. /**
  75. * G_INLINE_FUNC:
  76. *
  77. * This macro used to be used to conditionally define inline functions
  78. * in a compatible way before this feature was supported in all
  79. * compilers. These days, GLib requires inlining support from the
  80. * compiler, so your GLib-using programs can safely assume that the
  81. * "inline" keywork works properly.
  82. *
  83. * Never use this macro anymore. Just say "static inline".
  84. *
  85. * Deprecated: 2.48: Use "static inline" instead
  86. */
  87. /* For historical reasons we need to continue to support those who
  88. * define G_IMPLEMENT_INLINES to mean "don't implement this here".
  89. */
  90. #ifdef G_IMPLEMENT_INLINES
  91. # define G_INLINE_FUNC extern GLIB_DEPRECATED_MACRO_IN_2_48_FOR(static inline)
  92. # undef G_CAN_INLINE
  93. #else
  94. # define G_INLINE_FUNC static inline GLIB_DEPRECATED_MACRO_IN_2_48_FOR(static inline)
  95. #endif /* G_IMPLEMENT_INLINES */
  96. /* Provide macros to feature the GCC function attribute.
  97. */
  98. /**
  99. * G_GNUC_PURE:
  100. *
  101. * Expands to the GNU C `pure` function attribute if the compiler is gcc.
  102. * Declaring a function as `pure` enables better optimization of calls to
  103. * the function. A `pure` function has no effects except its return value
  104. * and the return value depends only on the parameters and/or global
  105. * variables.
  106. *
  107. * Place the attribute after the declaration, just before the semicolon.
  108. *
  109. * |[<!-- language="C" -->
  110. * gboolean g_type_check_value (const GValue *value) G_GNUC_PURE;
  111. * ]|
  112. *
  113. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute) for more details.
  114. */
  115. /**
  116. * G_GNUC_MALLOC:
  117. *
  118. * Expands to the
  119. * [GNU C `malloc` function attribute](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-functions-that-behave-like-malloc)
  120. * if the compiler is gcc.
  121. * Declaring a function as `malloc` enables better optimization of the function,
  122. * but must only be done if the allocation behaviour of the function is fully
  123. * understood, otherwise miscompilation can result.
  124. *
  125. * A function can have the `malloc` attribute if it returns a pointer which is
  126. * guaranteed to not alias with any other pointer valid when the function
  127. * returns, and moreover no pointers to valid objects occur in any storage
  128. * addressed by the returned pointer.
  129. *
  130. * In practice, this means that `G_GNUC_MALLOC` can be used with any function
  131. * which returns unallocated or zeroed-out memory, but not with functions which
  132. * return initialised structures containing other pointers, or with functions
  133. * that reallocate memory. This definition changed in GLib 2.58 to match the
  134. * stricter definition introduced around GCC 5.
  135. *
  136. * Place the attribute after the declaration, just before the semicolon.
  137. *
  138. * |[<!-- language="C" -->
  139. * gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
  140. * ]|
  141. *
  142. * See the
  143. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-functions-that-behave-like-malloc)
  144. * for more details.
  145. *
  146. * Since: 2.6
  147. */
  148. /**
  149. * G_GNUC_NO_INLINE:
  150. *
  151. * Expands to the GNU C `noinline` function attribute if the compiler is gcc.
  152. * If the compiler is not gcc, this macro expands to nothing.
  153. *
  154. * Declaring a function as `noinline` prevents the function from being
  155. * considered for inlining.
  156. *
  157. * The attribute may be placed before the declaration or definition,
  158. * right before the `static` keyword.
  159. *
  160. * |[<!-- language="C" -->
  161. * G_GNUC_NO_INLINE
  162. * static int
  163. * do_not_inline_this (void)
  164. * {
  165. * ...
  166. * }
  167. * ]|
  168. *
  169. * See the
  170. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute)
  171. * for more details.
  172. *
  173. * Since: 2.58
  174. */
  175. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
  176. #define G_GNUC_PURE __attribute__((__pure__))
  177. #define G_GNUC_MALLOC __attribute__((__malloc__))
  178. #define G_GNUC_NO_INLINE __attribute__((noinline))
  179. #else
  180. #define G_GNUC_PURE
  181. #define G_GNUC_MALLOC
  182. #define G_GNUC_NO_INLINE
  183. #endif
  184. /**
  185. * G_GNUC_NULL_TERMINATED:
  186. *
  187. * Expands to the GNU C `sentinel` function attribute if the compiler is gcc.
  188. * This function attribute only applies to variadic functions and instructs
  189. * the compiler to check that the argument list is terminated with an
  190. * explicit %NULL.
  191. *
  192. * Place the attribute after the declaration, just before the semicolon.
  193. *
  194. * |[<!-- language="C" -->
  195. * gchar *g_strconcat (const gchar *string1,
  196. * ...) G_GNUC_NULL_TERMINATED;
  197. * ]|
  198. *
  199. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-sentinel-function-attribute) for more details.
  200. *
  201. * Since: 2.8
  202. */
  203. #if __GNUC__ >= 4
  204. #define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
  205. #else
  206. #define G_GNUC_NULL_TERMINATED
  207. #endif
  208. /*
  209. * We can only use __typeof__ on GCC >= 4.8, and not when compiling C++. Since
  210. * __typeof__ is used in a few places in GLib, provide a pre-processor symbol
  211. * to factor the check out from callers.
  212. *
  213. * This symbol is private.
  214. */
  215. #undef g_has_typeof
  216. #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(__cplusplus)
  217. #define g_has_typeof
  218. #endif
  219. /*
  220. * Clang feature detection: http://clang.llvm.org/docs/LanguageExtensions.html
  221. * These are not available on GCC, but since the pre-processor doesn't do
  222. * operator short-circuiting, we can't use it in a statement or we'll get:
  223. *
  224. * error: missing binary operator before token "("
  225. *
  226. * So we define it to 0 to satisfy the pre-processor.
  227. */
  228. #ifdef __has_attribute
  229. #define g_macro__has_attribute __has_attribute
  230. #else
  231. #define g_macro__has_attribute(x) 0
  232. #endif
  233. #ifdef __has_feature
  234. #define g_macro__has_feature __has_feature
  235. #else
  236. #define g_macro__has_feature(x) 0
  237. #endif
  238. #ifdef __has_builtin
  239. #define g_macro__has_builtin __has_builtin
  240. #else
  241. #define g_macro__has_builtin(x) 0
  242. #endif
  243. /**
  244. * G_GNUC_ALLOC_SIZE:
  245. * @x: the index of the argument specifying the allocation size
  246. *
  247. * Expands to the GNU C `alloc_size` function attribute if the compiler
  248. * is a new enough gcc. This attribute tells the compiler that the
  249. * function returns a pointer to memory of a size that is specified
  250. * by the @xth function parameter.
  251. *
  252. * Place the attribute after the function declaration, just before the
  253. * semicolon.
  254. *
  255. * |[<!-- language="C" -->
  256. * gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
  257. * ]|
  258. *
  259. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute) for more details.
  260. *
  261. * Since: 2.18
  262. */
  263. /**
  264. * G_GNUC_ALLOC_SIZE2:
  265. * @x: the index of the argument specifying one factor of the allocation size
  266. * @y: the index of the argument specifying the second factor of the allocation size
  267. *
  268. * Expands to the GNU C `alloc_size` function attribute if the compiler is a
  269. * new enough gcc. This attribute tells the compiler that the function returns
  270. * a pointer to memory of a size that is specified by the product of two
  271. * function parameters.
  272. *
  273. * Place the attribute after the function declaration, just before the
  274. * semicolon.
  275. *
  276. * |[<!-- language="C" -->
  277. * gpointer g_malloc_n (gsize n_blocks,
  278. * gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1, 2);
  279. * ]|
  280. *
  281. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute) for more details.
  282. *
  283. * Since: 2.18
  284. */
  285. #if (!defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \
  286. (defined(__clang__) && g_macro__has_attribute(__alloc_size__))
  287. #define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
  288. #define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
  289. #else
  290. #define G_GNUC_ALLOC_SIZE(x)
  291. #define G_GNUC_ALLOC_SIZE2(x,y)
  292. #endif
  293. /**
  294. * G_GNUC_PRINTF:
  295. * @format_idx: the index of the argument corresponding to the
  296. * format string (the arguments are numbered from 1)
  297. * @arg_idx: the index of the first of the format arguments, or 0 if
  298. * there are no format arguments
  299. *
  300. * Expands to the GNU C `format` function attribute if the compiler is gcc.
  301. * This is used for declaring functions which take a variable number of
  302. * arguments, with the same syntax as `printf()`. It allows the compiler
  303. * to type-check the arguments passed to the function.
  304. *
  305. * Place the attribute after the function declaration, just before the
  306. * semicolon.
  307. *
  308. * See the
  309. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288)
  310. * for more details.
  311. *
  312. * |[<!-- language="C" -->
  313. * gint g_snprintf (gchar *string,
  314. * gulong n,
  315. * gchar const *format,
  316. * ...) G_GNUC_PRINTF (3, 4);
  317. * ]|
  318. */
  319. /**
  320. * G_GNUC_SCANF:
  321. * @format_idx: the index of the argument corresponding to
  322. * the format string (the arguments are numbered from 1)
  323. * @arg_idx: the index of the first of the format arguments, or 0 if
  324. * there are no format arguments
  325. *
  326. * Expands to the GNU C `format` function attribute if the compiler is gcc.
  327. * This is used for declaring functions which take a variable number of
  328. * arguments, with the same syntax as `scanf()`. It allows the compiler
  329. * to type-check the arguments passed to the function.
  330. *
  331. * |[<!-- language="C" -->
  332. * int my_scanf (MyStream *stream,
  333. * const char *format,
  334. * ...) G_GNUC_SCANF (2, 3);
  335. * int my_vscanf (MyStream *stream,
  336. * const char *format,
  337. * va_list ap) G_GNUC_SCANF (2, 0);
  338. * ]|
  339. *
  340. * See the
  341. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288)
  342. * for details.
  343. */
  344. /**
  345. * G_GNUC_STRFTIME:
  346. * @format_idx: the index of the argument corresponding to
  347. * the format string (the arguments are numbered from 1)
  348. *
  349. * Expands to the GNU C `strftime` format function attribute if the compiler
  350. * is gcc. This is used for declaring functions which take a format argument
  351. * which is passed to `strftime()` or an API implementing its formats. It allows
  352. * the compiler check the format passed to the function.
  353. *
  354. * |[<!-- language="C" -->
  355. * gsize my_strftime (MyBuffer *buffer,
  356. * const char *format,
  357. * const struct tm *tm) G_GNUC_STRFTIME (2);
  358. * ]|
  359. *
  360. * See the
  361. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288)
  362. * for details.
  363. *
  364. * Since: 2.60
  365. */
  366. /**
  367. * G_GNUC_FORMAT:
  368. * @arg_idx: the index of the argument
  369. *
  370. * Expands to the GNU C `format_arg` function attribute if the compiler
  371. * is gcc. This function attribute specifies that a function takes a
  372. * format string for a `printf()`, `scanf()`, `strftime()` or `strfmon()` style
  373. * function and modifies it, so that the result can be passed to a `printf()`,
  374. * `scanf()`, `strftime()` or `strfmon()` style function (with the remaining
  375. * arguments to the format function the same as they would have been
  376. * for the unmodified string).
  377. *
  378. * Place the attribute after the function declaration, just before the
  379. * semicolon.
  380. *
  381. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-nonliteral-1) for more details.
  382. *
  383. * |[<!-- language="C" -->
  384. * gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
  385. * ]|
  386. */
  387. /**
  388. * G_GNUC_NORETURN:
  389. *
  390. * Expands to the GNU C `noreturn` function attribute if the compiler is gcc.
  391. * It is used for declaring functions which never return. It enables
  392. * optimization of the function, and avoids possible compiler warnings.
  393. *
  394. * Place the attribute after the declaration, just before the semicolon.
  395. *
  396. * |[<!-- language="C" -->
  397. * void g_abort (void) G_GNUC_NORETURN;
  398. * ]|
  399. *
  400. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute) for more details.
  401. */
  402. /**
  403. * G_GNUC_CONST:
  404. *
  405. * Expands to the GNU C `const` function attribute if the compiler is gcc.
  406. * Declaring a function as `const` enables better optimization of calls to
  407. * the function. A `const` function doesn't examine any values except its
  408. * parameters, and has no effects except its return value.
  409. *
  410. * Place the attribute after the declaration, just before the semicolon.
  411. *
  412. * |[<!-- language="C" -->
  413. * gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
  414. * ]|
  415. *
  416. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute) for more details.
  417. *
  418. * A function that has pointer arguments and examines the data pointed to
  419. * must not be declared `const`. Likewise, a function that calls a non-`const`
  420. * function usually must not be `const`. It doesn't make sense for a `const`
  421. * function to return `void`.
  422. */
  423. /**
  424. * G_GNUC_UNUSED:
  425. *
  426. * Expands to the GNU C `unused` function attribute if the compiler is gcc.
  427. * It is used for declaring functions and arguments which may never be used.
  428. * It avoids possible compiler warnings.
  429. *
  430. * For functions, place the attribute after the declaration, just before the
  431. * semicolon. For arguments, place the attribute at the beginning of the
  432. * argument declaration.
  433. *
  434. * |[<!-- language="C" -->
  435. * void my_unused_function (G_GNUC_UNUSED gint unused_argument,
  436. * gint other_argument) G_GNUC_UNUSED;
  437. * ]|
  438. *
  439. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-unused-function-attribute) for more details.
  440. */
  441. /**
  442. * G_GNUC_NO_INSTRUMENT:
  443. *
  444. * Expands to the GNU C `no_instrument_function` function attribute if the
  445. * compiler is gcc. Functions with this attribute will not be instrumented
  446. * for profiling, when the compiler is called with the
  447. * `-finstrument-functions` option.
  448. *
  449. * Place the attribute after the declaration, just before the semicolon.
  450. *
  451. * |[<!-- language="C" -->
  452. * int do_uninteresting_things (void) G_GNUC_NO_INSTRUMENT;
  453. * ]|
  454. *
  455. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005finstrument_005ffunction-function-attribute) for more details.
  456. */
  457. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
  458. #if !defined (__clang__) && G_GNUC_CHECK_VERSION (4, 4)
  459. #define G_GNUC_PRINTF( format_idx, arg_idx ) \
  460. __attribute__((__format__ (gnu_printf, format_idx, arg_idx)))
  461. #define G_GNUC_SCANF( format_idx, arg_idx ) \
  462. __attribute__((__format__ (gnu_scanf, format_idx, arg_idx)))
  463. #define G_GNUC_STRFTIME( format_idx ) \
  464. __attribute__((__format__ (gnu_strftime, format_idx, 0)))
  465. #else
  466. #define G_GNUC_PRINTF( format_idx, arg_idx ) \
  467. __attribute__((__format__ (__printf__, format_idx, arg_idx)))
  468. #define G_GNUC_SCANF( format_idx, arg_idx ) \
  469. __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
  470. #define G_GNUC_STRFTIME( format_idx ) \
  471. __attribute__((__format__ (__strftime__, format_idx, 0)))
  472. #endif
  473. #define G_GNUC_FORMAT( arg_idx ) \
  474. __attribute__((__format_arg__ (arg_idx)))
  475. #define G_GNUC_NORETURN \
  476. __attribute__((__noreturn__))
  477. #define G_GNUC_CONST \
  478. __attribute__((__const__))
  479. #define G_GNUC_UNUSED \
  480. __attribute__((__unused__))
  481. #define G_GNUC_NO_INSTRUMENT \
  482. __attribute__((__no_instrument_function__))
  483. #else /* !__GNUC__ */
  484. #define G_GNUC_PRINTF( format_idx, arg_idx )
  485. #define G_GNUC_SCANF( format_idx, arg_idx )
  486. #define G_GNUC_STRFTIME( format_idx )
  487. #define G_GNUC_FORMAT( arg_idx )
  488. /* NOTE: MSVC has __declspec(noreturn) but unlike GCC __attribute__,
  489. * __declspec can only be placed at the start of the function prototype
  490. * and not at the end, so we can't use it without breaking API.
  491. */
  492. #define G_GNUC_NORETURN
  493. #define G_GNUC_CONST
  494. #define G_GNUC_UNUSED
  495. #define G_GNUC_NO_INSTRUMENT
  496. #endif /* !__GNUC__ */
  497. /**
  498. * G_GNUC_FALLTHROUGH:
  499. *
  500. * Expands to the GNU C `fallthrough` statement attribute if the compiler is gcc.
  501. * This allows declaring case statement to explicitly fall through in switch
  502. * statements. To enable this feature, use `-Wimplicit-fallthrough` during
  503. * compilation.
  504. *
  505. * Put the attribute right before the case statement you want to fall through
  506. * to.
  507. *
  508. * |[<!-- language="C" -->
  509. * switch (foo)
  510. * {
  511. * case 1:
  512. * g_message ("it's 1");
  513. * G_GNUC_FALLTHROUGH;
  514. * case 2:
  515. * g_message ("it's either 1 or 2");
  516. * break;
  517. * }
  518. * ]|
  519. *
  520. *
  521. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#index-fallthrough-statement-attribute) for more details.
  522. *
  523. * Since: 2.60
  524. */
  525. #if __GNUC__ > 6
  526. #define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
  527. #else
  528. #define G_GNUC_FALLTHROUGH
  529. #endif /* __GNUC__ */
  530. /**
  531. * G_GNUC_DEPRECATED:
  532. *
  533. * Expands to the GNU C `deprecated` attribute if the compiler is gcc.
  534. * It can be used to mark `typedef`s, variables and functions as deprecated.
  535. * When called with the `-Wdeprecated-declarations` option,
  536. * gcc will generate warnings when deprecated interfaces are used.
  537. *
  538. * Place the attribute after the declaration, just before the semicolon.
  539. *
  540. * |[<!-- language="C" -->
  541. * int my_mistake (void) G_GNUC_DEPRECATED;
  542. * ]|
  543. *
  544. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute) for more details.
  545. *
  546. * Since: 2.2
  547. */
  548. #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || defined (__clang__)
  549. #define G_GNUC_DEPRECATED __attribute__((__deprecated__))
  550. #else
  551. #define G_GNUC_DEPRECATED
  552. #endif /* __GNUC__ */
  553. /**
  554. * G_GNUC_DEPRECATED_FOR:
  555. * @f: the intended replacement for the deprecated symbol,
  556. * such as the name of a function
  557. *
  558. * Like %G_GNUC_DEPRECATED, but names the intended replacement for the
  559. * deprecated symbol if the version of gcc in use is new enough to support
  560. * custom deprecation messages.
  561. *
  562. * Place the attribute after the declaration, just before the semicolon.
  563. *
  564. * |[<!-- language="C" -->
  565. * int my_mistake (void) G_GNUC_DEPRECATED_FOR(my_replacement);
  566. * ]|
  567. *
  568. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute) for more details.
  569. *
  570. * Note that if @f is a macro, it will be expanded in the warning message.
  571. * You can enclose it in quotes to prevent this. (The quotes will show up
  572. * in the warning, but it's better than showing the macro expansion.)
  573. *
  574. * Since: 2.26
  575. */
  576. #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined (__clang__)
  577. #define G_GNUC_DEPRECATED_FOR(f) \
  578. __attribute__((deprecated("Use " #f " instead")))
  579. #else
  580. #define G_GNUC_DEPRECATED_FOR(f) G_GNUC_DEPRECATED
  581. #endif /* __GNUC__ */
  582. #ifdef __ICC
  583. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  584. _Pragma ("warning (push)") \
  585. _Pragma ("warning (disable:1478)")
  586. #define G_GNUC_END_IGNORE_DEPRECATIONS \
  587. _Pragma ("warning (pop)")
  588. #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
  589. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  590. _Pragma ("GCC diagnostic push") \
  591. _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
  592. #define G_GNUC_END_IGNORE_DEPRECATIONS \
  593. _Pragma ("GCC diagnostic pop")
  594. #elif defined (_MSC_VER) && (_MSC_VER >= 1500) && !defined (__clang__)
  595. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  596. __pragma (warning (push)) \
  597. __pragma (warning (disable : 4996))
  598. #define G_GNUC_END_IGNORE_DEPRECATIONS \
  599. __pragma (warning (pop))
  600. #elif defined (__clang__)
  601. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  602. _Pragma("clang diagnostic push") \
  603. _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
  604. #define G_GNUC_END_IGNORE_DEPRECATIONS \
  605. _Pragma("clang diagnostic pop")
  606. #else
  607. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  608. #define G_GNUC_END_IGNORE_DEPRECATIONS
  609. #endif
  610. /**
  611. * G_GNUC_MAY_ALIAS:
  612. *
  613. * Expands to the GNU C `may_alias` type attribute if the compiler is gcc.
  614. * Types with this attribute will not be subjected to type-based alias
  615. * analysis, but are assumed to alias with any other type, just like `char`.
  616. *
  617. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-may_005falias-type-attribute) for details.
  618. *
  619. * Since: 2.14
  620. */
  621. #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
  622. #define G_GNUC_MAY_ALIAS __attribute__((may_alias))
  623. #else
  624. #define G_GNUC_MAY_ALIAS
  625. #endif
  626. /**
  627. * G_GNUC_WARN_UNUSED_RESULT:
  628. *
  629. * Expands to the GNU C `warn_unused_result` function attribute if the compiler
  630. * is gcc. This function attribute makes the compiler emit a warning if the
  631. * result of a function call is ignored.
  632. *
  633. * Place the attribute after the declaration, just before the semicolon.
  634. *
  635. * |[<!-- language="C" -->
  636. * GList *g_list_append (GList *list,
  637. * gpointer data) G_GNUC_WARN_UNUSED_RESULT;
  638. * ]|
  639. *
  640. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-warn_005funused_005fresult-function-attribute) for more details.
  641. *
  642. * Since: 2.10
  643. */
  644. #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
  645. #define G_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  646. #else
  647. #define G_GNUC_WARN_UNUSED_RESULT
  648. #endif /* __GNUC__ */
  649. /**
  650. * G_GNUC_FUNCTION:
  651. *
  652. * Expands to "" on all modern compilers, and to __FUNCTION__ on gcc
  653. * version 2.x. Don't use it.
  654. *
  655. * Deprecated: 2.16: Use G_STRFUNC() instead
  656. */
  657. /**
  658. * G_GNUC_PRETTY_FUNCTION:
  659. *
  660. * Expands to "" on all modern compilers, and to __PRETTY_FUNCTION__
  661. * on gcc version 2.x. Don't use it.
  662. *
  663. * Deprecated: 2.16: Use G_STRFUNC() instead
  664. */
  665. /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
  666. * macros, so we can refer to them as strings unconditionally.
  667. * usage not-recommended since gcc-3.0
  668. *
  669. * Mark them as deprecated since 2.26, since that’s when version macros were
  670. * introduced.
  671. */
  672. #if defined (__GNUC__) && (__GNUC__ < 3)
  673. #define G_GNUC_FUNCTION __FUNCTION__ GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
  674. #define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__ GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
  675. #else /* !__GNUC__ */
  676. #define G_GNUC_FUNCTION "" GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
  677. #define G_GNUC_PRETTY_FUNCTION "" GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
  678. #endif /* !__GNUC__ */
  679. #if g_macro__has_feature(attribute_analyzer_noreturn) && defined(__clang_analyzer__)
  680. #define G_ANALYZER_ANALYZING 1
  681. #define G_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
  682. #else
  683. #define G_ANALYZER_ANALYZING 0
  684. #define G_ANALYZER_NORETURN
  685. #endif
  686. #define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
  687. #define G_STRINGIFY_ARG(contents) #contents
  688. #ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
  689. #define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
  690. #define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
  691. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
  692. #define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
  693. #elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
  694. (defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \
  695. (defined (_MSC_VER) && (_MSC_VER >= 1800))
  696. #define G_STATIC_ASSERT(expr) static_assert (expr, "Expression evaluates to false")
  697. #else
  698. #ifdef __COUNTER__
  699. #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
  700. #else
  701. #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_GNUC_UNUSED
  702. #endif
  703. #endif /* __STDC_VERSION__ */
  704. #define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
  705. #endif /* !__GI_SCANNER__ */
  706. /* Provide a string identifying the current code position */
  707. #if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
  708. #define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
  709. #else
  710. #define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
  711. #endif
  712. /* Provide a string identifying the current function, non-concatenatable */
  713. #if defined (__GNUC__) && defined (__cplusplus)
  714. #define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__))
  715. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  716. #define G_STRFUNC ((const char*) (__func__))
  717. #elif defined (__GNUC__) || (defined(_MSC_VER) && (_MSC_VER > 1300))
  718. #define G_STRFUNC ((const char*) (__FUNCTION__))
  719. #else
  720. #define G_STRFUNC ((const char*) ("???"))
  721. #endif
  722. /* Guard C code in headers, while including them from C++ */
  723. #ifdef __cplusplus
  724. #define G_BEGIN_DECLS extern "C" {
  725. #define G_END_DECLS }
  726. #else
  727. #define G_BEGIN_DECLS
  728. #define G_END_DECLS
  729. #endif
  730. /* Provide definitions for some commonly used macros.
  731. * Some of them are only provided if they haven't already
  732. * been defined. It is assumed that if they are already
  733. * defined then the current definition is correct.
  734. */
  735. #ifndef NULL
  736. # ifdef __cplusplus
  737. # define NULL (0L)
  738. # else /* !__cplusplus */
  739. # define NULL ((void*) 0)
  740. # endif /* !__cplusplus */
  741. #endif
  742. #ifndef FALSE
  743. #define FALSE (0)
  744. #endif
  745. #ifndef TRUE
  746. #define TRUE (!FALSE)
  747. #endif
  748. #undef MAX
  749. #define MAX(a, b) (((a) > (b)) ? (a) : (b))
  750. #undef MIN
  751. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  752. #undef ABS
  753. #define ABS(a) (((a) < 0) ? -(a) : (a))
  754. #undef CLAMP
  755. #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
  756. #define G_APPROX_VALUE(a, b, epsilon) \
  757. (((a) > (b) ? (a) - (b) : (b) - (a)) < (epsilon))
  758. /* Count the number of elements in an array. The array must be defined
  759. * as such; using this with a dynamically allocated array will give
  760. * incorrect results.
  761. */
  762. #define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
  763. /* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
  764. */
  765. #define GPOINTER_TO_SIZE(p) ((gsize) (p))
  766. #define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
  767. /* Provide convenience macros for handling structure
  768. * fields through their offsets.
  769. */
  770. #if (defined(__GNUC__) && __GNUC__ >= 4) || defined (_MSC_VER)
  771. #define G_STRUCT_OFFSET(struct_type, member) \
  772. ((glong) offsetof (struct_type, member))
  773. #else
  774. #define G_STRUCT_OFFSET(struct_type, member) \
  775. ((glong) ((guint8*) &((struct_type*) 0)->member))
  776. #endif
  777. #define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
  778. ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
  779. #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
  780. (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
  781. /* Provide simple macro statement wrappers:
  782. * G_STMT_START { statements; } G_STMT_END;
  783. * This can be used as a single statement, like:
  784. * if (x) G_STMT_START { ... } G_STMT_END; else ...
  785. * This intentionally does not use compiler extensions like GCC's '({...})' to
  786. * avoid portability issue or side effects when compiled with different compilers.
  787. * MSVC complains about "while(0)": C4127: "Conditional expression is constant",
  788. * so we use __pragma to avoid the warning since the use here is intentional.
  789. */
  790. #if !(defined (G_STMT_START) && defined (G_STMT_END))
  791. #define G_STMT_START do
  792. #if defined (_MSC_VER) && (_MSC_VER >= 1500)
  793. #define G_STMT_END \
  794. __pragma(warning(push)) \
  795. __pragma(warning(disable:4127)) \
  796. while(0) \
  797. __pragma(warning(pop))
  798. #else
  799. #define G_STMT_END while (0)
  800. #endif
  801. #endif
  802. /* Provide G_ALIGNOF alignment macro.
  803. *
  804. * Note we cannot use the gcc __alignof__ operator here, as that returns the
  805. * preferred alignment rather than the minimal alignment. See
  806. * https://gitlab.gnome.org/GNOME/glib/merge_requests/538/diffs#note_390790.
  807. */
  808. /**
  809. * G_ALIGNOF
  810. * @type: a type-name
  811. *
  812. * Return the minimal alignment required by the platform ABI for values of the given
  813. * type. The address of a variable or struct member of the given type must always be
  814. * a multiple of this alignment. For example, most platforms require int variables
  815. * to be aligned at a 4-byte boundary, so `G_ALIGNOF (int)` is 4 on most platforms.
  816. *
  817. * Note this is not necessarily the same as the value returned by GCC’s
  818. * `__alignof__` operator, which returns the preferred alignment for a type.
  819. * The preferred alignment may be a stricter alignment than the minimal
  820. * alignment.
  821. *
  822. * Since: 2.60
  823. */
  824. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
  825. #define G_ALIGNOF(type) _Alignof (type)
  826. #else
  827. #define G_ALIGNOF(type) (G_STRUCT_OFFSET (struct { char a; type b; }, b))
  828. #endif
  829. /**
  830. * G_CONST_RETURN:
  831. *
  832. * If %G_DISABLE_CONST_RETURNS is defined, this macro expands
  833. * to nothing. By default, the macro expands to const. The macro
  834. * can be used in place of const for functions that return a value
  835. * that should not be modified. The purpose of this macro is to allow
  836. * us to turn on const for returned constant strings by default, while
  837. * allowing programmers who find that annoying to turn it off. This macro
  838. * should only be used for return values and for "out" parameters, it
  839. * doesn't make sense for "in" parameters.
  840. *
  841. * Deprecated: 2.30: API providers should replace all existing uses with
  842. * const and API consumers should adjust their code accordingly
  843. */
  844. #ifdef G_DISABLE_CONST_RETURNS
  845. #define G_CONST_RETURN GLIB_DEPRECATED_MACRO_IN_2_30_FOR(const)
  846. #else
  847. #define G_CONST_RETURN const GLIB_DEPRECATED_MACRO_IN_2_30_FOR(const)
  848. #endif
  849. /*
  850. * The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
  851. * the compiler about the expected result of an expression. Some compilers
  852. * can use this information for optimizations.
  853. *
  854. * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
  855. * putting assignments in g_return_if_fail ().
  856. */
  857. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  858. #define _G_BOOLEAN_EXPR(expr) \
  859. G_GNUC_EXTENSION ({ \
  860. int _g_boolean_var_; \
  861. if (expr) \
  862. _g_boolean_var_ = 1; \
  863. else \
  864. _g_boolean_var_ = 0; \
  865. _g_boolean_var_; \
  866. })
  867. #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
  868. #define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
  869. #else
  870. #define G_LIKELY(expr) (expr)
  871. #define G_UNLIKELY(expr) (expr)
  872. #endif
  873. #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || defined (__clang__)
  874. #define G_DEPRECATED __attribute__((__deprecated__))
  875. #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
  876. #define G_DEPRECATED __declspec(deprecated)
  877. #else
  878. #define G_DEPRECATED
  879. #endif
  880. #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined (__clang__)
  881. #define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
  882. #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
  883. #define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))
  884. #else
  885. #define G_DEPRECATED_FOR(f) G_DEPRECATED
  886. #endif
  887. #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined (__clang__)
  888. #define G_UNAVAILABLE(maj,min) __attribute__((deprecated("Not available before " #maj "." #min)))
  889. #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
  890. #define G_UNAVAILABLE(maj,min) __declspec(deprecated("is not available before " #maj "." #min))
  891. #else
  892. #define G_UNAVAILABLE(maj,min) G_DEPRECATED
  893. #endif
  894. #ifndef _GLIB_EXTERN
  895. #define _GLIB_EXTERN extern
  896. #endif
  897. /* These macros are used to mark deprecated symbols in GLib headers,
  898. * and thus have to be exposed in installed headers. But please
  899. * do *not* use them in other projects. Instead, use G_DEPRECATED
  900. * or define your own wrappers around it.
  901. */
  902. #ifdef GLIB_DISABLE_DEPRECATION_WARNINGS
  903. #define GLIB_DEPRECATED _GLIB_EXTERN
  904. #define GLIB_DEPRECATED_FOR(f) _GLIB_EXTERN
  905. #define GLIB_UNAVAILABLE(maj,min) _GLIB_EXTERN
  906. #else
  907. #define GLIB_DEPRECATED G_DEPRECATED _GLIB_EXTERN
  908. #define GLIB_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _GLIB_EXTERN
  909. #define GLIB_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _GLIB_EXTERN
  910. #endif
  911. #if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
  912. (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || \
  913. __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4))
  914. #define _GLIB_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x))
  915. #define GLIB_DEPRECATED_MACRO _GLIB_GNUC_DO_PRAGMA(GCC warning "Deprecated pre-processor symbol")
  916. #define GLIB_DEPRECATED_MACRO_FOR(f) _GLIB_GNUC_DO_PRAGMA(GCC warning #f)
  917. #define GLIB_UNAVAILABLE_MACRO(maj,min) _GLIB_GNUC_DO_PRAGMA(GCC warning "Not available before " #maj "." #min)
  918. #else
  919. #define GLIB_DEPRECATED_MACRO
  920. #define GLIB_DEPRECATED_MACRO_FOR(f)
  921. #define GLIB_UNAVAILABLE_MACRO(maj,min)
  922. #endif
  923. #if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
  924. ((defined (__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1))) || \
  925. (defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0))))
  926. #define GLIB_DEPRECATED_ENUMERATOR G_DEPRECATED
  927. #define GLIB_DEPRECATED_ENUMERATOR_FOR(f) G_DEPRECATED_FOR(f)
  928. #define GLIB_UNAVAILABLE_ENUMERATOR(maj,min) G_UNAVAILABLE(maj,min)
  929. #else
  930. #define GLIB_DEPRECATED_ENUMERATOR
  931. #define GLIB_DEPRECATED_ENUMERATOR_FOR(f)
  932. #define GLIB_UNAVAILABLE_ENUMERATOR(maj,min)
  933. #endif
  934. #if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
  935. ((defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) || \
  936. (defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0))))
  937. #define GLIB_DEPRECATED_TYPE G_DEPRECATED
  938. #define GLIB_DEPRECATED_TYPE_FOR(f) G_DEPRECATED_FOR(f)
  939. #define GLIB_UNAVAILABLE_TYPE(maj,min) G_UNAVAILABLE(maj,min)
  940. #else
  941. #define GLIB_DEPRECATED_TYPE
  942. #define GLIB_DEPRECATED_TYPE_FOR(f)
  943. #define GLIB_UNAVAILABLE_TYPE(maj,min)
  944. #endif
  945. #ifndef __GI_SCANNER__
  946. #if defined (__GNUC__) || defined (__clang__)
  947. /* these macros are private */
  948. #define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
  949. #define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName
  950. #define _GLIB_AUTOPTR_TYPENAME(TypeName) TypeName##_autoptr
  951. #define _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) glib_listautoptr_cleanup_##TypeName
  952. #define _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) TypeName##_listautoptr
  953. #define _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) glib_slistautoptr_cleanup_##TypeName
  954. #define _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) TypeName##_slistautoptr
  955. #define _GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName) glib_queueautoptr_cleanup_##TypeName
  956. #define _GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName) TypeName##_queueautoptr
  957. #define _GLIB_AUTO_FUNC_NAME(TypeName) glib_auto_cleanup_##TypeName
  958. #define _GLIB_CLEANUP(func) __attribute__((cleanup(func)))
  959. #define _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, ParentName, cleanup) \
  960. typedef TypeName *_GLIB_AUTOPTR_TYPENAME(TypeName); \
  961. typedef GList *_GLIB_AUTOPTR_LIST_TYPENAME(TypeName); \
  962. typedef GSList *_GLIB_AUTOPTR_SLIST_TYPENAME(TypeName); \
  963. typedef GQueue *_GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName); \
  964. G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  965. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (TypeName *_ptr) \
  966. { if (_ptr) (cleanup) ((ParentName *) _ptr); } \
  967. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) \
  968. { _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (*_ptr); } \
  969. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) \
  970. { g_list_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); } \
  971. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) \
  972. { g_slist_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); } \
  973. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName) (GQueue **_q) \
  974. { if (*_q) g_queue_free_full (*_q, (GDestroyNotify) (void(*)(void)) cleanup); } \
  975. G_GNUC_END_IGNORE_DEPRECATIONS
  976. #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \
  977. _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(ModuleObjName, ParentName, _GLIB_AUTOPTR_CLEAR_FUNC_NAME(ParentName))
  978. /* these macros are API */
  979. #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
  980. _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, TypeName, func)
  981. #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func) \
  982. G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  983. static inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { (func) (_ptr); } \
  984. G_GNUC_END_IGNORE_DEPRECATIONS
  985. #define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none) \
  986. G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  987. static inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { if (*_ptr != none) (func) (*_ptr); } \
  988. G_GNUC_END_IGNORE_DEPRECATIONS
  989. #define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName)
  990. #define g_autolist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_LIST_TYPENAME(TypeName)
  991. #define g_autoslist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName)
  992. #define g_autoqueue(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName)
  993. #define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName
  994. #define g_autofree _GLIB_CLEANUP(g_autoptr_cleanup_generic_gfree)
  995. #else /* not GNU C */
  996. /* this (dummy) macro is private */
  997. #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
  998. /* these (dummy) macros are API */
  999. #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
  1000. #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
  1001. #define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
  1002. /* no declaration of g_auto() or g_autoptr() here */
  1003. #endif /* __GNUC__ */
  1004. #else
  1005. #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
  1006. #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
  1007. #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
  1008. #define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
  1009. #endif /* __GI_SCANNER__ */
  1010. #endif /* __G_MACROS_H__ */