Merge branch 'doc-types' into 'master'
[glib.git] / glib / gmacros.h
blobcfeb9a00bafb917c917dc3b5f34be9ce7042856a
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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/>.
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/.
25 /* This file must not include any other glib header file and must thus
26 * not refer to variables from glibconfig.h
29 #ifndef __G_MACROS_H__
30 #define __G_MACROS_H__
32 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
33 #error "Only <glib.h> can be included directly."
34 #endif
36 /* We include stddef.h to get the system's definition of NULL
38 #include <stddef.h>
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
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'.
53 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
54 #define G_GNUC_EXTENSION __extension__
55 #else
56 #define G_GNUC_EXTENSION
57 #endif
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.
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
78 #ifdef G_INLINE_DEFINE_NEEDED
79 # undef inline
80 # define inline __inline
81 #endif
83 #undef G_INLINE_DEFINE_NEEDED
85 /* For historical reasons we need to continue to support those who
86 * define G_IMPLEMENT_INLINES to mean "don't implement this here".
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 */
95 /* Provide macros to feature the GCC function attribute.
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
107 #if __GNUC__ >= 4
108 #define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
109 #else
110 #define G_GNUC_NULL_TERMINATED
111 #endif
114 * Clang feature detection: http://clang.llvm.org/docs/LanguageExtensions.html
115 * These are not available on GCC, but since the pre-processor doesn't do
116 * operator short-circuiting, we can't use it in a statement or we'll get:
118 * error: missing binary operator before token "("
120 * So we define it to 0 to satisfy the pre-processor.
123 #ifdef __has_attribute
124 #define g_macro__has_attribute __has_attribute
125 #else
126 #define g_macro__has_attribute(x) 0
127 #endif
129 #ifdef __has_feature
130 #define g_macro__has_feature __has_feature
131 #else
132 #define g_macro__has_feature(x) 0
133 #endif
135 #ifdef __has_builtin
136 #define g_macro__has_builtin __has_builtin
137 #else
138 #define g_macro__has_builtin(x) 0
139 #endif
141 #if (!defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || \
142 (defined(__clang__) && g_macro__has_attribute(__alloc_size__))
143 #define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
144 #define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
145 #else
146 #define G_GNUC_ALLOC_SIZE(x)
147 #define G_GNUC_ALLOC_SIZE2(x,y)
148 #endif
150 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
151 #if !defined (__clang__) && G_GNUC_CHECK_VERSION (4, 4)
152 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
153 __attribute__((__format__ (gnu_printf, format_idx, arg_idx)))
154 #define G_GNUC_SCANF( format_idx, arg_idx ) \
155 __attribute__((__format__ (gnu_scanf, format_idx, arg_idx)))
156 #else
157 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
158 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
159 #define G_GNUC_SCANF( format_idx, arg_idx ) \
160 __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
161 #endif
162 #define G_GNUC_FORMAT( arg_idx ) \
163 __attribute__((__format_arg__ (arg_idx)))
164 #define G_GNUC_NORETURN \
165 __attribute__((__noreturn__))
166 #define G_GNUC_CONST \
167 __attribute__((__const__))
168 #define G_GNUC_UNUSED \
169 __attribute__((__unused__))
170 #define G_GNUC_NO_INSTRUMENT \
171 __attribute__((__no_instrument_function__))
172 #else /* !__GNUC__ */
173 #define G_GNUC_PRINTF( format_idx, arg_idx )
174 #define G_GNUC_SCANF( format_idx, arg_idx )
175 #define G_GNUC_FORMAT( arg_idx )
176 #define G_GNUC_NORETURN
177 #define G_GNUC_CONST
178 #define G_GNUC_UNUSED
179 #define G_GNUC_NO_INSTRUMENT
180 #endif /* !__GNUC__ */
182 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
183 #define G_GNUC_DEPRECATED __attribute__((__deprecated__))
184 #else
185 #define G_GNUC_DEPRECATED
186 #endif /* __GNUC__ */
188 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
189 #define G_GNUC_DEPRECATED_FOR(f) \
190 __attribute__((deprecated("Use " #f " instead")))
191 #else
192 #define G_GNUC_DEPRECATED_FOR(f) G_GNUC_DEPRECATED
193 #endif /* __GNUC__ */
195 #ifdef __ICC
196 #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
197 _Pragma ("warning (push)") \
198 _Pragma ("warning (disable:1478)")
199 #define G_GNUC_END_IGNORE_DEPRECATIONS \
200 _Pragma ("warning (pop)")
201 #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
202 #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
203 _Pragma ("GCC diagnostic push") \
204 _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
205 #define G_GNUC_END_IGNORE_DEPRECATIONS \
206 _Pragma ("GCC diagnostic pop")
207 #elif defined (_MSC_VER) && (_MSC_VER >= 1500)
208 #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
209 __pragma (warning (push)) \
210 __pragma (warning (disable : 4996))
211 #define G_GNUC_END_IGNORE_DEPRECATIONS \
212 __pragma (warning (pop))
213 #elif defined (__clang__)
214 #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
215 _Pragma("clang diagnostic push") \
216 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
217 #define G_GNUC_END_IGNORE_DEPRECATIONS \
218 _Pragma("clang diagnostic pop")
219 #else
220 #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS
221 #define G_GNUC_END_IGNORE_DEPRECATIONS
222 #endif
224 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
225 #define G_GNUC_MAY_ALIAS __attribute__((may_alias))
226 #else
227 #define G_GNUC_MAY_ALIAS
228 #endif
230 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
231 #define G_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
232 #else
233 #define G_GNUC_WARN_UNUSED_RESULT
234 #endif /* __GNUC__ */
236 #ifndef G_DISABLE_DEPRECATED
237 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
238 * macros, so we can refer to them as strings unconditionally.
239 * usage not-recommended since gcc-3.0
241 #if defined (__GNUC__) && (__GNUC__ < 3)
242 #define G_GNUC_FUNCTION __FUNCTION__
243 #define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
244 #else /* !__GNUC__ */
245 #define G_GNUC_FUNCTION ""
246 #define G_GNUC_PRETTY_FUNCTION ""
247 #endif /* !__GNUC__ */
248 #endif /* !G_DISABLE_DEPRECATED */
250 #if g_macro__has_feature(attribute_analyzer_noreturn) && defined(__clang_analyzer__)
251 #define G_ANALYZER_ANALYZING 1
252 #define G_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
253 #else
254 #define G_ANALYZER_ANALYZING 0
255 #define G_ANALYZER_NORETURN
256 #endif
258 #define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
259 #define G_STRINGIFY_ARG(contents) #contents
261 #ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
262 #define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
263 #define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
264 #ifdef __COUNTER__
265 #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
266 #else
267 #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_GNUC_UNUSED
268 #endif
269 #define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
270 #endif
272 /* Provide a string identifying the current code position */
273 #if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
274 #define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
275 #else
276 #define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
277 #endif
279 /* Provide a string identifying the current function, non-concatenatable */
280 #if defined (__GNUC__) && defined (__cplusplus)
281 #define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__))
282 #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
283 #define G_STRFUNC ((const char*) (__func__))
284 #elif defined (__GNUC__) || (defined(_MSC_VER) && (_MSC_VER > 1300))
285 #define G_STRFUNC ((const char*) (__FUNCTION__))
286 #else
287 #define G_STRFUNC ((const char*) ("???"))
288 #endif
290 /* Guard C code in headers, while including them from C++ */
291 #ifdef __cplusplus
292 #define G_BEGIN_DECLS extern "C" {
293 #define G_END_DECLS }
294 #else
295 #define G_BEGIN_DECLS
296 #define G_END_DECLS
297 #endif
299 /* Provide definitions for some commonly used macros.
300 * Some of them are only provided if they haven't already
301 * been defined. It is assumed that if they are already
302 * defined then the current definition is correct.
304 #ifndef NULL
305 # ifdef __cplusplus
306 # define NULL (0L)
307 # else /* !__cplusplus */
308 # define NULL ((void*) 0)
309 # endif /* !__cplusplus */
310 #endif
312 #ifndef FALSE
313 #define FALSE (0)
314 #endif
316 #ifndef TRUE
317 #define TRUE (!FALSE)
318 #endif
320 #undef MAX
321 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
323 #undef MIN
324 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
326 #undef ABS
327 #define ABS(a) (((a) < 0) ? -(a) : (a))
329 #undef CLAMP
330 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
332 #define G_APPROX_VALUE(a, b, epsilon) \
333 (((a) > (b) ? (a) - (b) : (b) - (a)) < (epsilon))
335 /* Count the number of elements in an array. The array must be defined
336 * as such; using this with a dynamically allocated array will give
337 * incorrect results.
339 #define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
341 /* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
343 #define GPOINTER_TO_SIZE(p) ((gsize) (p))
344 #define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
346 /* Provide convenience macros for handling structure
347 * fields through their offsets.
350 #if (defined(__GNUC__) && __GNUC__ >= 4) || defined (_MSC_VER)
351 #define G_STRUCT_OFFSET(struct_type, member) \
352 ((glong) offsetof (struct_type, member))
353 #else
354 #define G_STRUCT_OFFSET(struct_type, member) \
355 ((glong) ((guint8*) &((struct_type*) 0)->member))
356 #endif
358 #define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
359 ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
360 #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
361 (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
363 /* Provide simple macro statement wrappers:
364 * G_STMT_START { statements; } G_STMT_END;
365 * This can be used as a single statement, like:
366 * if (x) G_STMT_START { ... } G_STMT_END; else ...
367 * This intentionally does not use compiler extensions like GCC's '({...})' to
368 * avoid portability issue or side effects when compiled with different compilers.
369 * MSVC complains about "while(0)": C4127: "Conditional expression is constant",
370 * so we use __pragma to avoid the warning since the use here is intentional.
372 #if !(defined (G_STMT_START) && defined (G_STMT_END))
373 #define G_STMT_START do
374 #if defined (_MSC_VER) && (_MSC_VER >= 1500)
375 #define G_STMT_END \
376 __pragma(warning(push)) \
377 __pragma(warning(disable:4127)) \
378 while(0) \
379 __pragma(warning(pop))
380 #else
381 #define G_STMT_END while (0)
382 #endif
383 #endif
385 /* Deprecated -- do not use. */
386 #ifndef G_DISABLE_DEPRECATED
387 #ifdef G_DISABLE_CONST_RETURNS
388 #define G_CONST_RETURN
389 #else
390 #define G_CONST_RETURN const
391 #endif
392 #endif
395 * The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
396 * the compiler about the expected result of an expression. Some compilers
397 * can use this information for optimizations.
399 * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
400 * putting assignments in g_return_if_fail ().
402 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
403 #define _G_BOOLEAN_EXPR(expr) \
404 G_GNUC_EXTENSION ({ \
405 int _g_boolean_var_; \
406 if (expr) \
407 _g_boolean_var_ = 1; \
408 else \
409 _g_boolean_var_ = 0; \
410 _g_boolean_var_; \
412 #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR((expr)), 1))
413 #define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR((expr)), 0))
414 #else
415 #define G_LIKELY(expr) (expr)
416 #define G_UNLIKELY(expr) (expr)
417 #endif
419 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
420 #define G_DEPRECATED __attribute__((__deprecated__))
421 #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
422 #define G_DEPRECATED __declspec(deprecated)
423 #else
424 #define G_DEPRECATED
425 #endif
427 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
428 #define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
429 #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
430 #define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))
431 #else
432 #define G_DEPRECATED_FOR(f) G_DEPRECATED
433 #endif
435 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
436 #define G_UNAVAILABLE(maj,min) __attribute__((deprecated("Not available before " #maj "." #min)))
437 #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
438 #define G_UNAVAILABLE(maj,min) __declspec(deprecated("is not available before " #maj "." #min))
439 #else
440 #define G_UNAVAILABLE(maj,min) G_DEPRECATED
441 #endif
443 #ifndef _GLIB_EXTERN
444 #define _GLIB_EXTERN extern
445 #endif
447 /* These macros are used to mark deprecated functions in GLib headers,
448 * and thus have to be exposed in installed headers. But please
449 * do *not* use them in other projects. Instead, use G_DEPRECATED
450 * or define your own wrappers around it.
453 #ifdef GLIB_DISABLE_DEPRECATION_WARNINGS
454 #define GLIB_DEPRECATED _GLIB_EXTERN
455 #define GLIB_DEPRECATED_FOR(f) _GLIB_EXTERN
456 #define GLIB_UNAVAILABLE(maj,min) _GLIB_EXTERN
457 #else
458 #define GLIB_DEPRECATED G_DEPRECATED _GLIB_EXTERN
459 #define GLIB_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _GLIB_EXTERN
460 #define GLIB_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _GLIB_EXTERN
461 #endif
463 #ifndef __GI_SCANNER__
465 #ifdef __GNUC__
467 /* these macros are private */
468 #define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
469 #define _GLIB_AUTOPTR_TYPENAME(TypeName) TypeName##_autoptr
470 #define _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) glib_listautoptr_cleanup_##TypeName
471 #define _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) TypeName##_listautoptr
472 #define _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) glib_slistautoptr_cleanup_##TypeName
473 #define _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) TypeName##_slistautoptr
474 #define _GLIB_AUTO_FUNC_NAME(TypeName) glib_auto_cleanup_##TypeName
475 #define _GLIB_CLEANUP(func) __attribute__((cleanup(func)))
476 #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \
477 typedef ModuleObjName *_GLIB_AUTOPTR_TYPENAME(ModuleObjName); \
478 static inline void _GLIB_AUTOPTR_FUNC_NAME(ModuleObjName) (ModuleObjName **_ptr) { \
479 _GLIB_AUTOPTR_FUNC_NAME(ParentName) ((ParentName **) _ptr); } \
482 /* these macros are API */
483 #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
484 typedef TypeName *_GLIB_AUTOPTR_TYPENAME(TypeName); \
485 typedef GList *_GLIB_AUTOPTR_LIST_TYPENAME(TypeName); \
486 typedef GSList *_GLIB_AUTOPTR_SLIST_TYPENAME(TypeName); \
487 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
488 static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) { if (*_ptr) (func) (*_ptr); } \
489 static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) { g_list_free_full (*_l, (GDestroyNotify) (void(*)(void)) func); } \
490 static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) { g_slist_free_full (*_l, (GDestroyNotify) (void(*)(void)) func); } \
491 G_GNUC_END_IGNORE_DEPRECATIONS
492 #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func) \
493 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
494 static inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { (func) (_ptr); } \
495 G_GNUC_END_IGNORE_DEPRECATIONS
496 #define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none) \
497 G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
498 static inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { if (*_ptr != none) (func) (*_ptr); } \
499 G_GNUC_END_IGNORE_DEPRECATIONS
500 #define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName)
501 #define g_autolist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_LIST_TYPENAME(TypeName)
502 #define g_autoslist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName)
503 #define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName
504 #define g_autofree _GLIB_CLEANUP(g_autoptr_cleanup_generic_gfree)
506 #else /* not GNU C */
507 /* this (dummy) macro is private */
508 #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
510 /* these (dummy) macros are API */
511 #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
512 #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
513 #define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
515 /* no declaration of g_auto() or g_autoptr() here */
516 #endif /* __GNUC__ */
518 #else
520 #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
522 #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
523 #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
524 #define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
526 #endif /* __GI_SCANNER__ */
528 #endif /* __G_MACROS_H__ */