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/* For historical reasons we need to continue to support those who
86 * define G_IMPLEMENT_INLINES to mean "don't implement this here".
87 */
88#ifdef G_IMPLEMENT_INLINES
89# define G_INLINE_FUNC extern
90# undef G_CAN_INLINE
91#else
92# define G_INLINE_FUNC static inline
93#endif /* G_IMPLEMENT_INLINES */
94
95/* Provide macros to feature the GCC function attribute.
96 */
97#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
98#define G_GNUC_PURE __attribute__((__pure__))
99#define G_GNUC_MALLOC __attribute__((__malloc__))
100#define G_GNUC_NO_INLINE __attribute__((noinline))
101#else
102#define G_GNUC_PURE
103#define G_GNUC_MALLOC
104#define G_GNUC_NO_INLINE
105#endif
106
107#if __GNUC__ >= 4
108#define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
109#else
110#define G_GNUC_NULL_TERMINATED
111#endif
112
113/*
114 * We can only use __typeof__ on GCC >= 4.8, and not when compiling C++. Since
115 * __typeof__ is used in a few places in GLib, provide a pre-processor symbol
116 * to factor the check out from callers.
117 *
118 * This symbol is private.
119 */
120#undef g_has_typeof
121#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && !defined(__cplusplus)
122#define g_has_typeof
123#endif
124
125/*
126 * Clang feature detection: http://clang.llvm.org/docs/LanguageExtensions.html
127 * These are not available on GCC, but since the pre-processor doesn't do
128 * operator short-circuiting, we can't use it in a statement or we'll get:
129 *
130 * error: missing binary operator before token "("
131 *
132 * So we define it to 0 to satisfy the pre-processor.
133 */
134
135#ifdef __has_attribute
136#define g_macro__has_attribute __has_attribute
137#else
138#define g_macro__has_attribute(x) 0
139#endif
140
141#ifdef __has_feature
142#define g_macro__has_feature __has_feature
143#else
144#define g_macro__has_feature(x) 0
145#endif
146
147#ifdef __has_builtin
148#define g_macro__has_builtin __has_builtin
149#else
150#define g_macro__has_builtin(x) 0
151#endif
152
153#if (!defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \
154 (defined(__clang__) && g_macro__has_attribute(__alloc_size__))
155#define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
156#define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
157#else
158#define G_GNUC_ALLOC_SIZE(x)
159#define G_GNUC_ALLOC_SIZE2(x,y)
160#endif
161
162#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
163#if !defined (__clang__) && G_GNUC_CHECK_VERSION (4, 4)
164#define G_GNUC_PRINTF( format_idx, arg_idx ) \
165 __attribute__((__format__ (gnu_printf, format_idx, arg_idx)))
166#define G_GNUC_SCANF( format_idx, arg_idx ) \
167 __attribute__((__format__ (gnu_scanf, format_idx, arg_idx)))
168#define G_GNUC_STRFTIME( format_idx ) \
169 __attribute__((__format__ (gnu_strftime, format_idx, 0)))
170#else
171#define G_GNUC_PRINTF( format_idx, arg_idx ) \
172 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
173#define G_GNUC_SCANF( format_idx, arg_idx ) \
174 __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
175#define G_GNUC_STRFTIME( format_idx ) \
176 __attribute__((__format__ (__strftime__, format_idx, 0)))
177#endif
178#define G_GNUC_FORMAT( arg_idx ) \
179 __attribute__((__format_arg__ (arg_idx)))
180#define G_GNUC_NORETURN \
181 __attribute__((__noreturn__))
182#define G_GNUC_CONST \
183 __attribute__((__const__))
184#define G_GNUC_UNUSED \
185 __attribute__((__unused__))
186#define G_GNUC_NO_INSTRUMENT \
187 __attribute__((__no_instrument_function__))
188#else /* !__GNUC__ */
189#define G_GNUC_PRINTF( format_idx, arg_idx )
190#define G_GNUC_SCANF( format_idx, arg_idx )
191#define G_GNUC_STRFTIME( format_idx )
192#define G_GNUC_FORMAT( arg_idx )
193/* NOTE: MSVC has __declspec(noreturn) but unlike GCC __attribute__,
194 * __declspec can only be placed at the start of the function prototype
195 * and not at the end, so we can't use it without breaking API.
196 */
197#define G_GNUC_NORETURN
198#define G_GNUC_CONST
199#define G_GNUC_UNUSED
200#define G_GNUC_NO_INSTRUMENT
201#endif /* !__GNUC__ */
202
203#if __GNUC__ > 6
204#define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
205#else
206#define G_GNUC_FALLTHROUGH
207#endif /* __GNUC__ */
208
209#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
210#define G_GNUC_DEPRECATED __attribute__((__deprecated__))
211#else
212#define G_GNUC_DEPRECATED
213#endif /* __GNUC__ */
214
215#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
216#define G_GNUC_DEPRECATED_FOR(f) \
217 __attribute__((deprecated("Use " #f " instead")))
218#else
219#define G_GNUC_DEPRECATED_FOR(f) G_GNUC_DEPRECATED
220#endif /* __GNUC__ */
221
222#ifdef __ICC
223#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
224 _Pragma ("warning (push)") \
225 _Pragma ("warning (disable:1478)")
226#define G_GNUC_END_IGNORE_DEPRECATIONS \
227 _Pragma ("warning (pop)")
228#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
229#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
230 _Pragma ("GCC diagnostic push") \
231 _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
232#define G_GNUC_END_IGNORE_DEPRECATIONS \
233 _Pragma ("GCC diagnostic pop")
234#elif defined (_MSC_VER) && (_MSC_VER >= 1500)
235#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
236 __pragma (warning (push)) \
237 __pragma (warning (disable : 4996))
238#define G_GNUC_END_IGNORE_DEPRECATIONS \
239 __pragma (warning (pop))
240#elif defined (__clang__)
241#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
242 _Pragma("clang diagnostic push") \
243 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
244#define G_GNUC_END_IGNORE_DEPRECATIONS \
245 _Pragma("clang diagnostic pop")
246#else
247#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS
248#define G_GNUC_END_IGNORE_DEPRECATIONS
249#endif
250
251#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
252#define G_GNUC_MAY_ALIAS __attribute__((may_alias))
253#else
254#define G_GNUC_MAY_ALIAS
255#endif
256
257#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
258#define G_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
259#else
260#define G_GNUC_WARN_UNUSED_RESULT
261#endif /* __GNUC__ */
262
263#ifndef G_DISABLE_DEPRECATED
264/* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
265 * macros, so we can refer to them as strings unconditionally.
266 * usage not-recommended since gcc-3.0
267 */
268#if defined (__GNUC__) && (__GNUC__ < 3)
269#define G_GNUC_FUNCTION __FUNCTION__
270#define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
271#else /* !__GNUC__ */
272#define G_GNUC_FUNCTION ""
273#define G_GNUC_PRETTY_FUNCTION ""
274#endif /* !__GNUC__ */
275#endif /* !G_DISABLE_DEPRECATED */
276
277#if g_macro__has_feature(attribute_analyzer_noreturn) && defined(__clang_analyzer__)
278#define G_ANALYZER_ANALYZING 1
279#define G_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
280#else
281#define G_ANALYZER_ANALYZING 0
282#define G_ANALYZER_NORETURN
283#endif
284
285#define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
286#define G_STRINGIFY_ARG(contents) #contents
287
288#ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
289#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
290#define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
291#ifdef __COUNTER__
292#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
293#else
294#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_GNUC_UNUSED
295#endif
296#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
297#endif
298
299/* Provide a string identifying the current code position */
300#if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
301#define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
302#else
303#define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
304#endif
305
306/* Provide a string identifying the current function, non-concatenatable */
307#if defined (__GNUC__) && defined (__cplusplus)
308#define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__))
309#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
310#define G_STRFUNC ((const char*) (__func__))
311#elif defined (__GNUC__) || (defined(_MSC_VER) && (_MSC_VER > 1300))
312#define G_STRFUNC ((const char*) (__FUNCTION__))
313#else
314#define G_STRFUNC ((const char*) ("???"))
315#endif
316
317/* Guard C code in headers, while including them from C++ */
318#ifdef __cplusplus
319#define G_BEGIN_DECLS extern "C" {
320#define G_END_DECLS }
321#else
322#define G_BEGIN_DECLS
323#define G_END_DECLS
324#endif
325
326/* Provide definitions for some commonly used macros.
327 * Some of them are only provided if they haven't already
328 * been defined. It is assumed that if they are already
329 * defined then the current definition is correct.
330 */
331#ifndef NULL
332# ifdef __cplusplus
333# define NULL (0L)
334# else /* !__cplusplus */
335# define NULL ((void*) 0)
336# endif /* !__cplusplus */
337#endif
338
339#ifndef FALSE
340#define FALSE (0)
341#endif
342
343#ifndef TRUE
344#define TRUE (!FALSE)
345#endif
346
347#undef MAX
348#define MAX(a, b) (((a) > (b)) ? (a) : (b))
349
350#undef MIN
351#define MIN(a, b) (((a) < (b)) ? (a) : (b))
352
353#undef ABS
354#define ABS(a) (((a) < 0) ? -(a) : (a))
355
356#undef CLAMP
357#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
358
359#define G_APPROX_VALUE(a, b, epsilon) \
360 (((a) > (b) ? (a) - (b) : (b) - (a)) < (epsilon))
361
362/* Count the number of elements in an array. The array must be defined
363 * as such; using this with a dynamically allocated array will give
364 * incorrect results.
365 */
366#define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
367
368/* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
369 */
370#define GPOINTER_TO_SIZE(p) ((gsize) (p))
371#define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
372
373/* Provide convenience macros for handling structure
374 * fields through their offsets.
375 */
376
377#if (defined(__GNUC__) && __GNUC__ >= 4) || defined (_MSC_VER)
378#define G_STRUCT_OFFSET(struct_type, member) \
379 ((glong) offsetof (struct_type, member))
380#else
381#define G_STRUCT_OFFSET(struct_type, member) \
382 ((glong) ((guint8*) &((struct_type*) 0)->member))
383#endif
384
385#define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
386 ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
387#define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
388 (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
389
390/* Provide simple macro statement wrappers:
391 * G_STMT_START { statements; } G_STMT_END;
392 * This can be used as a single statement, like:
393 * if (x) G_STMT_START { ... } G_STMT_END; else ...
394 * This intentionally does not use compiler extensions like GCC's '({...})' to
395 * avoid portability issue or side effects when compiled with different compilers.
396 * MSVC complains about "while(0)": C4127: "Conditional expression is constant",
397 * so we use __pragma to avoid the warning since the use here is intentional.
398 */
399#if !(defined (G_STMT_START) && defined (G_STMT_END))
400#define G_STMT_START do
401#if defined (_MSC_VER) && (_MSC_VER >= 1500)
402#define G_STMT_END \
403 __pragma(warning(push)) \
404 __pragma(warning(disable:4127)) \
405 while(0) \
406 __pragma(warning(pop))
407#else
408#define G_STMT_END while (0)
409#endif
410#endif
411
412/* Provide G_ALIGNOF alignment macro.
413 *
414 * Note we cannot use the gcc __alignof__ operator here, as that returns the
415 * preferred alignment rather than the minimal alignment. See
416 * https://gitlab.gnome.org/GNOME/glib/merge_requests/538/diffs#note_390790.
417 */
418
419#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
420#define G_ALIGNOF(type) _Alignof (type)
421#else
422#define G_ALIGNOF(type) (G_STRUCT_OFFSET (struct { char a; type b; }, b))
423#endif
424
425/* Deprecated -- do not use. */
426#ifndef G_DISABLE_DEPRECATED
427#ifdef G_DISABLE_CONST_RETURNS
428#define G_CONST_RETURN
429#else
430#define G_CONST_RETURN const
431#endif
432#endif
433
434/*
435 * The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
436 * the compiler about the expected result of an expression. Some compilers
437 * can use this information for optimizations.
438 *
439 * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
440 * putting assignments in g_return_if_fail ().
441 */
442#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
443#define _G_BOOLEAN_EXPR(expr) \
444 G_GNUC_EXTENSION ({ \
445 int _g_boolean_var_; \
446 if (expr) \
447 _g_boolean_var_ = 1; \
448 else \
449 _g_boolean_var_ = 0; \
450 _g_boolean_var_; \
451})
452#define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
453#define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
454#else
455#define G_LIKELY(expr) (expr)
456#define G_UNLIKELY(expr) (expr)
457#endif
458
459#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
460#define G_DEPRECATED __attribute__((__deprecated__))
461#elif defined(_MSC_VER) && (_MSC_VER >= 1300)
462#define G_DEPRECATED __declspec(deprecated)
463#else
464#define G_DEPRECATED
465#endif
466
467#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
468#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
469#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
470#define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))
471#else
472#define G_DEPRECATED_FOR(f) G_DEPRECATED
473#endif
474
475#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
476#define G_UNAVAILABLE(maj,min) __attribute__((deprecated("Not available before " #maj "." #min)))
477#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
478#define G_UNAVAILABLE(maj,min) __declspec(deprecated("is not available before " #maj "." #min))
479#else
480#define G_UNAVAILABLE(maj,min) G_DEPRECATED
481#endif
482
483#ifndef _GLIB_EXTERN
484#define _GLIB_EXTERN extern
485#endif
486
487/* These macros are used to mark deprecated functions in GLib headers,
488 * and thus have to be exposed in installed headers. But please
489 * do *not* use them in other projects. Instead, use G_DEPRECATED
490 * or define your own wrappers around it.
491 */
492
493#ifdef GLIB_DISABLE_DEPRECATION_WARNINGS
494#define GLIB_DEPRECATED _GLIB_EXTERN
495#define GLIB_DEPRECATED_FOR(f) _GLIB_EXTERN
496#define GLIB_UNAVAILABLE(maj,min) _GLIB_EXTERN
497#else
498#define GLIB_DEPRECATED G_DEPRECATED _GLIB_EXTERN
499#define GLIB_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _GLIB_EXTERN
500#define GLIB_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _GLIB_EXTERN
501#endif
502
503#ifndef __GI_SCANNER__
504
505#ifdef __GNUC__
506
507/* these macros are private */
508#define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
509#define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName
510#define _GLIB_AUTOPTR_TYPENAME(TypeName) TypeName##_autoptr
511#define _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) glib_listautoptr_cleanup_##TypeName
512#define _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) TypeName##_listautoptr
513#define _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) glib_slistautoptr_cleanup_##TypeName
514#define _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) TypeName##_slistautoptr
515#define _GLIB_AUTO_FUNC_NAME(TypeName) glib_auto_cleanup_##TypeName
516#define _GLIB_CLEANUP(func) __attribute__((cleanup(func)))
517#define _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, ParentName, cleanup) \
518 typedef TypeName *_GLIB_AUTOPTR_TYPENAME(TypeName); \
519 typedef GList *_GLIB_AUTOPTR_LIST_TYPENAME(TypeName); \
520 typedef GSList *_GLIB_AUTOPTR_SLIST_TYPENAME(TypeName); \
521 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
522 static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (TypeName *_ptr) \
523 { if (_ptr) (cleanup) ((ParentName *) _ptr); } \
524 static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) \
525 { _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (*_ptr); } \
526 static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) \
527 { g_list_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); } \
528 static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) \
529 { g_slist_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); } \
530 G_GNUC_END_IGNORE_DEPRECATIONS
531#define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \
532 _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(ModuleObjName, ParentName, _GLIB_AUTOPTR_CLEAR_FUNC_NAME(ParentName))
533
534
535/* these macros are API */
536#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
537 _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, TypeName, func)
538#define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func) \
539 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
540 static inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { (func) (_ptr); } \
541 G_GNUC_END_IGNORE_DEPRECATIONS
542#define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none) \
543 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
544 static inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { if (*_ptr != none) (func) (*_ptr); } \
545 G_GNUC_END_IGNORE_DEPRECATIONS
546#define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName)
547#define g_autolist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_LIST_TYPENAME(TypeName)
548#define g_autoslist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName)
549#define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName
550#define g_autofree _GLIB_CLEANUP(g_autoptr_cleanup_generic_gfree)
551
552#else /* not GNU C */
553/* this (dummy) macro is private */
554#define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
555
556/* these (dummy) macros are API */
557#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
558#define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
559#define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
560
561/* no declaration of g_auto() or g_autoptr() here */
562#endif /* __GNUC__ */
563
564#else
565
566#define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
567
568#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
569#define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
570#define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
571
572#endif /* __GI_SCANNER__ */
573
574#endif /* __G_MACROS_H__ */
575