Zephyr API Documentation
4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
cbprintf_internal.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Nordic Semiconductor ASA
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef ZEPHYR_INCLUDE_SYS_CBPRINTF_INTERNAL_H_
8
#define ZEPHYR_INCLUDE_SYS_CBPRINTF_INTERNAL_H_
9
10
#include <
errno.h
>
11
#include <stdarg.h>
12
#include <stddef.h>
13
#include <
stdint.h
>
14
#include <
zephyr/toolchain.h
>
15
#include <
zephyr/sys/util.h
>
16
#include <
zephyr/sys/__assert.h
>
17
#include <
zephyr/arch/cpu.h
>
18
19
/*
20
* Special alignment cases
21
*/
22
23
#if defined(__i386__)
24
/* there are no gaps on the stack */
25
#define VA_STACK_ALIGN(type) 1
26
#elif defined(__sparc__)
27
/* there are no gaps on the stack */
28
#define VA_STACK_ALIGN(type) 1
29
#elif defined(__x86_64__)
30
#define VA_STACK_MIN_ALIGN 8
31
#elif defined(__aarch64__)
32
#define VA_STACK_MIN_ALIGN 8
33
#elif defined(CONFIG_ARC)
34
#define VA_STACK_MIN_ALIGN ARCH_STACK_PTR_ALIGN
35
#elif defined(__riscv)
36
#if defined(CONFIG_RISCV_ISA_RV32E)
37
#if !defined(CONFIG_CBPRINTF_RV32E_USE_DEFAULT_ALIGNMENT)
38
#define VA_STACK_ALIGN(type) 4
39
#endif
40
#else
41
#define VA_STACK_MIN_ALIGN (__riscv_xlen / 8)
42
#endif
/* CONFIG_RISCV_ISA_RV32E */
43
#endif
44
45
/*
46
* Default alignment values if not specified by architecture config
47
*/
48
49
#ifndef VA_STACK_MIN_ALIGN
50
#define VA_STACK_MIN_ALIGN 1
51
#endif
52
53
#ifndef VA_STACK_ALIGN
54
#define VA_STACK_ALIGN(type) MAX(VA_STACK_MIN_ALIGN, __alignof__(type))
55
#endif
56
57
static
inline
void
z_cbprintf_wcpy(
int
*dst,
int
*src,
size_t
len)
58
{
59
for
(
size_t
i = 0; i < len; i++) {
60
dst[i] = src[i];
61
}
62
}
63
64
#include <
zephyr/sys/cbprintf_cxx.h
>
65
66
#ifdef __cplusplus
67
extern
"C"
{
68
#endif
69
70
71
#if defined(__sparc__)
72
/* The SPARC V8 ABI guarantees that the arguments of a variable argument
73
* list function are stored on the stack at addresses which are 32-bit
74
* aligned. It means that variables of type unit64_t and double may not
75
* be properly aligned on the stack.
76
*
77
* The compiler is aware of the ABI and takes care of this. However,
78
* as we are directly accessing the variable argument list here, we need
79
* to take the alignment into consideration and copy 64-bit arguments
80
* as 32-bit words.
81
*/
82
#define Z_CBPRINTF_VA_STACK_LL_DBL_MEMCPY 1
83
#else
84
#define Z_CBPRINTF_VA_STACK_LL_DBL_MEMCPY 0
85
#endif
86
91
#define Z_ARGIFY(arg) ((0) ? 0 : (arg))
92
99
#ifdef __cplusplus
100
#define Z_CBPRINTF_IS_PCHAR(x, flags) \
101
z_cbprintf_cxx_is_pchar(x, (flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO)
102
#else
103
/* NOLINTBEGIN(misc-redundant-expression) */
104
#define Z_CBPRINTF_IS_PCHAR(x, flags) \
105
_Generic(Z_ARGIFY(x), \
106
/* char * */
\
107
char * : 1, \
108
const char * : ((flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO) ? 0 : 1, \
109
volatile char * : 1, \
110
const volatile char * : 1, \
111
/* unsigned char * */
\
112
unsigned char * : 1, \
113
const unsigned char * : ((flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO) ? 0 : 1, \
114
volatile unsigned char * : 1, \
115
const volatile unsigned char * : 1,\
116
/* wchar_t * */
\
117
wchar_t * : 1, \
118
const wchar_t * : ((flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO) ? 0 : 1, \
119
volatile wchar_t * : 1, \
120
const volatile wchar_t * : 1, \
121
default : \
122
0)
123
/* NOLINTEND(misc-redundant-expression) */
124
#endif
125
133
#ifdef __cplusplus
134
#define Z_CBPRINTF_IS_WORD_NUM(x) \
135
z_cbprintf_cxx_is_word_num(x)
136
#else
137
#define Z_CBPRINTF_IS_WORD_NUM(x) \
138
_Generic(x, \
139
char : 1, \
140
unsigned char : 1, \
141
short : 1, \
142
unsigned short : 1, \
143
int : 1, \
144
unsigned int : 1, \
145
long : sizeof(long) <= 4, \
146
unsigned long : sizeof(long) <= 4, \
147
default : \
148
0)
149
#endif
150
161
#ifdef __cplusplus
162
#define Z_CBPRINTF_IS_NONE_CHAR_PTR(x) z_cbprintf_cxx_is_none_char_ptr(x)
163
#else
164
#define Z_CBPRINTF_IS_NONE_CHAR_PTR(x) \
165
_Generic(Z_ARGIFY(x), \
166
char * : 0, \
167
volatile char * : 0, \
168
const char * : 0, \
169
const volatile char * : 0, \
170
unsigned char * : 0, \
171
volatile unsigned char * : 0, \
172
const unsigned char * : 0, \
173
const volatile unsigned char * : 0, \
174
char: 0, \
175
unsigned char: 0, \
176
short: 0, \
177
unsigned short: 0, \
178
int: 0, \
179
unsigned int: 0,\
180
long: 0, \
181
unsigned long: 0,\
182
long long: 0, \
183
unsigned long long: 0, \
184
float: 0, \
185
double: 0, \
186
default : \
187
1)
188
#endif
189
196
#define Z_CBPRINTF_NONE_CHAR_PTR_ARGS(...) \
197
(FOR_EACH(Z_CBPRINTF_IS_NONE_CHAR_PTR, (+), __VA_ARGS__)) \
198
205
#define Z_CBPRINTF_NONE_CHAR_PTR_COUNT(...) \
206
COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), \
207
(0), \
208
(Z_CBPRINTF_NONE_CHAR_PTR_ARGS(GET_ARGS_LESS_N(1, __VA_ARGS__))))
209
223
#define Z_CBPRINTF_P_COUNT(fmt, ...) \
224
((sizeof(fmt) >= 2 && fmt[0] == '%' && fmt[1] == 'p') ? 1 : 0) + \
225
((sizeof(fmt) >= 3 && fmt[0] != '%' && fmt[1] == '%' && fmt[2] == 'p') ? 1 : 0) + \
226
((sizeof(fmt) >= 4 && fmt[1] != '%' && fmt[2] == '%' && fmt[3] == 'p') ? 1 : 0) + \
227
((sizeof(fmt) >= 5 && fmt[2] != '%' && fmt[3] == '%' && fmt[4] == 'p') ? 1 : 0) + \
228
((sizeof(fmt) >= 6 && fmt[3] != '%' && fmt[4] == '%' && fmt[5] == 'p') ? 1 : 0) + \
229
((sizeof(fmt) >= 7 && fmt[4] != '%' && fmt[5] == '%' && fmt[6] == 'p') ? 1 : 0) + \
230
((sizeof(fmt) >= 8 && fmt[5] != '%' && fmt[6] == '%' && fmt[7] == 'p') ? 1 : 0) + \
231
((sizeof(fmt) >= 9 && fmt[6] != '%' && fmt[7] == '%' && fmt[8] == 'p') ? 1 : 0) + \
232
((sizeof(fmt) >= 10 && fmt[7] != '%' && fmt[8] == '%' && fmt[9] == 'p') ? 1 : 0) + \
233
((sizeof(fmt) >= 11 && fmt[8] != '%' && fmt[9] == '%' && fmt[10] == 'p') ? 1 : 0) + \
234
((sizeof(fmt) >= 12 && fmt[9] != '%' && fmt[10] == '%' && fmt[11] == 'p') ? 1 : 0) + \
235
((sizeof(fmt) >= 13 && fmt[10] != '%' && fmt[11] == '%' && fmt[12] == 'p') ? 1 : 0) + \
236
((sizeof(fmt) >= 14 && fmt[11] != '%' && fmt[12] == '%' && fmt[13] == 'p') ? 1 : 0) + \
237
((sizeof(fmt) >= 15 && fmt[12] != '%' && fmt[13] == '%' && fmt[14] == 'p') ? 1 : 0) + \
238
((sizeof(fmt) >= 16 && fmt[13] != '%' && fmt[14] == '%' && fmt[15] == 'p') ? 1 : 0) + \
239
((sizeof(fmt) >= 17 && fmt[14] != '%' && fmt[15] == '%' && fmt[16] == 'p') ? 1 : 0) + \
240
((sizeof(fmt) >= 18 && fmt[15] != '%' && fmt[16] == '%' && fmt[17] == 'p') ? 1 : 0) + \
241
((sizeof(fmt) >= 19 && fmt[16] != '%' && fmt[17] == '%' && fmt[18] == 'p') ? 1 : 0) + \
242
((sizeof(fmt) >= 20 && fmt[17] != '%' && fmt[18] == '%' && fmt[19] == 'p') ? 1 : 0) + \
243
((sizeof(fmt) >= 21 && fmt[18] != '%' && fmt[19] == '%' && fmt[20] == 'p') ? 1 : 0) + \
244
((sizeof(fmt) >= 22 && fmt[19] != '%' && fmt[20] == '%' && fmt[21] == 'p') ? 1 : 0) + \
245
((sizeof(fmt) >= 23 && fmt[20] != '%' && fmt[21] == '%' && fmt[22] == 'p') ? 1 : 0) + \
246
((sizeof(fmt) >= 24 && fmt[21] != '%' && fmt[22] == '%' && fmt[23] == 'p') ? 1 : 0) + \
247
((sizeof(fmt) >= 25 && fmt[22] != '%' && fmt[23] == '%' && fmt[24] == 'p') ? 1 : 0) + \
248
((sizeof(fmt) >= 26 && fmt[23] != '%' && fmt[24] == '%' && fmt[25] == 'p') ? 1 : 0) + \
249
((sizeof(fmt) >= 27 && fmt[24] != '%' && fmt[25] == '%' && fmt[26] == 'p') ? 1 : 0) + \
250
((sizeof(fmt) >= 28 && fmt[25] != '%' && fmt[26] == '%' && fmt[27] == 'p') ? 1 : 0) + \
251
((sizeof(fmt) >= 29 && fmt[26] != '%' && fmt[27] == '%' && fmt[28] == 'p') ? 1 : 0) + \
252
((sizeof(fmt) >= 30 && fmt[27] != '%' && fmt[28] == '%' && fmt[29] == 'p') ? 1 : 0) + \
253
((sizeof(fmt) >= 31 && fmt[28] != '%' && fmt[29] == '%' && fmt[30] == 'p') ? 1 : 0) + \
254
((sizeof(fmt) >= 32 && fmt[29] != '%' && fmt[30] == '%' && fmt[31] == 'p') ? 1 : 0) + \
255
((sizeof(fmt) >= 33 && fmt[30] != '%' && fmt[31] == '%' && fmt[32] == 'p') ? 1 : 0) + \
256
((sizeof(fmt) >= 34 && fmt[31] != '%' && fmt[32] == '%' && fmt[33] == 'p') ? 1 : 0) + \
257
((sizeof(fmt) >= 35 && fmt[32] != '%' && fmt[33] == '%' && fmt[34] == 'p') ? 1 : 0) + \
258
((sizeof(fmt) >= 36 && fmt[33] != '%' && fmt[34] == '%' && fmt[35] == 'p') ? 1 : 0) + \
259
((sizeof(fmt) >= 37 && fmt[34] != '%' && fmt[35] == '%' && fmt[36] == 'p') ? 1 : 0) + \
260
((sizeof(fmt) >= 38 && fmt[35] != '%' && fmt[36] == '%' && fmt[37] == 'p') ? 1 : 0) + \
261
((sizeof(fmt) >= 39 && fmt[36] != '%' && fmt[37] == '%' && fmt[38] == 'p') ? 1 : 0) + \
262
((sizeof(fmt) >= 40 && fmt[37] != '%' && fmt[38] == '%' && fmt[39] == 'p') ? 1 : 0) + \
263
((sizeof(fmt) >= 41 && fmt[38] != '%' && fmt[39] == '%' && fmt[40] == 'p') ? 1 : 0) + \
264
((sizeof(fmt) >= 42 && fmt[39] != '%' && fmt[40] == '%' && fmt[41] == 'p') ? 1 : 0) + \
265
((sizeof(fmt) >= 43 && fmt[40] != '%' && fmt[41] == '%' && fmt[42] == 'p') ? 1 : 0) + \
266
((sizeof(fmt) >= 44 && fmt[41] != '%' && fmt[42] == '%' && fmt[43] == 'p') ? 1 : 0) + \
267
((sizeof(fmt) >= 45 && fmt[42] != '%' && fmt[43] == '%' && fmt[44] == 'p') ? 1 : 0) + \
268
((sizeof(fmt) >= 46 && fmt[43] != '%' && fmt[44] == '%' && fmt[45] == 'p') ? 1 : 0) + \
269
((sizeof(fmt) >= 47 && fmt[44] != '%' && fmt[45] == '%' && fmt[46] == 'p') ? 1 : 0) + \
270
((sizeof(fmt) >= 48 && fmt[45] != '%' && fmt[46] == '%' && fmt[47] == 'p') ? 1 : 0) + \
271
((sizeof(fmt) >= 49 && fmt[46] != '%' && fmt[47] == '%' && fmt[48] == 'p') ? 1 : 0) + \
272
((sizeof(fmt) >= 50 && fmt[47] != '%' && fmt[48] == '%' && fmt[49] == 'p') ? 1 : 0) + \
273
((sizeof(fmt) >= 51 && fmt[48] != '%' && fmt[49] == '%' && fmt[50] == 'p') ? 1 : 0) + \
274
((sizeof(fmt) >= 52 && fmt[49] != '%' && fmt[50] == '%' && fmt[51] == 'p') ? 1 : 0) + \
275
((sizeof(fmt) >= 53 && fmt[50] != '%' && fmt[51] == '%' && fmt[52] == 'p') ? 1 : 0) + \
276
((sizeof(fmt) >= 54 && fmt[51] != '%' && fmt[52] == '%' && fmt[53] == 'p') ? 1 : 0) + \
277
((sizeof(fmt) >= 55 && fmt[52] != '%' && fmt[53] == '%' && fmt[54] == 'p') ? 1 : 0) + \
278
((sizeof(fmt) >= 56 && fmt[53] != '%' && fmt[54] == '%' && fmt[55] == 'p') ? 1 : 0) + \
279
((sizeof(fmt) >= 57 && fmt[54] != '%' && fmt[55] == '%' && fmt[56] == 'p') ? 1 : 0) + \
280
((sizeof(fmt) >= 58 && fmt[55] != '%' && fmt[56] == '%' && fmt[57] == 'p') ? 1 : 0) + \
281
((sizeof(fmt) >= 59 && fmt[56] != '%' && fmt[57] == '%' && fmt[58] == 'p') ? 1 : 0) + \
282
((sizeof(fmt) >= 60 && fmt[57] != '%' && fmt[58] == '%' && fmt[59] == 'p') ? 1 : 0) + \
283
((sizeof(fmt) >= 61 && fmt[58] != '%' && fmt[59] == '%' && fmt[60] == 'p') ? 1 : 0) + \
284
((sizeof(fmt) >= 62 && fmt[59] != '%' && fmt[60] == '%' && fmt[61] == 'p') ? 1 : 0) + \
285
((sizeof(fmt) >= 63 && fmt[60] != '%' && fmt[61] == '%' && fmt[62] == 'p') ? 1 : 0) + \
286
((sizeof(fmt) >= 64 && fmt[61] != '%' && fmt[62] == '%' && fmt[63] == 'p') ? 1 : 0) + \
287
((sizeof(fmt) >= 65 && fmt[62] != '%' && fmt[63] == '%' && fmt[64] == 'p') ? 1 : 0) + \
288
((sizeof(fmt) >= 66 && fmt[63] != '%' && fmt[64] == '%' && fmt[65] == 'p') ? 1 : 0) + \
289
((sizeof(fmt) >= 67 && fmt[64] != '%' && fmt[65] == '%' && fmt[66] == 'p') ? 1 : 0) + \
290
((sizeof(fmt) >= 68 && fmt[65] != '%' && fmt[66] == '%' && fmt[67] == 'p') ? 1 : 0) + \
291
((sizeof(fmt) >= 69 && fmt[66] != '%' && fmt[67] == '%' && fmt[68] == 'p') ? 1 : 0) + \
292
((sizeof(fmt) >= 70 && fmt[67] != '%' && fmt[68] == '%' && fmt[69] == 'p') ? 1 : 0) + \
293
((sizeof(fmt) >= 71 && fmt[68] != '%' && fmt[69] == '%' && fmt[70] == 'p') ? 1 : 0) + \
294
((sizeof(fmt) >= 72 && fmt[69] != '%' && fmt[70] == '%' && fmt[71] == 'p') ? 1 : 0) + \
295
((sizeof(fmt) >= 73 && fmt[70] != '%' && fmt[71] == '%' && fmt[72] == 'p') ? 1 : 0) + \
296
((sizeof(fmt) >= 74 && fmt[71] != '%' && fmt[72] == '%' && fmt[73] == 'p') ? 1 : 0) + \
297
((sizeof(fmt) >= 75 && fmt[72] != '%' && fmt[73] == '%' && fmt[74] == 'p') ? 1 : 0) + \
298
((sizeof(fmt) >= 76 && fmt[73] != '%' && fmt[74] == '%' && fmt[75] == 'p') ? 1 : 0) + \
299
((sizeof(fmt) >= 77 && fmt[74] != '%' && fmt[75] == '%' && fmt[76] == 'p') ? 1 : 0) + \
300
((sizeof(fmt) >= 78 && fmt[75] != '%' && fmt[76] == '%' && fmt[77] == 'p') ? 1 : 0) + \
301
((sizeof(fmt) >= 79 && fmt[76] != '%' && fmt[77] == '%' && fmt[78] == 'p') ? 1 : 0) + \
302
((sizeof(fmt) >= 80 && fmt[77] != '%' && fmt[78] == '%' && fmt[79] == 'p') ? 1 : 0) + \
303
((sizeof(fmt) >= 81 && fmt[78] != '%' && fmt[79] == '%' && fmt[80] == 'p') ? 1 : 0) + \
304
((sizeof(fmt) >= 82 && fmt[79] != '%' && fmt[80] == '%' && fmt[81] == 'p') ? 1 : 0) + \
305
((sizeof(fmt) >= 83 && fmt[80] != '%' && fmt[81] == '%' && fmt[82] == 'p') ? 1 : 0) + \
306
((sizeof(fmt) >= 84 && fmt[81] != '%' && fmt[82] == '%' && fmt[83] == 'p') ? 1 : 0) + \
307
((sizeof(fmt) >= 85 && fmt[82] != '%' && fmt[83] == '%' && fmt[84] == 'p') ? 1 : 0) + \
308
((sizeof(fmt) >= 86 && fmt[83] != '%' && fmt[84] == '%' && fmt[85] == 'p') ? 1 : 0) + \
309
((sizeof(fmt) >= 87 && fmt[84] != '%' && fmt[85] == '%' && fmt[86] == 'p') ? 1 : 0) + \
310
((sizeof(fmt) >= 88 && fmt[85] != '%' && fmt[86] == '%' && fmt[87] == 'p') ? 1 : 0) + \
311
((sizeof(fmt) >= 89 && fmt[86] != '%' && fmt[87] == '%' && fmt[88] == 'p') ? 1 : 0) + \
312
((sizeof(fmt) >= 90 && fmt[87] != '%' && fmt[88] == '%' && fmt[89] == 'p') ? 1 : 0) + \
313
((sizeof(fmt) >= 91 && fmt[88] != '%' && fmt[89] == '%' && fmt[90] == 'p') ? 1 : 0) + \
314
((sizeof(fmt) >= 92 && fmt[89] != '%' && fmt[90] == '%' && fmt[91] == 'p') ? 1 : 0) + \
315
((sizeof(fmt) >= 93 && fmt[90] != '%' && fmt[91] == '%' && fmt[92] == 'p') ? 1 : 0) + \
316
((sizeof(fmt) >= 94 && fmt[91] != '%' && fmt[92] == '%' && fmt[93] == 'p') ? 1 : 0) + \
317
((sizeof(fmt) >= 95 && fmt[92] != '%' && fmt[93] == '%' && fmt[94] == 'p') ? 1 : 0) + \
318
((sizeof(fmt) >= 96 && fmt[93] != '%' && fmt[94] == '%' && fmt[95] == 'p') ? 1 : 0) + \
319
((sizeof(fmt) >= 97 && fmt[94] != '%' && fmt[95] == '%' && fmt[96] == 'p') ? 1 : 0) + \
320
((sizeof(fmt) >= 98 && fmt[95] != '%' && fmt[96] == '%' && fmt[97] == 'p') ? 1 : 0) + \
321
((sizeof(fmt) >= 99 && fmt[96] != '%' && fmt[97] == '%' && fmt[98] == 'p') ? 1 : 0) + \
322
((sizeof(fmt) >= 100 && fmt[97] != '%' && fmt[98] == '%' && fmt[99] == 'p') ? 1 : 0) + \
323
((sizeof(fmt) >= 101 && fmt[98] != '%' && fmt[99] == '%' && fmt[100] == 'p') ? 1 : 0) + \
324
((sizeof(fmt) >= 102 && fmt[99] != '%' && fmt[100] == '%' && fmt[101] == 'p') ? 1 : 0) + \
325
((sizeof(fmt) >= 103 && fmt[100] != '%' && fmt[101] == '%' && fmt[102] == 'p') ? 1 : 0) + \
326
((sizeof(fmt) >= 104 && fmt[101] != '%' && fmt[102] == '%' && fmt[103] == 'p') ? 1 : 0) + \
327
((sizeof(fmt) >= 105 && fmt[102] != '%' && fmt[103] == '%' && fmt[104] == 'p') ? 1 : 0) + \
328
((sizeof(fmt) >= 106 && fmt[103] != '%' && fmt[104] == '%' && fmt[105] == 'p') ? 1 : 0) + \
329
((sizeof(fmt) >= 107 && fmt[104] != '%' && fmt[105] == '%' && fmt[106] == 'p') ? 1 : 0) + \
330
((sizeof(fmt) >= 108 && fmt[105] != '%' && fmt[106] == '%' && fmt[107] == 'p') ? 1 : 0) + \
331
((sizeof(fmt) >= 109 && fmt[106] != '%' && fmt[107] == '%' && fmt[108] == 'p') ? 1 : 0) + \
332
((sizeof(fmt) >= 110 && fmt[107] != '%' && fmt[108] == '%' && fmt[109] == 'p') ? 1 : 0) + \
333
((sizeof(fmt) >= 111 && fmt[108] != '%' && fmt[109] == '%' && fmt[110] == 'p') ? 1 : 0) + \
334
((sizeof(fmt) >= 112 && fmt[109] != '%' && fmt[110] == '%' && fmt[111] == 'p') ? 1 : 0) + \
335
((sizeof(fmt) >= 113 && fmt[110] != '%' && fmt[111] == '%' && fmt[112] == 'p') ? 1 : 0) + \
336
((sizeof(fmt) >= 114 && fmt[111] != '%' && fmt[112] == '%' && fmt[113] == 'p') ? 1 : 0) + \
337
((sizeof(fmt) >= 115 && fmt[112] != '%' && fmt[113] == '%' && fmt[114] == 'p') ? 1 : 0) + \
338
((sizeof(fmt) >= 116 && fmt[113] != '%' && fmt[114] == '%' && fmt[115] == 'p') ? 1 : 0) + \
339
((sizeof(fmt) >= 117 && fmt[114] != '%' && fmt[115] == '%' && fmt[116] == 'p') ? 1 : 0) + \
340
((sizeof(fmt) >= 118 && fmt[115] != '%' && fmt[116] == '%' && fmt[117] == 'p') ? 1 : 0) + \
341
((sizeof(fmt) >= 119 && fmt[116] != '%' && fmt[117] == '%' && fmt[118] == 'p') ? 1 : 0) + \
342
((sizeof(fmt) >= 120 && fmt[117] != '%' && fmt[118] == '%' && fmt[119] == 'p') ? 1 : 0) + \
343
((sizeof(fmt) >= 121 && fmt[118] != '%' && fmt[119] == '%' && fmt[120] == 'p') ? 1 : 0) + \
344
((sizeof(fmt) >= 122 && fmt[119] != '%' && fmt[120] == '%' && fmt[121] == 'p') ? 1 : 0) + \
345
((sizeof(fmt) >= 123 && fmt[120] != '%' && fmt[121] == '%' && fmt[122] == 'p') ? 1 : 0) + \
346
((sizeof(fmt) >= 124 && fmt[121] != '%' && fmt[122] == '%' && fmt[123] == 'p') ? 1 : 0) + \
347
((sizeof(fmt) >= 125 && fmt[122] != '%' && fmt[123] == '%' && fmt[124] == 'p') ? 1 : 0) + \
348
((sizeof(fmt) >= 126 && fmt[123] != '%' && fmt[124] == '%' && fmt[125] == 'p') ? 1 : 0) + \
349
((sizeof(fmt) >= 127 && fmt[124] != '%' && fmt[125] == '%' && fmt[126] == 'p') ? 1 : 0) + \
350
((sizeof(fmt) >= 128 && fmt[125] != '%' && fmt[126] == '%' && fmt[127] == 'p') ? 1 : 0) + \
351
((sizeof(fmt) >= 129 && fmt[126] != '%' && fmt[127] == '%' && fmt[128] == 'p') ? 1 : 0) + \
352
((sizeof(fmt) >= 130 && fmt[127] != '%' && fmt[128] == '%' && fmt[129] == 'p') ? 1 : 0) + \
353
((sizeof(fmt) >= 131 && fmt[128] != '%' && fmt[129] == '%' && fmt[130] == 'p') ? 1 : 0) + \
354
((sizeof(fmt) >= 132 && fmt[129] != '%' && fmt[130] == '%' && fmt[131] == 'p') ? 1 : 0) + \
355
((sizeof(fmt) >= 133 && fmt[130] != '%' && fmt[131] == '%' && fmt[132] == 'p') ? 1 : 0) + \
356
((sizeof(fmt) >= 134 && fmt[131] != '%' && fmt[132] == '%' && fmt[133] == 'p') ? 1 : 0) + \
357
((sizeof(fmt) >= 135 && fmt[132] != '%' && fmt[133] == '%' && fmt[134] == 'p') ? 1 : 0) + \
358
((sizeof(fmt) >= 136 && fmt[133] != '%' && fmt[134] == '%' && fmt[135] == 'p') ? 1 : 0) + \
359
((sizeof(fmt) >= 137 && fmt[134] != '%' && fmt[135] == '%' && fmt[136] == 'p') ? 1 : 0) + \
360
((sizeof(fmt) >= 138 && fmt[135] != '%' && fmt[136] == '%' && fmt[137] == 'p') ? 1 : 0) + \
361
((sizeof(fmt) >= 139 && fmt[136] != '%' && fmt[137] == '%' && fmt[138] == 'p') ? 1 : 0) + \
362
((sizeof(fmt) >= 140 && fmt[137] != '%' && fmt[138] == '%' && fmt[139] == 'p') ? 1 : 0) + \
363
((sizeof(fmt) >= 141 && fmt[138] != '%' && fmt[139] == '%' && fmt[140] == 'p') ? 1 : 0) + \
364
((sizeof(fmt) >= 142 && fmt[139] != '%' && fmt[140] == '%' && fmt[141] == 'p') ? 1 : 0) + \
365
((sizeof(fmt) >= 143 && fmt[140] != '%' && fmt[141] == '%' && fmt[142] == 'p') ? 1 : 0) + \
366
((sizeof(fmt) >= 144 && fmt[141] != '%' && fmt[142] == '%' && fmt[143] == 'p') ? 1 : 0) + \
367
((sizeof(fmt) >= 145 && fmt[142] != '%' && fmt[143] == '%' && fmt[144] == 'p') ? 1 : 0) + \
368
((sizeof(fmt) >= 146 && fmt[143] != '%' && fmt[144] == '%' && fmt[145] == 'p') ? 1 : 0) + \
369
((sizeof(fmt) >= 147 && fmt[144] != '%' && fmt[145] == '%' && fmt[146] == 'p') ? 1 : 0) + \
370
((sizeof(fmt) >= 148 && fmt[145] != '%' && fmt[146] == '%' && fmt[147] == 'p') ? 1 : 0) + \
371
((sizeof(fmt) >= 149 && fmt[146] != '%' && fmt[147] == '%' && fmt[148] == 'p') ? 1 : 0) + \
372
((sizeof(fmt) >= 150 && fmt[147] != '%' && fmt[148] == '%' && fmt[149] == 'p') ? 1 : 0) + \
373
((sizeof(fmt) >= 151 && fmt[148] != '%' && fmt[149] == '%' && fmt[150] == 'p') ? 1 : 0) + \
374
((sizeof(fmt) >= 152 && fmt[149] != '%' && fmt[150] == '%' && fmt[151] == 'p') ? 1 : 0) + \
375
((sizeof(fmt) >= 153 && fmt[150] != '%' && fmt[151] == '%' && fmt[152] == 'p') ? 1 : 0) + \
376
((sizeof(fmt) >= 154 && fmt[151] != '%' && fmt[152] == '%' && fmt[153] == 'p') ? 1 : 0) + \
377
((sizeof(fmt) >= 155 && fmt[152] != '%' && fmt[153] == '%' && fmt[154] == 'p') ? 1 : 0) + \
378
((sizeof(fmt) >= 156 && fmt[153] != '%' && fmt[154] == '%' && fmt[155] == 'p') ? 1 : 0) + \
379
((sizeof(fmt) >= 157 && fmt[154] != '%' && fmt[155] == '%' && fmt[156] == 'p') ? 1 : 0) + \
380
((sizeof(fmt) >= 158 && fmt[155] != '%' && fmt[156] == '%' && fmt[157] == 'p') ? 1 : 0) + \
381
((sizeof(fmt) >= 159 && fmt[156] != '%' && fmt[157] == '%' && fmt[158] == 'p') ? 1 : 0) + \
382
((sizeof(fmt) >= 160 && fmt[157] != '%' && fmt[158] == '%' && fmt[159] == 'p') ? 1 : 0) + \
383
((sizeof(fmt) >= 161 && fmt[158] != '%' && fmt[159] == '%' && fmt[160] == 'p') ? 1 : 0) + \
384
((sizeof(fmt) >= 162 && fmt[159] != '%' && fmt[160] == '%' && fmt[161] == 'p') ? 1 : 0) + \
385
((sizeof(fmt) >= 163 && fmt[160] != '%' && fmt[161] == '%' && fmt[162] == 'p') ? 1 : 0) + \
386
((sizeof(fmt) >= 164 && fmt[161] != '%' && fmt[162] == '%' && fmt[163] == 'p') ? 1 : 0) + \
387
((sizeof(fmt) >= 165 && fmt[162] != '%' && fmt[163] == '%' && fmt[164] == 'p') ? 1 : 0) + \
388
((sizeof(fmt) >= 166 && fmt[163] != '%' && fmt[164] == '%' && fmt[165] == 'p') ? 1 : 0) + \
389
((sizeof(fmt) >= 167 && fmt[164] != '%' && fmt[165] == '%' && fmt[166] == 'p') ? 1 : 0) + \
390
((sizeof(fmt) >= 168 && fmt[165] != '%' && fmt[166] == '%' && fmt[167] == 'p') ? 1 : 0) + \
391
((sizeof(fmt) >= 169 && fmt[166] != '%' && fmt[167] == '%' && fmt[168] == 'p') ? 1 : 0) + \
392
((sizeof(fmt) >= 170 && fmt[167] != '%' && fmt[168] == '%' && fmt[169] == 'p') ? 1 : 0) + \
393
((sizeof(fmt) >= 171 && fmt[168] != '%' && fmt[169] == '%' && fmt[170] == 'p') ? 1 : 0) + \
394
((sizeof(fmt) >= 172 && fmt[169] != '%' && fmt[170] == '%' && fmt[171] == 'p') ? 1 : 0) + \
395
((sizeof(fmt) >= 173 && fmt[170] != '%' && fmt[171] == '%' && fmt[172] == 'p') ? 1 : 0) + \
396
((sizeof(fmt) >= 174 && fmt[171] != '%' && fmt[172] == '%' && fmt[173] == 'p') ? 1 : 0) + \
397
((sizeof(fmt) >= 175 && fmt[172] != '%' && fmt[173] == '%' && fmt[174] == 'p') ? 1 : 0) + \
398
((sizeof(fmt) >= 176 && fmt[173] != '%' && fmt[174] == '%' && fmt[175] == 'p') ? 1 : 0) + \
399
((sizeof(fmt) >= 177 && fmt[174] != '%' && fmt[175] == '%' && fmt[176] == 'p') ? 1 : 0) + \
400
((sizeof(fmt) >= 178 && fmt[175] != '%' && fmt[176] == '%' && fmt[177] == 'p') ? 1 : 0) + \
401
((sizeof(fmt) >= 179 && fmt[176] != '%' && fmt[177] == '%' && fmt[178] == 'p') ? 1 : 0) + \
402
((sizeof(fmt) >= 180 && fmt[177] != '%' && fmt[178] == '%' && fmt[179] == 'p') ? 1 : 0) + \
403
((sizeof(fmt) >= 181 && fmt[178] != '%' && fmt[179] == '%' && fmt[180] == 'p') ? 1 : 0) + \
404
((sizeof(fmt) >= 182 && fmt[179] != '%' && fmt[180] == '%' && fmt[181] == 'p') ? 1 : 0) + \
405
((sizeof(fmt) >= 183 && fmt[180] != '%' && fmt[181] == '%' && fmt[182] == 'p') ? 1 : 0) + \
406
((sizeof(fmt) >= 184 && fmt[181] != '%' && fmt[182] == '%' && fmt[183] == 'p') ? 1 : 0) + \
407
((sizeof(fmt) >= 185 && fmt[182] != '%' && fmt[183] == '%' && fmt[184] == 'p') ? 1 : 0) + \
408
((sizeof(fmt) >= 186 && fmt[183] != '%' && fmt[184] == '%' && fmt[185] == 'p') ? 1 : 0) + \
409
((sizeof(fmt) >= 187 && fmt[184] != '%' && fmt[185] == '%' && fmt[186] == 'p') ? 1 : 0) + \
410
((sizeof(fmt) >= 188 && fmt[185] != '%' && fmt[186] == '%' && fmt[187] == 'p') ? 1 : 0) + \
411
((sizeof(fmt) >= 189 && fmt[186] != '%' && fmt[187] == '%' && fmt[188] == 'p') ? 1 : 0) + \
412
((sizeof(fmt) >= 190 && fmt[187] != '%' && fmt[188] == '%' && fmt[189] == 'p') ? 1 : 0) + \
413
((sizeof(fmt) >= 191 && fmt[188] != '%' && fmt[189] == '%' && fmt[190] == 'p') ? 1 : 0) + \
414
((sizeof(fmt) >= 192 && fmt[189] != '%' && fmt[190] == '%' && fmt[191] == 'p') ? 1 : 0) + \
415
((sizeof(fmt) >= 193 && fmt[190] != '%' && fmt[191] == '%' && fmt[192] == 'p') ? 1 : 0) + \
416
((sizeof(fmt) >= 194 && fmt[191] != '%' && fmt[192] == '%' && fmt[193] == 'p') ? 1 : 0) + \
417
((sizeof(fmt) >= 195 && fmt[192] != '%' && fmt[193] == '%' && fmt[194] == 'p') ? 1 : 0) + \
418
((sizeof(fmt) >= 196 && fmt[193] != '%' && fmt[194] == '%' && fmt[195] == 'p') ? 1 : 0) + \
419
((sizeof(fmt) >= 197 && fmt[194] != '%' && fmt[195] == '%' && fmt[196] == 'p') ? 1 : 0) + \
420
((sizeof(fmt) >= 198 && fmt[195] != '%' && fmt[196] == '%' && fmt[197] == 'p') ? 1 : 0) + \
421
((sizeof(fmt) >= 199 && fmt[196] != '%' && fmt[197] == '%' && fmt[198] == 'p') ? 1 : 0) + \
422
((sizeof(fmt) >= 200 && fmt[197] != '%' && fmt[198] == '%' && fmt[199] == 'p') ? 1 : 0) + \
423
((sizeof(fmt) >= 201 && fmt[198] != '%' && fmt[199] == '%' && fmt[200] == 'p') ? 1 : 0) + \
424
((sizeof(fmt) >= 202 && fmt[199] != '%' && fmt[200] == '%' && fmt[201] == 'p') ? 1 : 0) + \
425
((sizeof(fmt) >= 203 && fmt[200] != '%' && fmt[201] == '%' && fmt[202] == 'p') ? 1 : 0) + \
426
((sizeof(fmt) >= 204 && fmt[201] != '%' && fmt[202] == '%' && fmt[203] == 'p') ? 1 : 0) + \
427
((sizeof(fmt) >= 205 && fmt[202] != '%' && fmt[203] == '%' && fmt[204] == 'p') ? 1 : 0) + \
428
((sizeof(fmt) >= 206 && fmt[203] != '%' && fmt[204] == '%' && fmt[205] == 'p') ? 1 : 0) + \
429
((sizeof(fmt) >= 207 && fmt[204] != '%' && fmt[205] == '%' && fmt[206] == 'p') ? 1 : 0) + \
430
((sizeof(fmt) >= 208 && fmt[205] != '%' && fmt[206] == '%' && fmt[207] == 'p') ? 1 : 0) + \
431
((sizeof(fmt) >= 209 && fmt[206] != '%' && fmt[207] == '%' && fmt[208] == 'p') ? 1 : 0) + \
432
((sizeof(fmt) >= 210 && fmt[207] != '%' && fmt[208] == '%' && fmt[209] == 'p') ? 1 : 0) + \
433
((sizeof(fmt) >= 211 && fmt[208] != '%' && fmt[209] == '%' && fmt[210] == 'p') ? 1 : 0) + \
434
((sizeof(fmt) >= 212 && fmt[209] != '%' && fmt[210] == '%' && fmt[211] == 'p') ? 1 : 0) + \
435
((sizeof(fmt) >= 213 && fmt[210] != '%' && fmt[211] == '%' && fmt[212] == 'p') ? 1 : 0) + \
436
((sizeof(fmt) >= 214 && fmt[211] != '%' && fmt[212] == '%' && fmt[213] == 'p') ? 1 : 0) + \
437
((sizeof(fmt) >= 215 && fmt[212] != '%' && fmt[213] == '%' && fmt[214] == 'p') ? 1 : 0) + \
438
((sizeof(fmt) >= 216 && fmt[213] != '%' && fmt[214] == '%' && fmt[215] == 'p') ? 1 : 0) + \
439
((sizeof(fmt) >= 217 && fmt[214] != '%' && fmt[215] == '%' && fmt[216] == 'p') ? 1 : 0) + \
440
((sizeof(fmt) >= 218 && fmt[215] != '%' && fmt[216] == '%' && fmt[217] == 'p') ? 1 : 0) + \
441
((sizeof(fmt) >= 219 && fmt[216] != '%' && fmt[217] == '%' && fmt[218] == 'p') ? 1 : 0) + \
442
((sizeof(fmt) >= 220 && fmt[217] != '%' && fmt[218] == '%' && fmt[219] == 'p') ? 1 : 0) + \
443
((sizeof(fmt) >= 221 && fmt[218] != '%' && fmt[219] == '%' && fmt[220] == 'p') ? 1 : 0) + \
444
((sizeof(fmt) >= 222 && fmt[219] != '%' && fmt[220] == '%' && fmt[221] == 'p') ? 1 : 0) + \
445
((sizeof(fmt) >= 223 && fmt[220] != '%' && fmt[221] == '%' && fmt[222] == 'p') ? 1 : 0) + \
446
((sizeof(fmt) >= 224 && fmt[221] != '%' && fmt[222] == '%' && fmt[223] == 'p') ? 1 : 0) + \
447
((sizeof(fmt) >= 225 && fmt[222] != '%' && fmt[223] == '%' && fmt[224] == 'p') ? 1 : 0) + \
448
((sizeof(fmt) >= 226 && fmt[223] != '%' && fmt[224] == '%' && fmt[225] == 'p') ? 1 : 0) + \
449
((sizeof(fmt) >= 227 && fmt[224] != '%' && fmt[225] == '%' && fmt[226] == 'p') ? 1 : 0) + \
450
((sizeof(fmt) >= 228 && fmt[225] != '%' && fmt[226] == '%' && fmt[227] == 'p') ? 1 : 0) + \
451
((sizeof(fmt) >= 229 && fmt[226] != '%' && fmt[227] == '%' && fmt[228] == 'p') ? 1 : 0) + \
452
((sizeof(fmt) >= 230 && fmt[227] != '%' && fmt[228] == '%' && fmt[229] == 'p') ? 1 : 0) + \
453
((sizeof(fmt) >= 231 && fmt[228] != '%' && fmt[229] == '%' && fmt[230] == 'p') ? 1 : 0) + \
454
((sizeof(fmt) >= 232 && fmt[229] != '%' && fmt[230] == '%' && fmt[231] == 'p') ? 1 : 0) + \
455
((sizeof(fmt) >= 233 && fmt[230] != '%' && fmt[231] == '%' && fmt[232] == 'p') ? 1 : 0) + \
456
((sizeof(fmt) >= 234 && fmt[231] != '%' && fmt[232] == '%' && fmt[233] == 'p') ? 1 : 0) + \
457
((sizeof(fmt) >= 235 && fmt[232] != '%' && fmt[233] == '%' && fmt[234] == 'p') ? 1 : 0) + \
458
((sizeof(fmt) >= 236 && fmt[233] != '%' && fmt[234] == '%' && fmt[235] == 'p') ? 1 : 0) + \
459
((sizeof(fmt) >= 237 && fmt[234] != '%' && fmt[235] == '%' && fmt[236] == 'p') ? 1 : 0) + \
460
((sizeof(fmt) >= 238 && fmt[235] != '%' && fmt[236] == '%' && fmt[237] == 'p') ? 1 : 0) + \
461
((sizeof(fmt) >= 239 && fmt[236] != '%' && fmt[237] == '%' && fmt[238] == 'p') ? 1 : 0) + \
462
((sizeof(fmt) >= 240 && fmt[237] != '%' && fmt[238] == '%' && fmt[239] == 'p') ? 1 : 0) + \
463
((sizeof(fmt) >= 241 && fmt[238] != '%' && fmt[239] == '%' && fmt[240] == 'p') ? 1 : 0) + \
464
((sizeof(fmt) >= 242 && fmt[239] != '%' && fmt[240] == '%' && fmt[241] == 'p') ? 1 : 0) + \
465
((sizeof(fmt) >= 243 && fmt[240] != '%' && fmt[241] == '%' && fmt[242] == 'p') ? 1 : 0) + \
466
((sizeof(fmt) >= 244 && fmt[241] != '%' && fmt[242] == '%' && fmt[243] == 'p') ? 1 : 0) + \
467
((sizeof(fmt) >= 245 && fmt[242] != '%' && fmt[243] == '%' && fmt[244] == 'p') ? 1 : 0) + \
468
((sizeof(fmt) >= 246 && fmt[243] != '%' && fmt[244] == '%' && fmt[245] == 'p') ? 1 : 0) + \
469
((sizeof(fmt) >= 247 && fmt[244] != '%' && fmt[245] == '%' && fmt[246] == 'p') ? 1 : 0) + \
470
((sizeof(fmt) >= 248 && fmt[245] != '%' && fmt[246] == '%' && fmt[247] == 'p') ? 1 : 0) + \
471
((sizeof(fmt) >= 249 && fmt[246] != '%' && fmt[247] == '%' && fmt[248] == 'p') ? 1 : 0) + \
472
((sizeof(fmt) >= 250 && fmt[247] != '%' && fmt[248] == '%' && fmt[249] == 'p') ? 1 : 0) + \
473
((sizeof(fmt) >= 251 && fmt[248] != '%' && fmt[249] == '%' && fmt[250] == 'p') ? 1 : 0) + \
474
((sizeof(fmt) >= 252 && fmt[249] != '%' && fmt[250] == '%' && fmt[251] == 'p') ? 1 : 0) + \
475
((sizeof(fmt) >= 253 && fmt[250] != '%' && fmt[251] == '%' && fmt[252] == 'p') ? 1 : 0) + \
476
((sizeof(fmt) >= 254 && fmt[251] != '%' && fmt[252] == '%' && fmt[253] == 'p') ? 1 : 0) + \
477
((sizeof(fmt) >= 255 && fmt[252] != '%' && fmt[253] == '%' && fmt[254] == 'p') ? 1 : 0) + \
478
((sizeof(fmt) >= 256 && fmt[253] != '%' && fmt[254] == '%' && fmt[255] == 'p') ? 1 : 0)
479
497
#define Z_CBPRINTF_POINTERS_VALIDATE(...) \
498
(Z_CBPRINTF_NONE_CHAR_PTR_COUNT(__VA_ARGS__) == \
499
Z_CBPRINTF_P_COUNT(GET_ARG_N(1, __VA_ARGS__)))
500
501
/* @brief Check if argument is a certain type of char pointer. What exactly is checked
502
* depends on @p flags. If flags is 0 then 1 is returned if @p x is a char pointer.
503
*
504
* @param idx Argument index.
505
* @param x Argument.
506
* @param flags Flags. See @p CBPRINTF_PACKAGE_FLAGS.
507
*
508
* @retval 1 if @p x is char pointer meeting criteria identified by @p flags.
509
* @retval 0 otherwise.
510
*/
511
#define Z_CBPRINTF_IS_X_PCHAR(idx, x, flags) \
512
(idx < Z_CBPRINTF_PACKAGE_FIRST_RO_STR_CNT_GET(flags) ? \
513
0 : Z_CBPRINTF_IS_PCHAR(x, flags))
514
523
#define Z_CBPRINTF_HAS_PCHAR_ARGS(flags, fmt, ...) \
524
(FOR_EACH_IDX_FIXED_ARG(Z_CBPRINTF_IS_X_PCHAR, (+), flags, __VA_ARGS__))
525
526
#define Z_CBPRINTF_PCHAR_COUNT(flags, ...) \
527
COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), \
528
(0), \
529
(Z_CBPRINTF_HAS_PCHAR_ARGS(flags, __VA_ARGS__)))
530
539
#if Z_C_GENERIC
540
#define Z_CBPRINTF_MUST_RUNTIME_PACKAGE(flags, ...) ({\
541
int _rv; \
542
if ((flags) & CBPRINTF_PACKAGE_ADD_RW_STR_POS) { \
543
_rv = 0; \
544
} else { \
545
_rv = Z_CBPRINTF_PCHAR_COUNT(flags, __VA_ARGS__) > 0 ? 1 : 0; \
546
} \
547
_rv; \
548
})
549
#else
550
#define Z_CBPRINTF_MUST_RUNTIME_PACKAGE(flags, ...) 1
551
#endif
552
562
#ifdef __cplusplus
563
#define Z_CBPRINTF_ARG_SIZE(v) z_cbprintf_cxx_arg_size(v)
564
#else
565
#define Z_CONSTIFY(v) ({ \
566
__auto_type _uv = (v); \
567
__typeof__(_uv) const _cv = _uv; \
568
_cv; \
569
})
570
#define Z_CBPRINTF_ARG_SIZE(v) ({\
571
__auto_type __v = Z_ARGIFY(Z_CONSTIFY(v)); \
572
/* Static code analysis may complain about unused variable. */
\
573
(void)__v; \
574
size_t __arg_size = _Generic((v), \
575
float : sizeof(double), \
576
default : \
577
sizeof((__v))
/* NOLINT(bugprone-sizeof-expression) */
\
578
); \
579
__arg_size; \
580
})
581
#endif
582
589
#ifdef __cplusplus
590
#define Z_CBPRINTF_STORE_ARG(buf, arg) z_cbprintf_cxx_store_arg(buf, arg)
591
#else
592
#define Z_CBPRINTF_STORE_ARG(buf, arg) do { \
593
if (Z_CBPRINTF_VA_STACK_LL_DBL_MEMCPY) { \
594
/* If required, copy arguments by word to avoid unaligned access.*/
\
595
__auto_type _v = Z_ARGIFY(Z_CONSTIFY(arg)); \
596
double _d = _Generic(Z_ARGIFY(arg), \
597
float : Z_ARGIFY(arg), \
598
default : \
599
0.0); \
600
/* Static code analysis may complain about unused variable. */
\
601
(void)_v; \
602
(void)_d; \
603
size_t arg_size = Z_CBPRINTF_ARG_SIZE(arg); \
604
size_t _wsize = arg_size / sizeof(int); \
605
z_cbprintf_wcpy((int *)(buf), \
606
(int *) _Generic(Z_ARGIFY(arg), float : &_d, default : &_v), \
607
_wsize); \
608
} else { \
609
*_Generic(Z_ARGIFY(arg), \
610
char : (int *)(buf), \
611
unsigned char: (int *)(buf), \
612
short : (int *)(buf), \
613
unsigned short : (int *)(buf), \
614
int : (int *)(buf), \
615
unsigned int : (unsigned int *)(buf), \
616
long : (long *)(buf), \
617
unsigned long : (unsigned long *)(buf), \
618
long long : (long long *)(buf), \
619
unsigned long long : (unsigned long long *)(buf), \
620
float : (double *)(buf), \
621
double : (double *)(buf), \
622
long double : (long double *)(buf), \
623
default : \
624
(const void **)(buf)) = (arg); \
625
} \
626
} while (false)
627
#endif
628
635
#ifdef __cplusplus
636
#define Z_CBPRINTF_ALIGNMENT(_arg) z_cbprintf_cxx_alignment(_arg)
637
#else
638
#define Z_CBPRINTF_ALIGNMENT(_arg) \
639
MAX(_Generic(Z_ARGIFY(_arg), \
640
float : VA_STACK_ALIGN(double), \
641
double : VA_STACK_ALIGN(double), \
642
long double : VA_STACK_ALIGN(long double), \
643
long long : VA_STACK_ALIGN(long long), \
644
unsigned long long : VA_STACK_ALIGN(long long), \
645
default : \
646
__alignof__(Z_ARGIFY(_arg))), VA_STACK_MIN_ALIGN)
647
#endif
648
659
#ifdef __cplusplus
660
#if defined(__x86_64__) || defined(__riscv) || defined(__aarch64__)
661
#define Z_CBPRINTF_IS_LONGDOUBLE(x) 0
662
#else
663
#define Z_CBPRINTF_IS_LONGDOUBLE(x) z_cbprintf_cxx_is_longdouble(x)
664
#endif
665
#else
666
#define Z_CBPRINTF_IS_LONGDOUBLE(x) \
667
_Generic(Z_ARGIFY(x), long double : 1, default : 0)
668
#endif
669
685
#define Z_CBPRINTF_PACK_ARG2(arg_idx, _buf, _idx, _align_offset, _max, _arg) \
686
do { \
687
BUILD_ASSERT(!((sizeof(double) < VA_STACK_ALIGN(long double)) && \
688
Z_CBPRINTF_IS_LONGDOUBLE(_arg) && \
689
!IS_ENABLED(CONFIG_CBPRINTF_PACKAGE_LONGDOUBLE)),\
690
"Packaging of long double not enabled in Kconfig."); \
691
while (((_align_offset) % Z_CBPRINTF_ALIGNMENT(_arg)) != 0UL) { \
692
(_idx) += sizeof(int); \
693
(_align_offset) += sizeof(int); \
694
} \
695
uint32_t _arg_size = Z_CBPRINTF_ARG_SIZE(_arg); \
696
uint8_t _loc = (uint8_t)(_idx / sizeof(int)); \
697
if (arg_idx < 1 + _fros_cnt) { \
698
if (_ros_pos_en) { \
699
_ros_pos_buf[_ros_pos_idx++] = _loc; \
700
} \
701
} else if (Z_CBPRINTF_IS_PCHAR(_arg, 0)) { \
702
if (_cros_en) { \
703
if (Z_CBPRINTF_IS_X_PCHAR(arg_idx, _arg, _flags)) { \
704
if (_rws_pos_en) { \
705
_rws_buffer[_rws_pos_idx++] = arg_idx - 1; \
706
_rws_buffer[_rws_pos_idx++] = _loc; \
707
} \
708
} else { \
709
if (_ros_pos_en) { \
710
_ros_pos_buf[_ros_pos_idx++] = _loc; \
711
} \
712
} \
713
} else if (_rws_pos_en) { \
714
_rws_buffer[_rws_pos_idx++] = arg_idx - 1; \
715
_rws_buffer[_rws_pos_idx++] = (uint8_t)(_idx / sizeof(int)); \
716
} \
717
} \
718
if ((_buf) && (_idx) < (int)(_max)) { \
719
Z_CBPRINTF_STORE_ARG(&(_buf)[(_idx)], _arg); \
720
} \
721
(_idx) += (_arg_size); \
722
(_align_offset) += (_arg_size); \
723
} while (false)
724
731
#define Z_CBPRINTF_PACK_ARG(arg_idx, arg) \
732
Z_CBPRINTF_PACK_ARG2(arg_idx, _pbuf, _pkg_len, _pkg_offset, _pmax, arg)
733
734
/* Allocation to avoid using VLA and alloca. Alloc frees space when leaving
735
* a function which can lead to increased stack usage if logging is used
736
* multiple times. VLA is not always available.
737
*
738
* Use large array when optimization is off to avoid increased stack usage.
739
*/
740
#ifdef CONFIG_NO_OPTIMIZATIONS
741
#define Z_CBPRINTF_ON_STACK_ALLOC(_name, _len) \
742
__ASSERT(_len <= 32, "Too many string arguments."); \
743
uint8_t _name##_buf32[32]; \
744
_name = _name##_buf32
745
#else
746
#define Z_CBPRINTF_ON_STACK_ALLOC(_name, _len) \
747
__ASSERT(_len <= 32, "Too many string arguments."); \
748
uint8_t _name##_buf4[4]; \
749
uint8_t _name##_buf8[8]; \
750
uint8_t _name##_buf12[12]; \
751
uint8_t _name##_buf16[16]; \
752
uint8_t _name##_buf32[32]; \
753
_name = (_len) <= 4 ? _name##_buf4 : \
754
((_len) <= 8 ? _name##_buf8 : \
755
((_len) <= 12 ? _name##_buf12 : \
756
((_len) <= 16 ? _name##_buf16 : \
757
_name##_buf32)))
758
#endif
759
760
/* On Xtensa the cbprintf_package_desc requires
761
* an additional alignment array. This creates an
762
* initial value to hush the compiler when compiling
763
* with C++.
764
*/
765
#if defined(CONFIG_XTENSA) && defined(__cplusplus)
766
#define Z_CBPRINTF_XTENSA_PKG_DESC_PADDING_INITIALIZER .xtensa_padding = { },
767
#else
768
#define Z_CBPRINTF_XTENSA_PKG_DESC_PADDING_INITIALIZER
769
#endif
770
786
#define Z_CBPRINTF_STATIC_PACKAGE_GENERIC(buf, _inlen, _outlen, _align_offset, \
787
flags, ...
/* fmt, ... */
) \
788
do { \
789
BUILD_ASSERT(!IS_ENABLED(CONFIG_XTENSA) || \
790
(IS_ENABLED(CONFIG_XTENSA) && \
791
!((_align_offset) % CBPRINTF_PACKAGE_ALIGNMENT)), \
792
"Xtensa requires aligned package."); \
793
BUILD_ASSERT(((_align_offset) % sizeof(int)) == 0, \
794
"Alignment offset must be multiply of a word."); \
795
IF_ENABLED(CONFIG_CBPRINTF_STATIC_PACKAGE_CHECK_ALIGNMENT, \
796
(__ASSERT(!((uintptr_t)buf & (CBPRINTF_PACKAGE_ALIGNMENT - 1)), \
797
"Buffer must be aligned.");)) \
798
uint32_t _flags = flags; \
799
bool _ros_pos_en = (_flags) & CBPRINTF_PACKAGE_ADD_RO_STR_POS; \
800
bool _rws_pos_en = (_flags) & CBPRINTF_PACKAGE_ADD_RW_STR_POS; \
801
bool _cros_en = (_flags) & CBPRINTF_PACKAGE_CONST_CHAR_RO; \
802
uint8_t *_pbuf = (buf); \
803
uint8_t _rws_pos_idx = 0; \
804
uint8_t _ros_pos_idx = 0; \
805
/* Variable holds count of all string pointer arguments. */
\
806
uint8_t _alls_cnt = Z_CBPRINTF_PCHAR_COUNT(0, __VA_ARGS__); \
807
uint8_t _fros_cnt = Z_CBPRINTF_PACKAGE_FIRST_RO_STR_CNT_GET(_flags); \
808
/* Variable holds count of non const string pointers. */
\
809
uint8_t _rws_cnt = _cros_en ? \
810
Z_CBPRINTF_PCHAR_COUNT(_flags, __VA_ARGS__) : _alls_cnt - _fros_cnt; \
811
uint8_t _ros_cnt = _ros_pos_en ? (1 + _alls_cnt - _rws_cnt) : 0; \
812
uint8_t *_ros_pos_buf; \
813
Z_CBPRINTF_ON_STACK_ALLOC(_ros_pos_buf, _ros_cnt); \
814
uint8_t *_rws_buffer; \
815
Z_CBPRINTF_ON_STACK_ALLOC(_rws_buffer, 2 * _rws_cnt); \
816
size_t _pmax = !is_null_no_warn(buf) ? _inlen : INT32_MAX; \
817
int _pkg_len = 0; \
818
int _total_len = 0; \
819
int _pkg_offset = (_align_offset); \
820
union cbprintf_package_hdr *_len_loc; \
821
/* If string has rw string arguments CBPRINTF_PACKAGE_ADD_RW_STR_POS is a must. */
\
822
if (_rws_cnt && !((_flags) & CBPRINTF_PACKAGE_ADD_RW_STR_POS)) { \
823
_outlen = -EINVAL; \
824
break; \
825
} \
826
/* package starts with string address and field with length */
\
827
if (_pmax < sizeof(*_len_loc)) { \
828
(_outlen) = -ENOSPC; \
829
break; \
830
} \
831
_len_loc = (union cbprintf_package_hdr *)_pbuf; \
832
_pkg_len += sizeof(*_len_loc); \
833
_pkg_offset += sizeof(*_len_loc); \
834
/* Pack remaining arguments */
\
835
FOR_EACH_IDX(Z_CBPRINTF_PACK_ARG, (;), __VA_ARGS__);\
836
_total_len = _pkg_len; \
837
/* Append string indexes to the package. */
\
838
_total_len += _ros_cnt; \
839
_total_len += 2 * _rws_cnt; \
840
if (_pbuf != NULL) { \
841
/* Append string locations. */
\
842
uint8_t *_pbuf_loc = &_pbuf[_pkg_len]; \
843
for (size_t _ros_idx = 0; _ros_idx < _ros_cnt; _ros_idx++) { \
844
*_pbuf_loc++ = _ros_pos_buf[_ros_idx]; \
845
} \
846
for (size_t _rws_idx = 0; _rws_idx < (2 * _rws_cnt); _rws_idx++) { \
847
*_pbuf_loc++ = _rws_buffer[_rws_idx]; \
848
} \
849
} \
850
/* Store length */
\
851
(_outlen) = (_total_len > (int)_pmax) ? -ENOSPC : _total_len; \
852
/* Store length in the header, set number of dumped strings to 0 */
\
853
if (_pbuf != NULL) { \
854
union cbprintf_package_hdr pkg_hdr = { \
855
.desc = { \
856
.len = (uint8_t)(_pkg_len / sizeof(int)), \
857
.str_cnt = 0, \
858
.ro_str_cnt = _ros_cnt, \
859
.rw_str_cnt = _rws_cnt, \
860
Z_CBPRINTF_XTENSA_PKG_DESC_PADDING_INITIALIZER \
861
} \
862
}; \
863
IF_ENABLED(CONFIG_CBPRINTF_PACKAGE_HEADER_STORE_CREATION_FLAGS, \
864
(pkg_hdr.desc.pkg_flags = flags)); \
865
*_len_loc = pkg_hdr; \
866
} \
867
} while (false)
868
869
#if Z_C_GENERIC
870
#define Z_CBPRINTF_STATIC_PACKAGE(packaged, inlen, outlen, align_offset, flags, \
871
...
/* fmt, ... */
) \
872
Z_CBPRINTF_STATIC_PACKAGE_GENERIC(packaged, inlen, outlen, \
873
align_offset, flags, __VA_ARGS__)
874
#else
875
#define Z_CBPRINTF_STATIC_PACKAGE(packaged, inlen, outlen, align_offset, flags, \
876
...
/* fmt, ... */
) \
877
do { \
878
/* Small trick needed to avoid warning on always true */
\
879
if (((uintptr_t)packaged + 1) != 1) { \
880
outlen = cbprintf_package(packaged, inlen, flags, __VA_ARGS__); \
881
} else { \
882
outlen = cbprintf_package(NULL, align_offset, flags, __VA_ARGS__); \
883
} \
884
} while (false)
885
#endif
/* Z_C_GENERIC */
886
887
#ifdef __cplusplus
888
}
889
#endif
890
891
#ifdef CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS
892
#ifdef __cplusplus
893
/*
894
* Remove qualifiers like const, volatile. And also transform
895
* C++ argument reference back to its basic type.
896
*/
897
#define Z_CBPRINTF_ARG_REMOVE_QUAL(arg) \
898
z_cbprintf_cxx_remove_cv < \
899
z_cbprintf_cxx_remove_reference < decltype(arg) > ::type \
900
> ::type
901
902
/*
903
* Get the type of elements in an array.
904
*/
905
#define Z_CBPRINTF_CXX_ARG_ARRAY_TYPE(arg) \
906
z_cbprintf_cxx_remove_cv < \
907
z_cbprintf_cxx_remove_extent < decltype(arg) > ::type \
908
> ::type
909
910
/*
911
* Determine if incoming type is char.
912
*/
913
#define Z_CBPRINTF_CXX_ARG_IS_TYPE_CHAR(type) \
914
(z_cbprintf_cxx_is_same_type < type, \
915
char > :: value ? \
916
true : \
917
(z_cbprintf_cxx_is_same_type < type, \
918
const char > :: value ? \
919
true : \
920
(z_cbprintf_cxx_is_same_type < type, \
921
volatile char > :: value ? \
922
true : \
923
(z_cbprintf_cxx_is_same_type < type, \
924
const volatile char > :: value ? \
925
true : \
926
false))))
927
928
/*
929
* Figure out if this is a char array since (char *) and (char[])
930
* are of different types in C++.
931
*/
932
#define Z_CBPRINTF_CXX_ARG_IS_CHAR_ARRAY(arg) \
933
(z_cbprintf_cxx_is_array < decltype(arg) > :: value ? \
934
(Z_CBPRINTF_CXX_ARG_IS_TYPE_CHAR(Z_CBPRINTF_CXX_ARG_ARRAY_TYPE(arg)) ? \
935
true : \
936
false) : \
937
false)
938
939
/*
940
* Note that qualifiers of char * must be explicitly matched
941
* due to type matching in C++, where remove_cv() does not work.
942
*/
943
#define Z_CBPRINTF_ARG_TYPE(arg) \
944
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
945
char > ::value ? \
946
CBPRINTF_PACKAGE_ARG_TYPE_CHAR : \
947
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
948
unsigned char > ::value ? \
949
CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_CHAR : \
950
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
951
short > ::value ? \
952
CBPRINTF_PACKAGE_ARG_TYPE_SHORT : \
953
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
954
unsigned short > ::value ? \
955
CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_SHORT : \
956
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
957
int > ::value ? \
958
CBPRINTF_PACKAGE_ARG_TYPE_INT : \
959
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
960
unsigned int > ::value ? \
961
CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_INT : \
962
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
963
long > ::value ? \
964
CBPRINTF_PACKAGE_ARG_TYPE_LONG : \
965
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
966
unsigned long > ::value ? \
967
CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_LONG : \
968
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
969
long long > ::value ? \
970
CBPRINTF_PACKAGE_ARG_TYPE_LONG_LONG : \
971
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
972
unsigned long long > ::value ? \
973
CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_LONG_LONG : \
974
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
975
float > ::value ? \
976
CBPRINTF_PACKAGE_ARG_TYPE_FLOAT : \
977
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
978
double > ::value ? \
979
CBPRINTF_PACKAGE_ARG_TYPE_DOUBLE : \
980
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
981
long double > ::value ? \
982
CBPRINTF_PACKAGE_ARG_TYPE_LONG_DOUBLE : \
983
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
984
char * > :: value ? \
985
CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
986
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
987
const char * > :: value ? \
988
CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
989
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
990
volatile char * > :: value ? \
991
CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
992
(z_cbprintf_cxx_is_same_type < Z_CBPRINTF_ARG_REMOVE_QUAL(arg), \
993
const volatile char * > :: value ? \
994
CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
995
(Z_CBPRINTF_CXX_ARG_IS_CHAR_ARRAY(arg) ? \
996
CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR : \
997
CBPRINTF_PACKAGE_ARG_TYPE_PTR_VOID))))))))))))))))))
998
#else
999
#define Z_CBPRINTF_ARG_TYPE(arg) \
1000
_Generic(arg, \
1001
char : CBPRINTF_PACKAGE_ARG_TYPE_CHAR, \
1002
unsigned char : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_CHAR, \
1003
short : CBPRINTF_PACKAGE_ARG_TYPE_SHORT, \
1004
unsigned short : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_SHORT, \
1005
int : CBPRINTF_PACKAGE_ARG_TYPE_INT, \
1006
unsigned int : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_INT, \
1007
long : CBPRINTF_PACKAGE_ARG_TYPE_LONG, \
1008
unsigned long : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_LONG, \
1009
long long : CBPRINTF_PACKAGE_ARG_TYPE_LONG_LONG, \
1010
unsigned long long : CBPRINTF_PACKAGE_ARG_TYPE_UNSIGNED_LONG_LONG, \
1011
float : CBPRINTF_PACKAGE_ARG_TYPE_FLOAT, \
1012
double : CBPRINTF_PACKAGE_ARG_TYPE_DOUBLE, \
1013
long double : CBPRINTF_PACKAGE_ARG_TYPE_LONG_DOUBLE, \
1014
char * : CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR, \
1015
const char * : CBPRINTF_PACKAGE_ARG_TYPE_PTR_CHAR, \
1016
void * : CBPRINTF_PACKAGE_ARG_TYPE_PTR_VOID, \
1017
default : \
1018
CBPRINTF_PACKAGE_ARG_TYPE_PTR_VOID \
1019
)
1020
#endif
/* _cplusplus */
1021
1022
#define Z_CBPRINTF_TAGGED_EMPTY_ARGS(...) \
1023
CBPRINTF_PACKAGE_ARG_TYPE_END
1024
1025
#define Z_CBPRINTF_TAGGED_ARGS_3(arg) \
1026
Z_CBPRINTF_ARG_TYPE(arg), arg
1027
1028
#define Z_CBPRINTF_TAGGED_ARGS_2(...) \
1029
FOR_EACH(Z_CBPRINTF_TAGGED_ARGS_3, (,), __VA_ARGS__), \
1030
CBPRINTF_PACKAGE_ARG_TYPE_END
1031
1032
#define Z_CBPRINTF_TAGGED_ARGS(_num_args, ...) \
1033
COND_CODE_0(_num_args, \
1034
(CBPRINTF_PACKAGE_ARG_TYPE_END), \
1035
(Z_CBPRINTF_TAGGED_ARGS_2(__VA_ARGS__)))
1036
1037
#endif
/* CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS */
1038
1039
#endif
/* ZEPHYR_INCLUDE_SYS_CBPRINTF_INTERNAL_H_ */
__assert.h
cpu.h
cbprintf_cxx.h
errno.h
System error numbers.
stdint.h
util.h
Misc utilities.
toolchain.h
Macros to abstract toolchain specific capabilities.
zephyr
sys
cbprintf_internal.h
Generated on
for Zephyr API Documentation by
1.15.0