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