Skip to content

Commit d12a995

Browse files
pabigotcarlescufi
authored andcommitted
lib: cbprintf: remove cbprintf_arglen
This function was designed to support the logging infrastructure's need to copy values from va_list structures. It did not meet that need, since some values need to be changed based on additional data that is only available when the complete format specification is examined. Remove the function as unnecessary. Signed-off-by: Peter Bigot <[email protected]>
1 parent 0bc0182 commit d12a995

File tree

4 files changed

+0
-165
lines changed

4 files changed

+0
-165
lines changed

include/sys/cbprintf.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,6 @@ typedef int (*cbprintf_cb)(/* int c, void *ctx */);
6969
__printf_like(3, 4)
7070
int cbprintf(cbprintf_cb out, void *ctx, const char *format, ...);
7171

72-
/** @brief Calculate the number of words required for arguments to a cbprintf
73-
* format specification.
74-
*
75-
* This can be used in cases where the arguments must be copied off the stack
76-
* into separate storage for processing the conversion in another context.
77-
*
78-
* @note The length returned does not count bytes. It counts native words
79-
* defined as the size of an `int`.
80-
*
81-
* @note If `CONFIG_CBPRINTF_NANO` is selected the count will be incorrect if
82-
* any passed arguments require more than one `int`.
83-
*
84-
* @param format a standard ISO C format string with characters and conversion
85-
* specifications.
86-
*
87-
* @return the number of `int` elements required to provide all arguments
88-
* required for the conversion.
89-
*/
90-
size_t cbprintf_arglen(const char *format);
91-
9272
/** @brief varargs-aware *printf-like output through a callback.
9373
*
9474
* This is essentially vsprintf() except the output is generated

lib/os/cbprintf_complete.c

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -616,84 +616,6 @@ static inline const char *extract_conversion(struct conversion *conv,
616616
return sp;
617617
}
618618

619-
620-
/* Get the number of int-sized objects required to provide the arguments for
621-
* the conversion.
622-
*
623-
* This has a role in the logging subsystem where the arguments must
624-
* be captured for formatting in another thread.
625-
*
626-
* If the conversion specifier is invalid the calculated length may
627-
* not match what was actually passed as arguments.
628-
*/
629-
static size_t conversion_arglen(const struct conversion *conv)
630-
{
631-
enum specifier_cat_enum specifier_cat
632-
= (enum specifier_cat_enum)conv->specifier_cat;
633-
enum length_mod_enum length_mod
634-
= (enum length_mod_enum)conv->length_mod;
635-
size_t words = 0;
636-
637-
/* If the conversion is invalid behavior is undefined. What
638-
* this does is try to consume the argument anyway, in hopes
639-
* that subsequent valid arguments will format correctly.
640-
*/
641-
642-
/* Percent has no arguments */
643-
if (conv->specifier == '%') {
644-
return words;
645-
}
646-
647-
if (conv->width_star) {
648-
words += sizeof(int) / sizeof(int);
649-
}
650-
651-
if (conv->prec_star) {
652-
words += sizeof(int) / sizeof(int);
653-
}
654-
655-
if ((specifier_cat == SPECIFIER_SINT)
656-
|| (specifier_cat == SPECIFIER_UINT)) {
657-
/* The size of integral values is the same regardless
658-
* of signedness.
659-
*/
660-
switch (length_mod) {
661-
case LENGTH_NONE:
662-
case LENGTH_HH:
663-
case LENGTH_H:
664-
words += sizeof(int) / sizeof(int);
665-
break;
666-
case LENGTH_L:
667-
words += sizeof(long) / sizeof(int);
668-
break;
669-
case LENGTH_LL:
670-
words += sizeof(long long) / sizeof(int);
671-
break;
672-
case LENGTH_J:
673-
words += sizeof(intmax_t) / sizeof(int);
674-
break;
675-
case LENGTH_Z:
676-
words += sizeof(size_t) / sizeof(int);
677-
break;
678-
case LENGTH_T:
679-
words += sizeof(ptrdiff_t) / sizeof(int);
680-
break;
681-
default:
682-
break;
683-
}
684-
} else if (specifier_cat == SPECIFIER_FP) {
685-
if (length_mod == LENGTH_UPPER_L) {
686-
words += sizeof(long double) / sizeof(int);
687-
} else {
688-
words += sizeof(double) / sizeof(int);
689-
}
690-
} else if (specifier_cat == SPECIFIER_PTR) {
691-
words += sizeof(void *) / sizeof(int);
692-
}
693-
694-
return words;
695-
}
696-
697619
#ifdef CONFIG_64BIT
698620

