]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/macro.h
Merge pull request #10994 from poettering/sd-bus-tweaks
[thirdparty/systemd.git] / src / basic / macro.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <assert.h>
5 #include <inttypes.h>
6 #include <stdbool.h>
7 #include <sys/param.h>
8 #include <sys/sysmacros.h>
9 #include <sys/types.h>
10
11 #define _printf_(a, b) __attribute__((__format__(printf, a, b)))
12 #ifdef __clang__
13 # define _alloc_(...)
14 #else
15 # define _alloc_(...) __attribute__((__alloc_size__(__VA_ARGS__)))
16 #endif
17 #define _sentinel_ __attribute__((__sentinel__))
18 #define _section_(x) __attribute__((__section__(x)))
19 #define _used_ __attribute__((__used__))
20 #define _unused_ __attribute__((__unused__))
21 #define _destructor_ __attribute__((__destructor__))
22 #define _pure_ __attribute__((__pure__))
23 #define _const_ __attribute__((__const__))
24 #define _deprecated_ __attribute__((__deprecated__))
25 #define _packed_ __attribute__((__packed__))
26 #define _malloc_ __attribute__((__malloc__))
27 #define _weak_ __attribute__((__weak__))
28 #define _likely_(x) (__builtin_expect(!!(x), 1))
29 #define _unlikely_(x) (__builtin_expect(!!(x), 0))
30 #define _public_ __attribute__((__visibility__("default")))
31 #define _hidden_ __attribute__((__visibility__("hidden")))
32 #define _weakref_(x) __attribute__((__weakref__(#x)))
33 #define _align_(x) __attribute__((__aligned__(x)))
34 #define _alignas_(x) __attribute__((__aligned__(__alignof(x))))
35 #define _alignptr_ __attribute__((__aligned__(sizeof(void*))))
36 #define _cleanup_(x) __attribute__((__cleanup__(x)))
37 #if __GNUC__ >= 7
38 #define _fallthrough_ __attribute__((__fallthrough__))
39 #else
40 #define _fallthrough_
41 #endif
42 /* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
43 * compiler versions */
44 #ifndef _noreturn_
45 #if __STDC_VERSION__ >= 201112L
46 #define _noreturn_ _Noreturn
47 #else
48 #define _noreturn_ __attribute__((__noreturn__))
49 #endif
50 #endif
51
52 #if !defined(HAS_FEATURE_MEMORY_SANITIZER)
53 # if defined(__has_feature)
54 # if __has_feature(memory_sanitizer)
55 # define HAS_FEATURE_MEMORY_SANITIZER 1
56 # endif
57 # endif
58 # if !defined(HAS_FEATURE_MEMORY_SANITIZER)
59 # define HAS_FEATURE_MEMORY_SANITIZER 0
60 # endif
61 #endif
62
63 #if !defined(HAS_FEATURE_ADDRESS_SANITIZER)
64 # ifdef __SANITIZE_ADDRESS__
65 # define HAS_FEATURE_ADDRESS_SANITIZER 1
66 # elif defined(__has_feature)
67 # if __has_feature(address_sanitizer)
68 # define HAS_FEATURE_ADDRESS_SANITIZER 1
69 # endif
70 # endif
71 # if !defined(HAS_FEATURE_ADDRESS_SANITIZER)
72 # define HAS_FEATURE_ADDRESS_SANITIZER 0
73 # endif
74 #endif
75
76 /* Note: on GCC "no_sanitize_address" is a function attribute only, on llvm it may also be applied to global
77 * variables. We define a specific macro which knows this. Note that on GCC we don't need this decorator so much, since
78 * our primary usecase for this attribute is registration structures placed in named ELF sections which shall not be
79 * padded, but GCC doesn't pad those anyway if AddressSanitizer is enabled. */
80 #if HAS_FEATURE_ADDRESS_SANITIZER && defined(__clang__)
81 #define _variable_no_sanitize_address_ __attribute__((__no_sanitize_address__))
82 #else
83 #define _variable_no_sanitize_address_
84 #endif
85
86 /* Temporarily disable some warnings */
87 #define DISABLE_WARNING_FORMAT_NONLITERAL \
88 _Pragma("GCC diagnostic push"); \
89 _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
90
91 #define DISABLE_WARNING_MISSING_PROTOTYPES \
92 _Pragma("GCC diagnostic push"); \
93 _Pragma("GCC diagnostic ignored \"-Wmissing-prototypes\"")
94
95 #define DISABLE_WARNING_NONNULL \
96 _Pragma("GCC diagnostic push"); \
97 _Pragma("GCC diagnostic ignored \"-Wnonnull\"")
98
99 #define DISABLE_WARNING_SHADOW \
100 _Pragma("GCC diagnostic push"); \
101 _Pragma("GCC diagnostic ignored \"-Wshadow\"")
102
103 #define DISABLE_WARNING_INCOMPATIBLE_POINTER_TYPES \
104 _Pragma("GCC diagnostic push"); \
105 _Pragma("GCC diagnostic ignored \"-Wincompatible-pointer-types\"")
106
107 #define REENABLE_WARNING \
108 _Pragma("GCC diagnostic pop")
109
110 /* automake test harness */
111 #define EXIT_TEST_SKIP 77
112
113 #define XSTRINGIFY(x) #x
114 #define STRINGIFY(x) XSTRINGIFY(x)
115
116 #define XCONCATENATE(x, y) x ## y
117 #define CONCATENATE(x, y) XCONCATENATE(x, y)
118
119 #define UNIQ_T(x, uniq) CONCATENATE(__unique_prefix_, CONCATENATE(x, uniq))
120 #define UNIQ __COUNTER__
121
122 /* builtins */
123 #if __SIZEOF_INT__ == 4
124 #define BUILTIN_FFS_U32(x) __builtin_ffs(x);
125 #elif __SIZEOF_LONG__ == 4
126 #define BUILTIN_FFS_U32(x) __builtin_ffsl(x);
127 #else
128 #error "neither int nor long are four bytes long?!?"
129 #endif
130
131 /* Rounds up */
132
133 #define ALIGN4(l) (((l) + 3) & ~3)
134 #define ALIGN8(l) (((l) + 7) & ~7)
135
136 #if __SIZEOF_POINTER__ == 8
137 #define ALIGN(l) ALIGN8(l)
138 #elif __SIZEOF_POINTER__ == 4
139 #define ALIGN(l) ALIGN4(l)
140 #else
141 #error "Wut? Pointers are neither 4 nor 8 bytes long?"
142 #endif
143
144 #define ALIGN_PTR(p) ((void*) ALIGN((unsigned long) (p)))
145 #define ALIGN4_PTR(p) ((void*) ALIGN4((unsigned long) (p)))
146 #define ALIGN8_PTR(p) ((void*) ALIGN8((unsigned long) (p)))
147
148 static inline size_t ALIGN_TO(size_t l, size_t ali) {
149 return ((l + ali - 1) & ~(ali - 1));
150 }
151
152 #define ALIGN_TO_PTR(p, ali) ((void*) ALIGN_TO((unsigned long) (p), (ali)))
153
154 /* align to next higher power-of-2 (except for: 0 => 0, overflow => 0) */
155 static inline unsigned long ALIGN_POWER2(unsigned long u) {
156 /* clz(0) is undefined */
157 if (u == 1)
158 return 1;
159
160 /* left-shift overflow is undefined */
161 if (__builtin_clzl(u - 1UL) < 1)
162 return 0;
163
164 return 1UL << (sizeof(u) * 8 - __builtin_clzl(u - 1UL));
165 }
166
167 #ifndef __COVERITY__
168 # define VOID_0 ((void)0)
169 #else
170 # define VOID_0 ((void*)0)
171 #endif
172
173 #define ELEMENTSOF(x) \
174 (__builtin_choose_expr( \
175 !__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \
176 sizeof(x)/sizeof((x)[0]), \
177 VOID_0))
178
179 /*
180 * STRLEN - return the length of a string literal, minus the trailing NUL byte.
181 * Contrary to strlen(), this is a constant expression.
182 * @x: a string literal.
183 */
184 #define STRLEN(x) (sizeof(""x"") - 1)
185
186 /*
187 * container_of - cast a member of a structure out to the containing structure
188 * @ptr: the pointer to the member.
189 * @type: the type of the container struct this is embedded in.
190 * @member: the name of the member within the struct.
191 */
192 #define container_of(ptr, type, member) __container_of(UNIQ, (ptr), type, member)
193 #define __container_of(uniq, ptr, type, member) \
194 ({ \
195 const typeof( ((type*)0)->member ) *UNIQ_T(A, uniq) = (ptr); \
196 (type*)( (char *)UNIQ_T(A, uniq) - offsetof(type, member) ); \
197 })
198
199 #undef MAX
200 #define MAX(a, b) __MAX(UNIQ, (a), UNIQ, (b))
201 #define __MAX(aq, a, bq, b) \
202 ({ \
203 const typeof(a) UNIQ_T(A, aq) = (a); \
204 const typeof(b) UNIQ_T(B, bq) = (b); \
205 UNIQ_T(A, aq) > UNIQ_T(B, bq) ? UNIQ_T(A, aq) : UNIQ_T(B, bq); \
206 })
207
208 /* evaluates to (void) if _A or _B are not constant or of different types */
209 #define CONST_MAX(_A, _B) \
210 (__builtin_choose_expr( \
211 __builtin_constant_p(_A) && \
212 __builtin_constant_p(_B) && \
213 __builtin_types_compatible_p(typeof(_A), typeof(_B)), \
214 ((_A) > (_B)) ? (_A) : (_B), \
215 VOID_0))
216
217 /* takes two types and returns the size of the larger one */
218 #define MAXSIZE(A, B) (sizeof(union _packed_ { typeof(A) a; typeof(B) b; }))
219
220 #define MAX3(x, y, z) \
221 ({ \
222 const typeof(x) _c = MAX(x, y); \
223 MAX(_c, z); \
224 })
225
226 #undef MIN
227 #define MIN(a, b) __MIN(UNIQ, (a), UNIQ, (b))
228 #define __MIN(aq, a, bq, b) \
229 ({ \
230 const typeof(a) UNIQ_T(A, aq) = (a); \
231 const typeof(b) UNIQ_T(B, bq) = (b); \
232 UNIQ_T(A, aq) < UNIQ_T(B, bq) ? UNIQ_T(A, aq) : UNIQ_T(B, bq); \
233 })
234
235 #define MIN3(x, y, z) \
236 ({ \
237 const typeof(x) _c = MIN(x, y); \
238 MIN(_c, z); \
239 })
240
241 #define LESS_BY(a, b) __LESS_BY(UNIQ, (a), UNIQ, (b))
242 #define __LESS_BY(aq, a, bq, b) \
243 ({ \
244 const typeof(a) UNIQ_T(A, aq) = (a); \
245 const typeof(b) UNIQ_T(B, bq) = (b); \
246 UNIQ_T(A, aq) > UNIQ_T(B, bq) ? UNIQ_T(A, aq) - UNIQ_T(B, bq) : 0; \
247 })
248
249 #define CMP(a, b) __CMP(UNIQ, (a), UNIQ, (b))
250 #define __CMP(aq, a, bq, b) \
251 ({ \
252 const typeof(a) UNIQ_T(A, aq) = (a); \
253 const typeof(b) UNIQ_T(B, bq) = (b); \
254 UNIQ_T(A, aq) < UNIQ_T(B, bq) ? -1 : \
255 UNIQ_T(A, aq) > UNIQ_T(B, bq) ? 1 : 0; \
256 })
257
258 #undef CLAMP
259 #define CLAMP(x, low, high) __CLAMP(UNIQ, (x), UNIQ, (low), UNIQ, (high))
260 #define __CLAMP(xq, x, lowq, low, highq, high) \
261 ({ \
262 const typeof(x) UNIQ_T(X, xq) = (x); \
263 const typeof(low) UNIQ_T(LOW, lowq) = (low); \
264 const typeof(high) UNIQ_T(HIGH, highq) = (high); \
265 UNIQ_T(X, xq) > UNIQ_T(HIGH, highq) ? \
266 UNIQ_T(HIGH, highq) : \
267 UNIQ_T(X, xq) < UNIQ_T(LOW, lowq) ? \
268 UNIQ_T(LOW, lowq) : \
269 UNIQ_T(X, xq); \
270 })
271
272 /* [(x + y - 1) / y] suffers from an integer overflow, even though the
273 * computation should be possible in the given type. Therefore, we use
274 * [x / y + !!(x % y)]. Note that on "Real CPUs" a division returns both the
275 * quotient and the remainder, so both should be equally fast. */
276 #define DIV_ROUND_UP(x, y) __DIV_ROUND_UP(UNIQ, (x), UNIQ, (y))
277 #define __DIV_ROUND_UP(xq, x, yq, y) \
278 ({ \
279 const typeof(x) UNIQ_T(X, xq) = (x); \
280 const typeof(y) UNIQ_T(Y, yq) = (y); \
281 (UNIQ_T(X, xq) / UNIQ_T(Y, yq) + !!(UNIQ_T(X, xq) % UNIQ_T(Y, yq))); \
282 })
283
284 #ifdef __COVERITY__
285
286 /* Use special definitions of assertion macros in order to prevent
287 * false positives of ASSERT_SIDE_EFFECT on Coverity static analyzer
288 * for uses of assert_se() and assert_return().
289 *
290 * These definitions make expression go through a (trivial) function
291 * call to ensure they are not discarded. Also use ! or !! to ensure
292 * the boolean expressions are seen as such.
293 *
294 * This technique has been described and recommended in:
295 * https://community.synopsys.com/s/question/0D534000046Yuzb/suppressing-assertsideeffect-for-functions-that-allow-for-sideeffects
296 */
297
298 extern void __coverity_panic__(void);
299
300 static inline int __coverity_check__(int condition) {
301 return condition;
302 }
303
304 #define assert_message_se(expr, message) \
305 do { \
306 if (__coverity_check__(!(expr))) \
307 __coverity_panic__(); \
308 } while (false)
309
310 #define assert_log(expr, message) __coverity_check__(!!(expr))
311
312 #else /* ! __COVERITY__ */
313
314 #define assert_message_se(expr, message) \
315 do { \
316 if (_unlikely_(!(expr))) \
317 log_assert_failed(message, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
318 } while (false)
319
320 #define assert_log(expr, message) ((_likely_(expr)) \
321 ? (true) \
322 : (log_assert_failed_return(message, __FILE__, __LINE__, __PRETTY_FUNCTION__), false))
323
324 #endif /* __COVERITY__ */
325
326 #define assert_se(expr) assert_message_se(expr, #expr)
327
328 /* We override the glibc assert() here. */
329 #undef assert
330 #ifdef NDEBUG
331 #define assert(expr) do {} while (false)
332 #else
333 #define assert(expr) assert_message_se(expr, #expr)
334 #endif
335
336 #define assert_not_reached(t) \
337 do { \
338 log_assert_failed_unreachable(t, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
339 } while (false)
340
341 #if defined(static_assert)
342 #define assert_cc(expr) \
343 static_assert(expr, #expr);
344 #else
345 #define assert_cc(expr) \
346 struct CONCATENATE(_assert_struct_, __COUNTER__) { \
347 char x[(expr) ? 0 : -1]; \
348 };
349 #endif
350
351 #define assert_return(expr, r) \
352 do { \
353 if (!assert_log(expr, #expr)) \
354 return (r); \
355 } while (false)
356
357 #define assert_return_errno(expr, r, err) \
358 do { \
359 if (!assert_log(expr, #expr)) { \
360 errno = err; \
361 return (r); \
362 } \
363 } while (false)
364
365 #define return_with_errno(r, err) \
366 do { \
367 errno = abs(err); \
368 return r; \
369 } while (false)
370
371 #define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
372 #define INT_TO_PTR(u) ((void *) ((intptr_t) (u)))
373 #define PTR_TO_UINT(p) ((unsigned) ((uintptr_t) (p)))
374 #define UINT_TO_PTR(u) ((void *) ((uintptr_t) (u)))
375
376 #define PTR_TO_LONG(p) ((long) ((intptr_t) (p)))
377 #define LONG_TO_PTR(u) ((void *) ((intptr_t) (u)))
378 #define PTR_TO_ULONG(p) ((unsigned long) ((uintptr_t) (p)))
379 #define ULONG_TO_PTR(u) ((void *) ((uintptr_t) (u)))
380
381 #define PTR_TO_INT32(p) ((int32_t) ((intptr_t) (p)))
382 #define INT32_TO_PTR(u) ((void *) ((intptr_t) (u)))
383 #define PTR_TO_UINT32(p) ((uint32_t) ((uintptr_t) (p)))
384 #define UINT32_TO_PTR(u) ((void *) ((uintptr_t) (u)))
385
386 #define PTR_TO_INT64(p) ((int64_t) ((intptr_t) (p)))
387 #define INT64_TO_PTR(u) ((void *) ((intptr_t) (u)))
388 #define PTR_TO_UINT64(p) ((uint64_t) ((uintptr_t) (p)))
389 #define UINT64_TO_PTR(u) ((void *) ((uintptr_t) (u)))
390
391 #define PTR_TO_SIZE(p) ((size_t) ((uintptr_t) (p)))
392 #define SIZE_TO_PTR(u) ((void *) ((uintptr_t) (u)))
393
394 #define CHAR_TO_STR(x) ((char[2]) { x, 0 })
395
396 #define char_array_0(x) x[sizeof(x)-1] = 0;
397
398 /* Returns the number of chars needed to format variables of the
399 * specified type as a decimal string. Adds in extra space for a
400 * negative '-' prefix (hence works correctly on signed
401 * types). Includes space for the trailing NUL. */
402 #define DECIMAL_STR_MAX(type) \
403 (2+(sizeof(type) <= 1 ? 3 : \
404 sizeof(type) <= 2 ? 5 : \
405 sizeof(type) <= 4 ? 10 : \
406 sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)])))
407
408 #define DECIMAL_STR_WIDTH(x) \
409 ({ \
410 typeof(x) _x_ = (x); \
411 unsigned ans = 1; \
412 while ((_x_ /= 10) != 0) \
413 ans++; \
414 ans; \
415 })
416
417 #define SET_FLAG(v, flag, b) \
418 (v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
419 #define FLAGS_SET(v, flags) \
420 ((~(v) & (flags)) == 0)
421
422 #define CASE_F(X) case X:
423 #define CASE_F_1(CASE, X) CASE_F(X)
424 #define CASE_F_2(CASE, X, ...) CASE(X) CASE_F_1(CASE, __VA_ARGS__)
425 #define CASE_F_3(CASE, X, ...) CASE(X) CASE_F_2(CASE, __VA_ARGS__)
426 #define CASE_F_4(CASE, X, ...) CASE(X) CASE_F_3(CASE, __VA_ARGS__)
427 #define CASE_F_5(CASE, X, ...) CASE(X) CASE_F_4(CASE, __VA_ARGS__)
428 #define CASE_F_6(CASE, X, ...) CASE(X) CASE_F_5(CASE, __VA_ARGS__)
429 #define CASE_F_7(CASE, X, ...) CASE(X) CASE_F_6(CASE, __VA_ARGS__)
430 #define CASE_F_8(CASE, X, ...) CASE(X) CASE_F_7(CASE, __VA_ARGS__)
431 #define CASE_F_9(CASE, X, ...) CASE(X) CASE_F_8(CASE, __VA_ARGS__)
432 #define CASE_F_10(CASE, X, ...) CASE(X) CASE_F_9(CASE, __VA_ARGS__)
433 #define CASE_F_11(CASE, X, ...) CASE(X) CASE_F_10(CASE, __VA_ARGS__)
434 #define CASE_F_12(CASE, X, ...) CASE(X) CASE_F_11(CASE, __VA_ARGS__)
435 #define CASE_F_13(CASE, X, ...) CASE(X) CASE_F_12(CASE, __VA_ARGS__)
436 #define CASE_F_14(CASE, X, ...) CASE(X) CASE_F_13(CASE, __VA_ARGS__)
437 #define CASE_F_15(CASE, X, ...) CASE(X) CASE_F_14(CASE, __VA_ARGS__)
438 #define CASE_F_16(CASE, X, ...) CASE(X) CASE_F_15(CASE, __VA_ARGS__)
439 #define CASE_F_17(CASE, X, ...) CASE(X) CASE_F_16(CASE, __VA_ARGS__)
440 #define CASE_F_18(CASE, X, ...) CASE(X) CASE_F_17(CASE, __VA_ARGS__)
441 #define CASE_F_19(CASE, X, ...) CASE(X) CASE_F_18(CASE, __VA_ARGS__)
442 #define CASE_F_20(CASE, X, ...) CASE(X) CASE_F_19(CASE, __VA_ARGS__)
443
444 #define GET_CASE_F(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,NAME,...) NAME
445 #define FOR_EACH_MAKE_CASE(...) \
446 GET_CASE_F(__VA_ARGS__,CASE_F_20,CASE_F_19,CASE_F_18,CASE_F_17,CASE_F_16,CASE_F_15,CASE_F_14,CASE_F_13,CASE_F_12,CASE_F_11, \
447 CASE_F_10,CASE_F_9,CASE_F_8,CASE_F_7,CASE_F_6,CASE_F_5,CASE_F_4,CASE_F_3,CASE_F_2,CASE_F_1) \
448 (CASE_F,__VA_ARGS__)
449
450 #define IN_SET(x, ...) \
451 ({ \
452 bool _found = false; \
453 /* If the build breaks in the line below, you need to extend the case macros. (We use "long double" as \
454 * type for the array, in the hope that checkers such as ubsan don't complain that the initializers for \
455 * the array are not representable by the base type. Ideally we'd use typeof(x) as base type, but that \
456 * doesn't work, as we want to use this on bitfields and gcc refuses typeof() on bitfields.) */ \
457 assert_cc((sizeof((long double[]){__VA_ARGS__})/sizeof(long double)) <= 20); \
458 switch(x) { \
459 FOR_EACH_MAKE_CASE(__VA_ARGS__) \
460 _found = true; \
461 break; \
462 default: \
463 break; \
464 } \
465 _found; \
466 })
467
468 #define SWAP_TWO(x, y) do { \
469 typeof(x) _t = (x); \
470 (x) = (y); \
471 (y) = (_t); \
472 } while (false)
473
474 /* Define C11 thread_local attribute even on older gcc compiler
475 * version */
476 #ifndef thread_local
477 /*
478 * Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
479 * see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53769
480 */
481 #if __STDC_VERSION__ >= 201112L && !(defined(__STDC_NO_THREADS__) || (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
482 #define thread_local _Thread_local
483 #else
484 #define thread_local __thread
485 #endif
486 #endif
487
488 #define DEFINE_TRIVIAL_DESTRUCTOR(name, type, func) \
489 static inline void name(type *p) { \
490 func(p); \
491 }
492
493 #define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
494 static inline void func##p(type *p) { \
495 if (*p) \
496 func(*p); \
497 }
498
499 #define _DEFINE_TRIVIAL_REF_FUNC(type, name, scope) \
500 scope type *name##_ref(type *p) { \
501 if (!p) \
502 return NULL; \
503 \
504 assert(p->n_ref > 0); \
505 p->n_ref++; \
506 return p; \
507 }
508
509 #define _DEFINE_TRIVIAL_UNREF_FUNC(type, name, free_func, scope) \
510 scope type *name##_unref(type *p) { \
511 if (!p) \
512 return NULL; \
513 \
514 assert(p->n_ref > 0); \
515 p->n_ref--; \
516 if (p->n_ref > 0) \
517 return NULL; \
518 \
519 return free_func(p); \
520 }
521
522 #define DEFINE_TRIVIAL_REF_FUNC(type, name) \
523 _DEFINE_TRIVIAL_REF_FUNC(type, name,)
524 #define DEFINE_PRIVATE_TRIVIAL_REF_FUNC(type, name) \
525 _DEFINE_TRIVIAL_REF_FUNC(type, name, static)
526 #define DEFINE_PUBLIC_TRIVIAL_REF_FUNC(type, name) \
527 _DEFINE_TRIVIAL_REF_FUNC(type, name, _public_)
528
529 #define DEFINE_TRIVIAL_UNREF_FUNC(type, name, free_func) \
530 _DEFINE_TRIVIAL_UNREF_FUNC(type, name, free_func,)
531 #define DEFINE_PRIVATE_TRIVIAL_UNREF_FUNC(type, name, free_func) \
532 _DEFINE_TRIVIAL_UNREF_FUNC(type, name, free_func, static)
533 #define DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC(type, name, free_func) \
534 _DEFINE_TRIVIAL_UNREF_FUNC(type, name, free_func, _public_)
535
536 #define DEFINE_TRIVIAL_REF_UNREF_FUNC(type, name, free_func) \
537 DEFINE_TRIVIAL_REF_FUNC(type, name); \
538 DEFINE_TRIVIAL_UNREF_FUNC(type, name, free_func);
539
540 #define DEFINE_PRIVATE_TRIVIAL_REF_UNREF_FUNC(type, name, free_func) \
541 DEFINE_PRIVATE_TRIVIAL_REF_FUNC(type, name); \
542 DEFINE_PRIVATE_TRIVIAL_UNREF_FUNC(type, name, free_func);
543
544 #define DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(type, name, free_func) \
545 DEFINE_PUBLIC_TRIVIAL_REF_FUNC(type, name); \
546 DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC(type, name, free_func);
547
548 #include "log.h"