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 <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
0bc01822a2
commit
d12a99588b
4 changed files with 0 additions and 165 deletions
|
@ -69,26 +69,6 @@ typedef int (*cbprintf_cb)(/* int c, void *ctx */);
|
|||
__printf_like(3, 4)
|
||||
int cbprintf(cbprintf_cb out, void *ctx, const char *format, ...);
|
||||
|
||||
/** @brief Calculate the number of words required for arguments to a cbprintf
|
||||
* format specification.
|
||||
*
|
||||
* This can be used in cases where the arguments must be copied off the stack
|
||||
* into separate storage for processing the conversion in another context.
|
||||
*
|
||||
* @note The length returned does not count bytes. It counts native words
|
||||
* defined as the size of an `int`.
|
||||
*
|
||||
* @note If `CONFIG_CBPRINTF_NANO` is selected the count will be incorrect if
|
||||
* any passed arguments require more than one `int`.
|
||||
*
|
||||
* @param format a standard ISO C format string with characters and conversion
|
||||
* specifications.
|
||||
*
|
||||
* @return the number of `int` elements required to provide all arguments
|
||||
* required for the conversion.
|
||||
*/
|
||||
size_t cbprintf_arglen(const char *format);
|
||||
|
||||
/** @brief varargs-aware *printf-like output through a callback.
|
||||
*
|
||||
* This is essentially vsprintf() except the output is generated
|
||||
|
|
|
@ -616,84 +616,6 @@ static inline const char *extract_conversion(struct conversion *conv,
|
|||
return sp;
|
||||
}
|
||||
|
||||
|
||||
/* Get the number of int-sized objects required to provide the arguments for
|
||||
* the conversion.
|
||||
*
|
||||
* This has a role in the logging subsystem where the arguments must
|
||||
* be captured for formatting in another thread.
|
||||
*
|
||||
* If the conversion specifier is invalid the calculated length may
|
||||
* not match what was actually passed as arguments.
|
||||
*/
|
||||
static size_t conversion_arglen(const struct conversion *conv)
|
||||
{
|
||||
enum specifier_cat_enum specifier_cat
|
||||
= (enum specifier_cat_enum)conv->specifier_cat;
|
||||
enum length_mod_enum length_mod
|
||||
= (enum length_mod_enum)conv->length_mod;
|
||||
size_t words = 0;
|
||||
|
||||
/* If the conversion is invalid behavior is undefined. What
|
||||
* this does is try to consume the argument anyway, in hopes
|
||||
* that subsequent valid arguments will format correctly.
|
||||
*/
|
||||
|
||||
/* Percent has no arguments */
|
||||
if (conv->specifier == '%') {
|
||||
return words;
|
||||
}
|
||||
|
||||
if (conv->width_star) {
|
||||
words += sizeof(int) / sizeof(int);
|
||||
}
|
||||
|
||||
if (conv->prec_star) {
|
||||
words += sizeof(int) / sizeof(int);
|
||||
}
|
||||
|
||||
if ((specifier_cat == SPECIFIER_SINT)
|
||||
|| (specifier_cat == SPECIFIER_UINT)) {
|
||||
/* The size of integral values is the same regardless
|
||||
* of signedness.
|
||||
*/
|
||||
switch (length_mod) {
|
||||
case LENGTH_NONE:
|
||||
case LENGTH_HH:
|
||||
case LENGTH_H:
|
||||
words += sizeof(int) / sizeof(int);
|
||||
break;
|
||||
case LENGTH_L:
|
||||
words += sizeof(long) / sizeof(int);
|
||||
break;
|
||||
case LENGTH_LL:
|
||||
words += sizeof(long long) / sizeof(int);
|
||||
break;
|
||||
case LENGTH_J:
|
||||
words += sizeof(intmax_t) / sizeof(int);
|
||||
break;
|
||||
case LENGTH_Z:
|
||||
words += sizeof(size_t) / sizeof(int);
|
||||
break;
|
||||
case LENGTH_T:
|
||||
words += sizeof(ptrdiff_t) / sizeof(int);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (specifier_cat == SPECIFIER_FP) {
|
||||
if (length_mod == LENGTH_UPPER_L) {
|
||||
words += sizeof(long double) / sizeof(int);
|
||||
} else {
|
||||
words += sizeof(double) / sizeof(int);
|
||||
}
|
||||
} else if (specifier_cat == SPECIFIER_PTR) {
|
||||
words += sizeof(void *) / sizeof(int);
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_64BIT
|
||||
|
||||
static void _ldiv5(uint64_t *v)
|
||||
|
@ -1823,20 +1745,3 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fp, va_list ap)
|
|||
#undef OUTS
|
||||
#undef OUTC
|
||||
}
|
||||
|
||||
size_t cbprintf_arglen(const char *format)
|
||||
{
|
||||
size_t rv = 0;
|
||||
struct conversion conv;
|
||||
|
||||
while (*format) {
|
||||
if (*format == '%') {
|
||||
format = extract_conversion(&conv, format);
|
||||
rv += conversion_arglen(&conv);
|
||||
} else {
|
||||
++format;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -294,22 +294,3 @@ still_might_format:
|
|||
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t cbprintf_arglen(const char *format)
|
||||
{
|
||||
size_t rv = 0;
|
||||
bool last_pct = false;
|
||||
|
||||
while (*format != 0) {
|
||||
if (*format == '%') {
|
||||
last_pct = !last_pct;
|
||||
} else if (last_pct) {
|
||||
++rv;
|
||||
last_pct = false;
|
||||
} else {
|
||||
}
|
||||
++format;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -984,36 +984,6 @@ static void test_n(void)
|
|||
#define EXPECTED_1ARG(_t) (IS_ENABLED(CONFIG_CBPRINTF_NANO) \
|
||||
? 1U : (sizeof(_t) / sizeof(int)))
|
||||
|
||||
static void test_arglen(void)
|
||||
{
|
||||
zassert_equal(cbprintf_arglen("/%hhd/"), 1U, NULL);
|
||||
zassert_equal(cbprintf_arglen("/%hd/"), 1U, NULL);
|
||||
zassert_equal(cbprintf_arglen("/%d/"), 1U, NULL);
|
||||
zassert_equal(cbprintf_arglen("/%ld/"),
|
||||
EXPECTED_1ARG(long), NULL);
|
||||
zassert_equal(cbprintf_arglen("/%lld/"),
|
||||
EXPECTED_1ARG(long long), NULL);
|
||||
zassert_equal(cbprintf_arglen("/%jd/"),
|
||||
EXPECTED_1ARG(intmax_t), NULL);
|
||||
zassert_equal(cbprintf_arglen("/%zd/"),
|
||||
EXPECTED_1ARG(size_t), NULL);
|
||||
zassert_equal(cbprintf_arglen("/%td/"),
|
||||
EXPECTED_1ARG(ptrdiff_t), NULL);
|
||||
zassert_equal(cbprintf_arglen("/%f/"),
|
||||
EXPECTED_1ARG(double), NULL);
|
||||
zassert_equal(cbprintf_arglen("/%Lf/"),
|
||||
EXPECTED_1ARG(long double), NULL);
|
||||
zassert_equal(cbprintf_arglen("/%p/"),
|
||||
EXPECTED_1ARG(void *), NULL);
|
||||
|
||||
zassert_equal(cbprintf_arglen("/%%/"), 0U, NULL);
|
||||
zassert_equal(cbprintf_arglen("/%*d%/"), 2U, NULL);
|
||||
zassert_equal(cbprintf_arglen("/%.*d%/"), 2U, NULL);
|
||||
zassert_equal(cbprintf_arglen("/%*.*d%/"),
|
||||
IS_ENABLED(CONFIG_CBPRINTF_NANO) ? 2U : 3U,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void test_p(void)
|
||||
{
|
||||
if (ENABLED_USE_LIBC) {
|
||||
|
@ -1182,7 +1152,6 @@ void test_main(void)
|
|||
ztest_unit_test(test_star_precision),
|
||||
ztest_unit_test(test_n),
|
||||
ztest_unit_test(test_p),
|
||||
ztest_unit_test(test_arglen),
|
||||
ztest_unit_test(test_libc_substs),
|
||||
ztest_unit_test(test_nop)
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue