forked from NetworkManager/NetworkManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnm-std-aux.h
More file actions
1600 lines (1385 loc) · 86.3 KB
/
nm-std-aux.h
File metadata and controls
1600 lines (1385 loc) · 86.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#ifndef __NM_STD_AUX_H__
#define __NM_STD_AUX_H__
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stddef.h>
/*****************************************************************************/
#define _nm_packed __attribute__((__packed__))
#define _nm_unused __attribute__((__unused__))
#define _nm_always_inline __attribute__((__always_inline__))
#define _nm_used __attribute__((__used__))
#define _nm_pure __attribute__((__pure__))
#define _nm_const __attribute__((__const__))
#define _nm_noreturn __attribute__((__noreturn__))
#define _nm_warn_unused_result __attribute__((__warn_unused_result__))
#define _nm_printf(a, b) __attribute__((__format__(__printf__, a, b)))
#define _nm_align(s) __attribute__((__aligned__(s)))
#define _nm_section(s) __attribute__((__section__(s)))
#define _nm_alignof(type) __alignof(type)
#define _nm_alignas(type) _nm_align(_nm_alignof(type))
#define _nm_deprecated(msg) __attribute__((__deprecated__(msg)))
#define _nm_retain
#if defined(__clang__) && defined(__has_attribute)
#if __has_attribute(__retain__)
/* __attribute__((__retain__)) is supported in clang 13+, but is warned about
* as an unknown attribute in older versions. We assume older versions are used
* together with linkers that do not require the attribute.
*
* Ideally __has_attribute(__retain__) would be checked in other compilers as
* well, but it is broken in GCC (bug 99587). Limit it to clang for now, as it
* is only known to be needed for linking lld. */
#undef _nm_retain
#define _nm_retain __attribute__((__retain__))
#endif
#endif
#if defined(__clang__)
/* Clang can emit -Wunused-but-set-variable warning for cleanup variables
* that are only assigned (never used otherwise). Hack around */
#define _nm_auto_extra _nm_unused
#else
#define _nm_auto_extra
#endif
#define nm_auto(fcn) _nm_auto_extra __attribute__((__cleanup__(fcn)))
#define _nm_nil
/* This is required to make LTO working.
*
* See https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/76#note_112694
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48200#c28
*/
#ifndef __clang__
#define _nm_externally_visible __attribute__((__externally_visible__))
#else
#define _nm_externally_visible
#endif
#if __GNUC__ >= 7
#define _nm_fallthrough __attribute__((__fallthrough__))
#else
#define _nm_fallthrough
#endif
/*****************************************************************************/
/* This is mainly used in case of failed assertions. Usually assert() itself
* already ensures that the code path is marked as unreachable, however with
* NDEBUG that might not be the case. We want to mark the code as unreachable
* even with NDEBUG/G_DISABLE_ASSERT. */
#define _nm_unreachable_code() __builtin_unreachable()
/*****************************************************************************/
/* Reason for double application is described here
* https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Stringification.html */
#define NM_STRINGIFY_ARG(contents) #contents
#define NM_STRINGIFY(macro_or_string) NM_STRINGIFY_ARG(macro_or_string)
/*****************************************************************************/
#ifndef _NM_CC_SUPPORT_AUTO_TYPE
#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)))
#define _NM_CC_SUPPORT_AUTO_TYPE 1
#else
#define _NM_CC_SUPPORT_AUTO_TYPE 0
#endif
#endif
#if _NM_CC_SUPPORT_AUTO_TYPE
#define _nm_auto_type __auto_type
#endif
#ifndef _NM_CC_SUPPORT_GENERIC
/* In the meantime, NetworkManager requires C11 and _Generic() should always be available.
* However, shared/nm-utils may also be used in VPN/applet, which possibly did not yet
* bump the C standard requirement. Leave this for the moment, but eventually we can
* drop it.
*
* Technically, gcc 4.9 already has some support for _Generic(). But there seems
* to be issues with propagating "const char *[5]" to "const char **". Only assume
* we have _Generic() since gcc 5. */
#if (defined(__GNUC__) && __GNUC__ >= 5) || (defined(__clang__))
#define _NM_CC_SUPPORT_GENERIC 1
#else
#define _NM_CC_SUPPORT_GENERIC 0
#endif
#endif
/*****************************************************************************/
#ifdef __CHECKER__
#define _nm_bitwise __attribute__((__bitwise__))
#define _nm_force __attribute__((__force__))
#else
#define _nm_bitwise
#define _nm_force
#endif
typedef uint16_t _nm_bitwise nm_le16_t;
typedef uint16_t _nm_bitwise nm_be16_t;
typedef uint32_t _nm_bitwise nm_le32_t;
typedef uint32_t _nm_bitwise nm_be32_t;
typedef uint64_t _nm_bitwise nm_le64_t;
typedef uint64_t _nm_bitwise nm_be64_t;
/*****************************************************************************/
#ifdef thread_local
#define _nm_thread_local thread_local
/*
* Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
* see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53769
*/
#elif __STDC_VERSION__ >= 201112L \
&& !(defined(__STDC_NO_THREADS__) \
|| (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
#define _nm_thread_local _Thread_local
#else
#define _nm_thread_local __thread
#endif
/*****************************************************************************/
#define _NM_DUMMY_STRUCT_FOR_TRAILING_SEMICOLON struct _nm_dummy_struct_for_trailing_semicolon
/*****************************************************************************/
#define NM_BIT(n) (1ull << (n))
/*****************************************************************************/
#define _NM_INT_IS_SIGNED(arg) (!(((typeof(arg)) -1) > 0))
#define _NM_INT_SAME_SIGNEDNESS(arg1, arg2) (_NM_INT_IS_SIGNED(arg1) == _NM_INT_IS_SIGNED(arg2))
/*****************************************************************************/
#define NM_PASTE_ARGS(identifier1, identifier2) identifier1##identifier2
#define NM_PASTE(identifier1, identifier2) NM_PASTE_ARGS(identifier1, identifier2)
/* Taken from systemd's UNIQ_T and UNIQ macros. */
#define NM_UNIQ_T(x, uniq) NM_PASTE(__unique_prefix_, NM_PASTE(x, uniq))
#define NM_UNIQ __COUNTER__
/*****************************************************************************/
/* NM_BOOLEAN_EXPR(expr) exists to ensure that there is still a compiler
* warning when accidentally(?) using assignments like `NM_BOOLEAN_EXPR(x = 1)`
* Compiler will warn about that and suggest either == or additional parentheses
* `NM_BOOLEAN_EXPR((x = 1))`.
*
* This also is true for users of this macro, like `NM_LIKELY(x = 1)` and further
* up `nm_assert(x = 1)`. Those users must make sure not themselves adding additional
* parentheses around the condition.
*/
#define _NM_BOOLEAN_EXPR_IMPL(v, expr) \
({ \
int NM_UNIQ_T(V, v); \
\
if (expr) \
NM_UNIQ_T(V, v) = 1; \
else \
NM_UNIQ_T(V, v) = 0; \
NM_UNIQ_T(V, v); \
})
#if defined(__GNUC__) && (__GNUC__ > 4)
#define NM_BOOLEAN_EXPR(expr) \
__builtin_choose_expr(__builtin_constant_p(expr), \
(!!(expr)), \
_NM_BOOLEAN_EXPR_IMPL(NM_UNIQ, expr))
#else
#define NM_BOOLEAN_EXPR(expr) (!!(expr))
#endif
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define NM_LIKELY(expr) __builtin_expect(NM_BOOLEAN_EXPR(expr), 1)
#define NM_UNLIKELY(expr) __builtin_expect(NM_BOOLEAN_EXPR(expr), 0)
#else
#define NM_LIKELY(expr) NM_BOOLEAN_EXPR(expr)
#define NM_UNLIKELY(expr) NM_BOOLEAN_EXPR(expr)
#endif
/*****************************************************************************/
#if defined(__GNUC__)
#define _NM_PRAGMA_WARNING_DO(warning) NM_STRINGIFY(GCC diagnostic ignored warning)
#elif defined(__clang__)
#define _NM_PRAGMA_WARNING_DO(warning) NM_STRINGIFY(clang diagnostic ignored warning)
#endif
/* you can only suppress a specific warning that the compiler
* understands. Otherwise you will get another compiler warning
* about invalid pragma option.
* It's not that bad however, because gcc and clang often have the
* same name for the same warning. */
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma("GCC diagnostic push")
#define NM_PRAGMA_WARNING_DISABLE(warning) \
NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma(_NM_PRAGMA_WARNING_DO(warning))
#define NM_PRAGMA_WARNING_REENABLE _Pragma("GCC diagnostic pop")
#elif defined(__clang__)
#define NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma("clang diagnostic push")
#define NM_PRAGMA_WARNING_DISABLE(warning) \
NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma(_NM_PRAGMA_WARNING_DO("-Wunknown-warning-option")) \
_Pragma(_NM_PRAGMA_WARNING_DO(warning))
#define NM_PRAGMA_WARNING_REENABLE _Pragma("clang diagnostic pop")
#else
#define NM_PRAGMA_DIAGNOSTICS_PUSH
#define NM_PRAGMA_WARNING_DISABLE(warning)
#define NM_PRAGMA_WARNING_REENABLE
#endif
/*****************************************************************************/
/* Seems gcc-12 has a tendency for false-positive -Wdangling-pointer warnings with
* g_error()'s `for(;;);`. See https://bugzilla.redhat.com/show_bug.cgi?id=2056613 .
* Work around, but only for the affected gcc 12.0.1. */
#if defined(__GNUC__) && __GNUC__ == 12 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ <= 1
#define NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER NM_PRAGMA_WARNING_DISABLE("-Wdangling-pointer")
#else
#define NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER NM_PRAGMA_DIAGNOSTICS_PUSH
#endif
/*****************************************************************************/
/* glib/C provides the following kind of assertions:
* - assert() -- disable with NDEBUG
* - g_return_if_fail() -- disable with G_DISABLE_CHECKS
* - g_assert() -- disable with G_DISABLE_ASSERT
* but they are all enabled by default and usually even production builds have
* these kind of assertions enabled. It also means, that disabling assertions
* is an untested configuration, and might have bugs.
*
* Add our own assertion macro nm_assert(), which is disabled by default and must
* be explicitly enabled. They are useful for more expensive checks or checks that
* depend less on runtime conditions (that is, are generally expected to be true). */
#ifndef NM_MORE_ASSERTS
#define NM_MORE_ASSERTS 0
#endif
#ifndef NDEBUG
#define _NM_ASSERT_FAIL_ENABLED 1
#define _nm_assert_fail(msg) \
__assert_fail(((NM_MORE_ASSERTS) ? "" msg "" : "<dropped>"), \
__FILE__, \
__LINE__, \
((NM_MORE_ASSERTS) ? __func__ : "<unknown-fcn>"))
#else
#define _NM_ASSERT_FAIL_ENABLED 0
#define _nm_assert_fail(msg) ((void) ("" msg ""), _nm_unreachable_code())
#endif
#define NM_MORE_ASSERTS_EFFECTIVE (_NM_ASSERT_FAIL_ENABLED ? NM_MORE_ASSERTS : 0)
#if defined(__GNUC__) && __GNUC__ >= 12
#define _nm_assert_pragma_enter NM_PRAGMA_WARNING_DISABLE("-Wnonnull-compare")
#define _nm_assert_pragma_leave NM_PRAGMA_WARNING_REENABLE
#else
#define _nm_assert_pragma_enter
#define _nm_assert_pragma_leave
#endif
#define nm_assert(cond) \
({ \
_nm_assert_pragma_enter; \
\
/* nm_assert() must do *nothing* of effect, except evaluating
* @cond (0 or 1 times).
*
* As such, nm_assert() is async-signal-safe (provided @cond is, and
* the assertion does not fail). */ \
if (NM_MORE_ASSERTS_EFFECTIVE == 0) { \
if (__builtin_constant_p(cond) && !(cond)) { \
/* Constant expressions are still evaluated and result
* in unreachable code. This handles nm_assert(FALSE). */ \
_nm_unreachable_code(); \
} \
/* pass */ \
} else if (NM_LIKELY(cond)) { \
/* pass */ \
} else { \
_nm_assert_fail(#cond); \
} \
\
_nm_assert_pragma_leave; \
\
1; \
})
#define nm_assert_se(cond) \
({ \
/* nm_assert() must do *nothing* of effect, except evaluating
* @cond (exactly 1 times).
*
* As such, nm_assert() is async-signal-safe (provided @cond is, and
* the assertion does not fail). */ \
if (NM_LIKELY(cond)) { \
/* pass */ \
} else { \
if (NM_MORE_ASSERTS_EFFECTIVE != 0) { \
_nm_assert_fail(#cond); \
} \
_nm_unreachable_code(); \
} \
1; \
})
#define nm_assert_not_reached() \
({ \
_nm_assert_fail("unreachable"); \
1; \
})
/* This is similar nm_assert_not_reached(), but it's supposed to be used only during
* development. Like _XXX_ comments, they can be used as a marker that something still
* needs to be done. */
#define XXX(msg) \
({ \
_nm_assert_fail("X" \
"XX error: " msg ""); \
1; \
})
#define nm_assert_unreachable_val(val) \
({ \
_nm_assert_fail("unreachable value " #val); \
(val); \
})
#define NM_STATIC_ASSERT(cond) static_assert(cond, "")
#define NM_STATIC_ASSERT_EXPR_1(cond) \
(!!sizeof(struct { unsigned __static_assert_expr_1 : ((cond) ? 2 : -1); }))
#define NM_STATIC_ASSERT_EXPR_VOID(cond) ((void) NM_STATIC_ASSERT_EXPR_1(cond))
/*****************************************************************************/
#define NM_N_ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0]))
/*****************************************************************************/
#define nm_offsetof(t, m) offsetof(t, m)
#define nm_offsetofend(t, m) (nm_offsetof(t, m) + sizeof(((t *) NULL)->m))
/*****************************************************************************/
/* This does a compile time check that "type" is a suitable C type. It either
* returns a compile time constant of 1 or it fails compilation. The point
* is only in macros to check that a macro parameter (what we might pass to
* sizeof() is really a type, and not a variable. */
#define NM_ENSURE_IS_TYPE(type) (sizeof(void (*)(type[])) == sizeof(void (*)(void *)))
/*****************************************************************************/
#if _NM_CC_SUPPORT_GENERIC
/* returns @value, if the type of @value matches @type.
* This requires support for C11 _Generic(). If no support is
* present, this returns @value directly.
*
* It's useful to check the let the compiler ensure that @value is
* of a certain type. */
#define _NM_ENSURE_TYPE(type, value) (_Generic((value), type: (value)))
#define _NM_ENSURE_TYPE_CONST(type, value) \
(_Generic((value), const type: ((const type)(value)), type: ((const type)(value))))
#else
#define _NM_ENSURE_TYPE(type, value) (value)
#define _NM_ENSURE_TYPE_CONST(type, value) ((const type)(value))
#endif
/* returns void, but does a compile time check that the argument is a pointer
* (that is, can be converted to (const void *)). It does not actually evaluate
* (value). That means, it's also safe to call _NM_ENSURE_POINTER(array[0]) if
* array might be NULL. It's also safe to call on a macro argument that is
* supposed to be evaluate at most once (this macro will not "execute" the
* argument). */
#define _NM_ENSURE_POINTER(value) \
do { \
_nm_unused const void *const _unused_for_type_check = 0 ? (value) : NULL; \
} while (0)
#if _NM_CC_SUPPORT_GENERIC && (!defined(__clang__) || __clang_major__ > 3)
#define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) \
(_Generic((&(((container *) NULL)->field))[0], type: nm_offsetof(container, field)))
#else
#define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) nm_offsetof(container, field)
#endif
/*****************************************************************************/
static inline uint32_t
nm_add_clamped_u32(uint32_t a, uint32_t b)
{
uint32_t c;
/* returns a+b, or UINT32_MAX if the result would overflow. */
c = a + b;
if (c < a)
return UINT32_MAX;
return c;
}
static inline unsigned
nm_mult_clamped_u(unsigned a, unsigned b)
{
unsigned c;
/* returns a*b, or UINT_MAX if the result would overflow. */
if (b == 0)
return 0;
c = a * b;
if (c / b != a)
return (unsigned) -1;
return c;
}
/* In a few places where a constant expression is required, NM_MIN() doesn't work.
* In that case, use NM_MIN_CONST(). */
#define NM_MIN_CONST(a, b) \
((NM_STATIC_ASSERT_EXPR_1(_NM_INT_SAME_SIGNEDNESS((a), (b)) && __builtin_constant_p((a)) \
&& __builtin_constant_p((b))) \
&& ((a) <= (b))) \
? (a) \
: (b))
#define _NM_MIN_V(aq, a, bq, b) \
({ \
typeof(a) NM_UNIQ_T(A, aq) = (a); \
typeof(b) NM_UNIQ_T(B, bq) = (b); \
\
((NM_UNIQ_T(A, aq) <= NM_UNIQ_T(B, bq)) ? NM_UNIQ_T(A, aq) : NM_UNIQ_T(B, bq)); \
})
#define NM_MIN(a, b) \
__builtin_choose_expr(__builtin_constant_p((a)) && __builtin_constant_p((b)) \
&& NM_STATIC_ASSERT_EXPR_1(_NM_INT_SAME_SIGNEDNESS((a), (b))), \
(((a) <= (b)) ? (a) : (b)), \
_NM_MIN_V(NM_UNIQ, a, NM_UNIQ, b))
#define NM_MAX_CONST(a, b) \
((NM_STATIC_ASSERT_EXPR_1(_NM_INT_SAME_SIGNEDNESS((a), (b)) && __builtin_constant_p((a)) \
&& __builtin_constant_p((b))) \
&& ((a) >= (b))) \
? (a) \
: (b))
#define _NM_MAX_V(aq, a, bq, b) \
({ \
typeof(a) NM_UNIQ_T(A, aq) = (a); \
typeof(b) NM_UNIQ_T(B, bq) = (b); \
\
((NM_UNIQ_T(A, aq) >= NM_UNIQ_T(B, bq)) ? NM_UNIQ_T(A, aq) : NM_UNIQ_T(B, bq)); \
})
#define NM_MAX(a, b) \
__builtin_choose_expr(__builtin_constant_p((a)) && __builtin_constant_p((b)) \
&& NM_STATIC_ASSERT_EXPR_1(_NM_INT_SAME_SIGNEDNESS((a), (b))), \
(((a) >= (b)) ? (a) : (b)), \
_NM_MAX_V(NM_UNIQ, a, NM_UNIQ, b))
#define NM_CLAMP(x, low, high) __NM_CLAMP(NM_UNIQ, x, NM_UNIQ, low, NM_UNIQ, high)
#define __NM_CLAMP(xq, x, lowq, low, highq, high) \
({ \
typeof(x) NM_UNIQ_T(X, xq) = (x); \
typeof(low) NM_UNIQ_T(LOW, lowq) = (low); \
typeof(high) NM_UNIQ_T(HIGH, highq) = (high); \
\
NM_STATIC_ASSERT(_NM_INT_SAME_SIGNEDNESS(NM_UNIQ_T(X, xq), NM_UNIQ_T(LOW, lowq))); \
NM_STATIC_ASSERT(_NM_INT_SAME_SIGNEDNESS(NM_UNIQ_T(X, xq), NM_UNIQ_T(HIGH, highq))); \
\
((NM_UNIQ_T(X, xq) > NM_UNIQ_T(HIGH, highq)) ? NM_UNIQ_T(HIGH, highq) \
: (NM_UNIQ_T(X, xq) < NM_UNIQ_T(LOW, lowq)) ? NM_UNIQ_T(LOW, lowq) \
: NM_UNIQ_T(X, xq)); \
})
#define NM_MAX_WITH_CMP(cmp, a, b) \
({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
\
(((cmp(_a, _b)) >= 0) ? _a : _b); \
})
/* Determine whether @x is a power of two (@x being an integer type).
* Basically, this returns TRUE, if @x has exactly one bit set.
* For negative values and zero, this always returns FALSE. */
#define nm_utils_is_power_of_two(x) \
({ \
typeof(x) _x2 = (x); \
const typeof(_x2) _X_0 = ((typeof(_x2)) 0); \
const typeof(_x2) _X_1 = ((typeof(_x2)) 1); \
\
((_x2 > _X_0) && ((_x2 & (_x2 - _X_1)) == _X_0)); \
})
#define nm_utils_is_power_of_two_or_zero(x) \
({ \
typeof(x) _x1 = (x); \
\
((_x1 == 0) || nm_utils_is_power_of_two(_x1)); \
})
/*****************************************************************************/
static inline size_t
NM_ALIGN_TO(size_t l, size_t ali)
{
nm_assert(nm_utils_is_power_of_two(ali));
if (l > SIZE_MAX - (ali - 1))
return SIZE_MAX; /* indicate overflow */
return ((l + ali - 1) & ~(ali - 1));
}
#define NM_ALIGN4(l) NM_ALIGN_TO(l, 4)
#define NM_ALIGN8(l) NM_ALIGN_TO(l, 8)
#define NM_ALIGN(l) NM_ALIGN_TO(l, sizeof(void *))
#define NM_ALIGN_PTR(p) ((void *) NM_ALIGN((uintptr_t) (p)))
/*****************************************************************************/
#define NM_SWAP(p_a, p_b) \
do { \
typeof(*(p_a)) *const _p_a = (p_a); \
typeof(*(p_a)) *const _p_b = (p_b); \
typeof(*(p_a)) _tmp; \
\
_tmp = *_p_a; \
*_p_a = *_p_b; \
*_p_b = _tmp; \
} while (0)
/*****************************************************************************/
/* macro to return strlen() of a compile time string. */
#define NM_STRLEN(str) (sizeof("" str "") - 1u)
static inline size_t
_nm_ptrarray_len_impl(const void *const *array)
{
size_t n = 0;
if (array) {
while (array[n])
n++;
}
return n;
}
/* returns the length of a NULL terminated array of pointers,
* like g_strv_length() does. The difference is:
* - it operates on arrays of pointers (of any kind, requiring no cast).
* - it accepts NULL to return zero. */
#define NM_PTRARRAY_LEN(array) \
({ \
_NM_ENSURE_POINTER((array)[0]); \
_nm_ptrarray_len_impl((const void *const *) (array)); \
})
/*****************************************************************************/
static inline int
nm_strcmp0(const char *s1, const char *s2)
{
int c;
/* like g_strcmp0(), but this is inlinable.
*
* Also, it is guaranteed to return either -1, 0, or 1. */
if (s1 == s2)
return 0;
if (!s1)
return -1;
if (!s2)
return 1;
c = strcmp(s1, s2);
if (c < 0)
return -1;
if (c > 0)
return 1;
return 0;
}
static inline int
nm_streq(const char *s1, const char *s2)
{
return strcmp(s1, s2) == 0;
}
static inline int
nm_streq0(const char *s1, const char *s2)
{
return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0);
}
static inline int
nm_memcmp(const void *s1, const void *s2, size_t n)
{
/* Workaround undefined behavior in memcmp() with NULL pointers. */
if (n == 0)
return 0;
nm_assert(s1);
nm_assert(s2);
return memcmp(s1, s2, n);
}
static inline bool
nm_memeq(const void *s1, const void *s2, size_t len)
{
return nm_memcmp(s1, s2, len) == 0;
}
static inline void *
nm_memcpy(void *restrict dest, const void *restrict src, size_t n)
{
/* Workaround undefined behavior in memcpy() with NULL pointers. */
if (n == 0)
return dest;
nm_assert(src);
return memcpy(dest, src, n);
}
/*
* Very similar to g_str_has_prefix() with the obvious meaning.
* Differences:
* 1) prefix is enforced to be a C string literal
* (it is thus more restricted, but you'll know it at compile time).
* 2) it accepts str==NULL
* (it is thus more forgiving than g_str_has_prefix())
* 3) it can get the job done with one strncmp() (with
* the length argument being a compile time constant, and compiler optimizing
* strncmp() call).
* Compare to g_str_has_prefix() which requires one call into glib, then
* one strlen() and one strncmp() call.
*
* If it compiles (re:1), NM_STR_HAS_PREFIX() can fully replace g_str_has_prefix().
* The other way is not necessarily possible due to 2).
*/
#define NM_STR_HAS_PREFIX(str, prefix) \
({ \
const char *const _str_has_prefix = (str); \
\
nm_assert(strlen(prefix) == NM_STRLEN(prefix)); \
\
_str_has_prefix && (strncmp(_str_has_prefix, "" prefix "", NM_STRLEN(prefix)) == 0); \
})
/*
* Very similar to g_str_has_suffix() with the obvious meaning.
* Differences:
* 1) suffix is enforced to be a C string literal
* (it is thus more restricted, but you'll know it at compile time).
* 2) it accepts str==NULL
* (it is thus more forgiving than g_str_has_suffix())
* 3) it can get the job done with one strlen() and one memcpy() call (with
* the length argument being a compile time constant, and compiler optimizing
* memcpy() call).
* Compare to g_str_has_suffix() which requires one call into glib, then
* two strlen() and one strcmp() call.
*
* If it compiles (re:1), NM_STR_HAS_SUFFIX() can fully replace g_str_has_suffix().
* The other way is not necessarily possible due to 2).
*/
#define NM_STR_HAS_SUFFIX(str, suffix) \
({ \
const char *const _str_has_suffix = (str); \
size_t _l; \
\
nm_assert(strlen(suffix) == NM_STRLEN(suffix)); \
\
(_str_has_suffix && ((_l = strlen(_str_has_suffix)) >= NM_STRLEN(suffix)) \
&& (memcmp(&_str_has_suffix[_l - NM_STRLEN(suffix)], "" suffix "", NM_STRLEN(suffix)) \
== 0)); \
})
/* whether @str starts with the string literal @prefix and is followed by
* some other text. It is like NM_STR_HAS_PREFIX() && !nm_streq() together. */
#define NM_STR_HAS_PREFIX_WITH_MORE(str, prefix) \
({ \
const char *const _str_has_prefix_with_more = (str); \
\
NM_STR_HAS_PREFIX(_str_has_prefix_with_more, "" prefix "") \
&&_str_has_prefix_with_more[NM_STRLEN(prefix)] != '\0'; \
})
#define NM_STR_HAS_SUFFIX_WITH_MORE(str, suffix) \
({ \
const char *const _str_has_suffix = (str); \
size_t _l; \
\
nm_assert(strlen(suffix) == NM_STRLEN(suffix)); \
\
(_str_has_suffix && ((_l = strlen(_str_has_suffix)) > NM_STRLEN(suffix)) \
&& (memcmp(&_str_has_suffix[_l - NM_STRLEN(suffix)], "" suffix "", NM_STRLEN(suffix)) \
== 0)); \
})
/*****************************************************************************/
/* clang-format off */
#define _NM_MACRO_SELECT_ARG_120(_empty, \
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
_61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \
_71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \
_81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \
_91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \
_101, _102, _103, _104, _105, _106, _107, _108, _109, _110, \
_111, _112, _113, _114, _115, _116, _117, _118, _119, _120, \
N, \
...) \
N
#define NM_NARG(...) \
_NM_MACRO_SELECT_ARG_120(, ##__VA_ARGS__, \
120, \
119, 118, 117, 116, 115, 114, 113, 112, 111, 110, \
109, 108, 107, 106, 105, 104, 103, 102, 101, 100, \
99, 98, 97, 96, 95, 94, 93, 92, 91, 90, \
89, 88, 87, 86, 85, 84, 83, 82, 81, 80, \
79, 78, 77, 76, 75, 74, 73, 72, 71, 70, \
69, 68, 67, 66, 65, 64, 63, 62, 61, 60, \
59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define NM_NARG_MAX1(...) \
_NM_MACRO_SELECT_ARG_120(, ##__VA_ARGS__, \
1, \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 110 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 100 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 90 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 70 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10 */ \
1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
#define NM_NARG_MAX2(...) \
_NM_MACRO_SELECT_ARG_120(, ##__VA_ARGS__, \
2, \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 110 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 100 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 90 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 80 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 70 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 60 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 50 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 40 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 30 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 20 */ \
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 10 */ \
2, 2, 2, 2, 2, 2, 2, 2, 1, 0)
/* clang-format on */
/*****************************************************************************/
#define _NM_MACRO_IDENTITY(...) __VA_ARGS__
#define _NM_MACRO_SELECT_FIRST(...) _NM_MACRO_SELECT_FIRST_IMPL(__VA_ARGS__, throwaway)
#define _NM_MACRO_SELECT_FIRST_IMPL(first, ...) first
#define _NM_MACRO_CALL(macro, ...) macro(__VA_ARGS__)
#define _NM_MACRO_CALL2(macro, ...) macro(__VA_ARGS__)
/*****************************************************************************/
/* clang-format off */
#define _NM_VA_ARGS_FOREACH_0( prefix, postfix, sep, op, op_arg)
#define _NM_VA_ARGS_FOREACH_1( prefix, postfix, sep, op, op_arg, x) prefix _NM_MACRO_CALL2(op, x, 0, op_arg) postfix
#define _NM_VA_ARGS_FOREACH_2( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 1, op_arg) postfix sep _NM_VA_ARGS_FOREACH_1( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_3( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 2, op_arg) postfix sep _NM_VA_ARGS_FOREACH_2( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_4( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 3, op_arg) postfix sep _NM_VA_ARGS_FOREACH_3( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_5( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 4, op_arg) postfix sep _NM_VA_ARGS_FOREACH_4( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_6( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 5, op_arg) postfix sep _NM_VA_ARGS_FOREACH_5( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_7( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 6, op_arg) postfix sep _NM_VA_ARGS_FOREACH_6( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_8( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 7, op_arg) postfix sep _NM_VA_ARGS_FOREACH_7( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_9( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 8, op_arg) postfix sep _NM_VA_ARGS_FOREACH_8( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_10( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 9, op_arg) postfix sep _NM_VA_ARGS_FOREACH_9( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_11( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 10, op_arg) postfix sep _NM_VA_ARGS_FOREACH_10( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_12( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 11, op_arg) postfix sep _NM_VA_ARGS_FOREACH_11( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_13( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 12, op_arg) postfix sep _NM_VA_ARGS_FOREACH_12( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_14( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 13, op_arg) postfix sep _NM_VA_ARGS_FOREACH_13( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_15( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 14, op_arg) postfix sep _NM_VA_ARGS_FOREACH_14( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_16( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 15, op_arg) postfix sep _NM_VA_ARGS_FOREACH_15( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_17( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 16, op_arg) postfix sep _NM_VA_ARGS_FOREACH_16( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_18( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 17, op_arg) postfix sep _NM_VA_ARGS_FOREACH_17( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_19( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 18, op_arg) postfix sep _NM_VA_ARGS_FOREACH_18( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_20( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 19, op_arg) postfix sep _NM_VA_ARGS_FOREACH_19( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_21( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 20, op_arg) postfix sep _NM_VA_ARGS_FOREACH_20( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_22( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 21, op_arg) postfix sep _NM_VA_ARGS_FOREACH_21( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_23( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 22, op_arg) postfix sep _NM_VA_ARGS_FOREACH_22( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_24( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 23, op_arg) postfix sep _NM_VA_ARGS_FOREACH_23( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_25( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 24, op_arg) postfix sep _NM_VA_ARGS_FOREACH_24( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_26( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 25, op_arg) postfix sep _NM_VA_ARGS_FOREACH_25( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_27( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 26, op_arg) postfix sep _NM_VA_ARGS_FOREACH_26( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_28( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 27, op_arg) postfix sep _NM_VA_ARGS_FOREACH_27( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_29( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 28, op_arg) postfix sep _NM_VA_ARGS_FOREACH_28( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_30( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 29, op_arg) postfix sep _NM_VA_ARGS_FOREACH_29( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_31( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 30, op_arg) postfix sep _NM_VA_ARGS_FOREACH_30( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_32( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 31, op_arg) postfix sep _NM_VA_ARGS_FOREACH_31( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_33( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 32, op_arg) postfix sep _NM_VA_ARGS_FOREACH_32( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_34( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 33, op_arg) postfix sep _NM_VA_ARGS_FOREACH_33( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_35( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 34, op_arg) postfix sep _NM_VA_ARGS_FOREACH_34( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_36( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 35, op_arg) postfix sep _NM_VA_ARGS_FOREACH_35( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_37( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 36, op_arg) postfix sep _NM_VA_ARGS_FOREACH_36( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_38( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 37, op_arg) postfix sep _NM_VA_ARGS_FOREACH_37( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_39( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 38, op_arg) postfix sep _NM_VA_ARGS_FOREACH_38( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_40( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 39, op_arg) postfix sep _NM_VA_ARGS_FOREACH_39( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_41( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 40, op_arg) postfix sep _NM_VA_ARGS_FOREACH_40( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_42( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 41, op_arg) postfix sep _NM_VA_ARGS_FOREACH_41( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_43( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 42, op_arg) postfix sep _NM_VA_ARGS_FOREACH_42( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_44( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 43, op_arg) postfix sep _NM_VA_ARGS_FOREACH_43( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_45( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 44, op_arg) postfix sep _NM_VA_ARGS_FOREACH_44( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_46( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 45, op_arg) postfix sep _NM_VA_ARGS_FOREACH_45( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_47( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 46, op_arg) postfix sep _NM_VA_ARGS_FOREACH_46( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_48( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 47, op_arg) postfix sep _NM_VA_ARGS_FOREACH_47( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_49( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 48, op_arg) postfix sep _NM_VA_ARGS_FOREACH_48( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_50( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 49, op_arg) postfix sep _NM_VA_ARGS_FOREACH_49( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_51( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 50, op_arg) postfix sep _NM_VA_ARGS_FOREACH_50( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_52( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 51, op_arg) postfix sep _NM_VA_ARGS_FOREACH_51( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_53( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 52, op_arg) postfix sep _NM_VA_ARGS_FOREACH_52( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_54( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 53, op_arg) postfix sep _NM_VA_ARGS_FOREACH_53( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_55( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 54, op_arg) postfix sep _NM_VA_ARGS_FOREACH_54( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_56( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 55, op_arg) postfix sep _NM_VA_ARGS_FOREACH_55( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_57( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 56, op_arg) postfix sep _NM_VA_ARGS_FOREACH_56( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_58( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 57, op_arg) postfix sep _NM_VA_ARGS_FOREACH_57( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_59( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 58, op_arg) postfix sep _NM_VA_ARGS_FOREACH_58( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_60( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 59, op_arg) postfix sep _NM_VA_ARGS_FOREACH_59( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_61( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 10, op_arg) postfix sep _NM_VA_ARGS_FOREACH_60( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_62( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 61, op_arg) postfix sep _NM_VA_ARGS_FOREACH_61( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_63( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 62, op_arg) postfix sep _NM_VA_ARGS_FOREACH_62( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_64( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 63, op_arg) postfix sep _NM_VA_ARGS_FOREACH_63( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_65( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 64, op_arg) postfix sep _NM_VA_ARGS_FOREACH_64( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_66( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 65, op_arg) postfix sep _NM_VA_ARGS_FOREACH_65( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_67( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 66, op_arg) postfix sep _NM_VA_ARGS_FOREACH_66( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_68( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 67, op_arg) postfix sep _NM_VA_ARGS_FOREACH_67( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_69( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 68, op_arg) postfix sep _NM_VA_ARGS_FOREACH_68( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_70( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 69, op_arg) postfix sep _NM_VA_ARGS_FOREACH_69( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_71( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 70, op_arg) postfix sep _NM_VA_ARGS_FOREACH_70( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_72( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 71, op_arg) postfix sep _NM_VA_ARGS_FOREACH_71( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_73( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 72, op_arg) postfix sep _NM_VA_ARGS_FOREACH_72( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_74( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 73, op_arg) postfix sep _NM_VA_ARGS_FOREACH_73( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_75( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 74, op_arg) postfix sep _NM_VA_ARGS_FOREACH_74( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_76( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 75, op_arg) postfix sep _NM_VA_ARGS_FOREACH_75( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_77( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 76, op_arg) postfix sep _NM_VA_ARGS_FOREACH_76( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_78( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 77, op_arg) postfix sep _NM_VA_ARGS_FOREACH_77( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_79( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 78, op_arg) postfix sep _NM_VA_ARGS_FOREACH_78( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_80( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 79, op_arg) postfix sep _NM_VA_ARGS_FOREACH_79( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_81( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 80, op_arg) postfix sep _NM_VA_ARGS_FOREACH_80( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_82( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 81, op_arg) postfix sep _NM_VA_ARGS_FOREACH_81( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_83( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 82, op_arg) postfix sep _NM_VA_ARGS_FOREACH_82( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_84( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 83, op_arg) postfix sep _NM_VA_ARGS_FOREACH_83( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_85( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 84, op_arg) postfix sep _NM_VA_ARGS_FOREACH_84( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_86( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 85, op_arg) postfix sep _NM_VA_ARGS_FOREACH_85( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_87( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 86, op_arg) postfix sep _NM_VA_ARGS_FOREACH_86( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_88( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 87, op_arg) postfix sep _NM_VA_ARGS_FOREACH_87( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_89( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 88, op_arg) postfix sep _NM_VA_ARGS_FOREACH_88( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_90( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 89, op_arg) postfix sep _NM_VA_ARGS_FOREACH_89( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_91( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 90, op_arg) postfix sep _NM_VA_ARGS_FOREACH_90( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_92( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 91, op_arg) postfix sep _NM_VA_ARGS_FOREACH_91( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_93( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 92, op_arg) postfix sep _NM_VA_ARGS_FOREACH_92( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_94( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 93, op_arg) postfix sep _NM_VA_ARGS_FOREACH_93( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_95( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 94, op_arg) postfix sep _NM_VA_ARGS_FOREACH_94( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_96( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 95, op_arg) postfix sep _NM_VA_ARGS_FOREACH_95( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_97( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 96, op_arg) postfix sep _NM_VA_ARGS_FOREACH_96( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_98( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 97, op_arg) postfix sep _NM_VA_ARGS_FOREACH_97( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_99( prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 98, op_arg) postfix sep _NM_VA_ARGS_FOREACH_98( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_100(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 99, op_arg) postfix sep _NM_VA_ARGS_FOREACH_99( prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_101(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 100, op_arg) postfix sep _NM_VA_ARGS_FOREACH_100(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_102(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 101, op_arg) postfix sep _NM_VA_ARGS_FOREACH_101(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_103(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 102, op_arg) postfix sep _NM_VA_ARGS_FOREACH_102(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_104(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 103, op_arg) postfix sep _NM_VA_ARGS_FOREACH_103(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_105(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 104, op_arg) postfix sep _NM_VA_ARGS_FOREACH_104(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_106(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 105, op_arg) postfix sep _NM_VA_ARGS_FOREACH_105(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_107(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 106, op_arg) postfix sep _NM_VA_ARGS_FOREACH_106(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_108(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 107, op_arg) postfix sep _NM_VA_ARGS_FOREACH_107(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_109(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 108, op_arg) postfix sep _NM_VA_ARGS_FOREACH_108(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_110(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 109, op_arg) postfix sep _NM_VA_ARGS_FOREACH_109(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_111(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 100, op_arg) postfix sep _NM_VA_ARGS_FOREACH_110(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_112(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 111, op_arg) postfix sep _NM_VA_ARGS_FOREACH_111(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_113(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 112, op_arg) postfix sep _NM_VA_ARGS_FOREACH_112(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_114(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 113, op_arg) postfix sep _NM_VA_ARGS_FOREACH_113(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_115(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 114, op_arg) postfix sep _NM_VA_ARGS_FOREACH_114(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_116(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 115, op_arg) postfix sep _NM_VA_ARGS_FOREACH_115(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_117(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 116, op_arg) postfix sep _NM_VA_ARGS_FOREACH_116(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_118(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 117, op_arg) postfix sep _NM_VA_ARGS_FOREACH_117(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_119(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 118, op_arg) postfix sep _NM_VA_ARGS_FOREACH_118(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
#define _NM_VA_ARGS_FOREACH_120(prefix, postfix, sep, op, op_arg, x, ...) prefix _NM_MACRO_CALL2(op, x, 119, op_arg) postfix sep _NM_VA_ARGS_FOREACH_119(prefix, postfix, sep, op, op_arg, __VA_ARGS__)
/* clang-format on */
#define NM_VA_ARGS_FOREACH(prefix, postfix, sep, op, op_arg, ...) \
_NM_MACRO_CALL(NM_PASTE(_NM_VA_ARGS_FOREACH_, NM_NARG(__VA_ARGS__)), \
prefix, \
postfix, \
sep, \
op, \
op_arg, \
##__VA_ARGS__)
/*****************************************************************************/
#define NM_VA_ARGS_JOIN(sep, ...) NM_VA_ARGS_FOREACH(, , sep, _NM_MACRO_SELECT_FIRST, , __VA_ARGS__)
/*****************************************************************************/
#define _NM_IN_SET_OP(x, idx, uniq) ((int) (NM_UNIQ_T(xx, uniq) == (x)))
#define _NM_IN_SET(uniq, op, type, x, ...) \
({ \
type NM_UNIQ_T(xx, uniq) = (x); \
\
/* trigger a -Wenum-compare warning */ \
nm_assert(true || NM_UNIQ_T(xx, uniq) == (x)); \
\
!!(NM_VA_ARGS_FOREACH(, , op, _NM_IN_SET_OP, uniq, __VA_ARGS__)); \
})
/* Beware that this does short-circuit evaluation (use "||" instead of "|")
* which has a possibly unexpected non-function-like behavior.
* Use NM_IN_SET_SE if you need all arguments to be evaluated. */
#define NM_IN_SET(x, ...) _NM_IN_SET(NM_UNIQ, ||, typeof(x), x, __VA_ARGS__)
/* "SE" stands for "side-effect". Contrary to NM_IN_SET(), this does not do
* short-circuit evaluation, which can make a difference if the arguments have
* side-effects. */
#define NM_IN_SET_SE(x, ...) _NM_IN_SET(NM_UNIQ, |, typeof(x), x, __VA_ARGS__)
/* the *_TYPED forms allow one to explicitly select the type of "x". This is useful
* if "x" doesn't support typeof (bitfields) or you want to gracefully convert
* a type using automatic type conversion rules (but not forcing the conversion
* with a cast). */
#define NM_IN_SET_TYPED(type, x, ...) _NM_IN_SET(NM_UNIQ, ||, type, x, __VA_ARGS__)
#define NM_IN_SET_SE_TYPED(type, x, ...) _NM_IN_SET(NM_UNIQ, |, type, x, __VA_ARGS__)
/*****************************************************************************/
static inline int
_NM_IN_STRSET_EVAL_op_streq(const char *x1, const char *x)
{
return x && nm_streq(x1, x);
}
#define _NM_IN_STRSET_EVAL_OP_NULL(x, idx, op_arg) ((int) (((const char *) NULL) == (x)))
#define _NM_IN_STRSET_EVAL_OP_STREQ(x, idx, op_arg) _NM_IN_STRSET_EVAL_op_streq(_x1, x)
#define _NM_IN_STRSET_EVAL(op, eval_op, x1, ...) \
({ \
const char *const _x1 = (x1); \
\
!!(_x1 ? (NM_VA_ARGS_FOREACH(, , op, eval_op, , __VA_ARGS__)) \
: (NM_VA_ARGS_FOREACH(, , op, _NM_IN_STRSET_EVAL_OP_NULL, , __VA_ARGS__))); \