1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

Remove duplicated code from __printf_fp_l, __printf_fphex, and __printf_size

In __printf_fp_l, __printf_fphex, and __printf_size the blocks of code that are
used to read a double or long double argument, check for special values and
convert to multiprecision are similar.  When adding float128 support to libc,
more code would be duplicated to deal with the extra type.  This patch moves
the repetitive code to a macro which is now used by double and long double and
will be used for float128 when support is added, thus avoiding more
duplication.

Tested for powerpc64le and s390x.

	* stdio-common/printf_fp.c (PRINTF_FP_FETCH): New macro.
	(__printf_fp_l): Use the new macro to avoid duplicating code.
	* stdio-common/printf_fphex.c (PRINTF_FPHEX_FETCH): New macro.
	(__printf_fphex): Use the new macro to avoid duplicating code.
	* stdio-common/printf_size.c (PRINTF_SIZE_FETCH): New macro.
	(__printf_size): Use the new macro to avoid duplicating code.
This commit is contained in:
Gabriel F. T. Gomes
2017-05-29 10:49:42 -03:00
parent 32bf1d09da
commit aab0f374e7
4 changed files with 125 additions and 199 deletions

View File

@ -157,82 +157,52 @@ __printf_fphex (FILE *fp,
/* The decimal point character must never be zero. */
assert (*decimal != '\0' && decimalwc != L'\0');
#define PRINTF_FPHEX_FETCH(FLOAT, VAR) \
{ \
(VAR) = *(const FLOAT *) args[0]; \
\
/* Check for special values: not a number or infinity. */ \
if (isnan (VAR)) \
{ \
if (isupper (info->spec)) \
{ \
special = "NAN"; \
wspecial = L"NAN"; \
} \
else \
{ \
special = "nan"; \
wspecial = L"nan"; \
} \
} \
else \
{ \
if (isinf (VAR)) \
{ \
if (isupper (info->spec)) \
{ \
special = "INF"; \
wspecial = L"INF"; \
} \
else \
{ \
special = "inf"; \
wspecial = L"inf"; \
} \
} \
} \
negative = signbit (VAR); \
}
/* Fetch the argument value. */
#ifndef __NO_LONG_DOUBLE_MATH
if (info->is_long_double && sizeof (long double) > sizeof (double))
{
fpnum.ldbl = *(const long double *) args[0];
/* Check for special values: not a number or infinity. */
if (isnan (fpnum.ldbl))
{
if (isupper (info->spec))
{
special = "NAN";
wspecial = L"NAN";
}
else
{
special = "nan";
wspecial = L"nan";
}
}
else
{
if (isinf (fpnum.ldbl))
{
if (isupper (info->spec))
{
special = "INF";
wspecial = L"INF";
}
else
{
special = "inf";
wspecial = L"inf";
}
}
}
negative = signbit (fpnum.ldbl);
}
PRINTF_FPHEX_FETCH (long double, fpnum.ldbl)
else
#endif /* no long double */
{
fpnum.dbl.d = *(const double *) args[0];
#endif
PRINTF_FPHEX_FETCH (double, fpnum.dbl.d)
/* Check for special values: not a number or infinity. */
if (isnan (fpnum.dbl.d))
{
if (isupper (info->spec))
{
special = "NAN";
wspecial = L"NAN";
}
else
{
special = "nan";
wspecial = L"nan";
}
}
else
{
if (isinf (fpnum.dbl.d))
{
if (isupper (info->spec))
{
special = "INF";
wspecial = L"INF";
}
else
{
special = "inf";
wspecial = L"inf";
}
}
}
negative = signbit (fpnum.dbl.d);
}
#undef PRINTF_FPHEX_FETCH
if (special)
{