699621
static void _ldiv5(uint64_t *v)
@@ -1823,20 +1745,3 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fp, va_list ap)
18231745
#undef OUTS
18241746
#undef OUTC
18251747
}
1826-
1827-
size_t cbprintf_arglen(const char *format)
1828-
{
1829-
size_t rv = 0;
1830-
struct conversion conv;
1831-
1832-
while (*format) {
1833-
if (*format == '%') {
1834-
format = extract_conversion(&conv, format);
1835-
rv += conversion_arglen(&conv);
1836-
} else {
1837-
++format;
1838-
}
1839-
}
1840-
1841-
return rv;
1842-
}

lib/os/cbprintf_nano.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -294,22 +294,3 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fmt, va_list ap)
294294

295295
return count;
296296
}
297-
298-
size_t cbprintf_arglen(const char *format)
299-
{
300-
size_t rv = 0;
301-
bool last_pct = false;
302-
303-
while (*format != 0) {
304-
if (*format == '%') {
305-
last_pct = !last_pct;
306-
} else if (last_pct) {
307-
++rv;
308-
last_pct = false;
309-
} else {
310-
}
311-
++format;
312-
}
313-
314-
return rv;
315-
}

tests/unit/cbprintf/main.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -984,36 +984,6 @@ static void test_n(void)
984984
#define EXPECTED_1ARG(_t) (IS_ENABLED(CONFIG_CBPRINTF_NANO) \
985985
? 1U : (sizeof(_t) / sizeof(int)))
986986

987-
static void test_arglen(void)
988-
{
989-
zassert_equal(cbprintf_arglen("/%hhd/"), 1U, NULL);
990-
zassert_equal(cbprintf_arglen("/%hd/"), 1U, NULL);
991-
zassert_equal(cbprintf_arglen("/%d/"), 1U, NULL);
992-
zassert_equal(cbprintf_arglen("/%ld/"),
993-
EXPECTED_1ARG(long), NULL);
994-
zassert_equal(cbprintf_arglen("/%lld/"),
995-
EXPECTED_1ARG(long long), NULL);
996-
zassert_equal(cbprintf_arglen("/%jd/"),
997-
EXPECTED_1ARG(intmax_t), NULL);
998-
zassert_equal(cbprintf_arglen("/%zd/"),
999-
EXPECTED_1ARG(size_t), NULL);
1000-
zassert_equal(cbprintf_arglen("/%td/"),
1001-
EXPECTED_1ARG(ptrdiff_t), NULL);
1002-
zassert_equal(cbprintf_arglen("/%f/"),
1003-
EXPECTED_1ARG(double), NULL);
1004-
zassert_equal(cbprintf_arglen("/%Lf/"),
1005-
EXPECTED_1ARG(long double), NULL);
1006-
zassert_equal(cbprintf_arglen("/%p/"),
1007-
EXPECTED_1ARG(void *), NULL);
1008-
1009-
zassert_equal(cbprintf_arglen("/%%/"), 0U, NULL);
1010-
zassert_equal(cbprintf_arglen("/%*d%/"), 2U, NULL);
1011-
zassert_equal(cbprintf_arglen("/%.*d%/"), 2U, NULL);
1012-
zassert_equal(cbprintf_arglen("/%*.*d%/"),
1013-
IS_ENABLED(CONFIG_CBPRINTF_NANO) ? 2U : 3U,
1014-
NULL);
1015-
}
1016-
1017987
static void test_p(void)
1018988
{
1019989
if (ENABLED_USE_LIBC) {
@@ -1182,7 +1152,6 @@ void test_main(void)
11821152
ztest_unit_test(test_star_precision),
11831153
ztest_unit_test(test_n),
11841154
ztest_unit_test(test_p),
1185-
ztest_unit_test(test_arglen),
11861155
ztest_unit_test(test_libc_substs),
11871156
ztest_unit_test(test_nop)
11881157
);

0 commit comments

Comments
 (0)