LCOV - code coverage report
Current view: top level - zephyr/sys - cbprintf_internal.h Coverage Total Hit
Test: new.info Lines: 0.0 % 3 0
Test Date: 2025-09-05 16:43:28

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

Generated by: LCOV version 2.0-1