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