stdlib: Use __get_numeric_locale instead of __localeconv_l for decimal_point

The string/float conversion functions need to get the locale decimal
point. Instead of calling __localeconv_l (which copies locale data
into lconv form from __get_numeric_locale), use __get_numeric_locale
directly.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2018-09-05 21:25:01 -07:00 committed by Corinna Vinschen
parent 28ecec475f
commit 3b6994ec5f
5 changed files with 14 additions and 13 deletions

View File

@ -149,8 +149,8 @@ gethex (struct _reent *ptr, const char **sp, const FPI *fpi,
int esign, havedig, irv, k, n, nbits, up, zret;
__ULong L, lostbits, *x;
Long e, e1;
unsigned char *decimalpoint = (unsigned char *)
__localeconv_l (loc)->decimal_point;
const unsigned char *decimalpoint = (unsigned char *)
__get_numeric_locale(loc)->decimal_point;
size_t decp_len = strlen ((const char *) decimalpoint);
unsigned char decp_end = decimalpoint[decp_len - 1];

View File

@ -263,8 +263,8 @@ _strtod_l (struct _reent *ptr, const char *__restrict s00, char **__restrict se,
#ifdef Honor_FLT_ROUNDS
int rounding;
#endif
struct lconv *lconv = __localeconv_l (loc);
int dec_len = strlen (lconv->decimal_point);
const char *decimal_point = __get_numeric_locale(loc)->decimal_point;
int dec_len = strlen (decimal_point);
delta = bs = bd = NULL;
sign = nz0 = nz = decpt = 0;
@ -344,7 +344,7 @@ _strtod_l (struct _reent *ptr, const char *__restrict s00, char **__restrict se,
else
z = 10*z + c - '0';
nd0 = nd;
if (strncmp (s, lconv->decimal_point, dec_len) == 0)
if (strncmp (s, decimal_point, dec_len) == 0)
{
decpt = 1;
c = *(s += dec_len);

View File

@ -419,8 +419,8 @@ _strtodg_l (struct _reent *p, const char *s00, char **se, FPI *fpi, Long *exp,
Long L;
__ULong y, z;
_Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0;
struct lconv *lconv = __localeconv_l (loc);
int dec_len = strlen (lconv->decimal_point);
const char *decimal_point = __get_numeric_locale(loc)->decimal_point;
int dec_len = strlen (decimal_point);
irv = STRTOG_Zero;
denorm = sign = nz0 = nz = 0;
@ -479,7 +479,7 @@ _strtodg_l (struct _reent *p, const char *s00, char **se, FPI *fpi, Long *exp,
z = 10*z + c - '0';
nd0 = nd;
#ifdef USE_LOCALE
if (strncmp (s, lconv->decimal_point, dec_len) == 0)
if (strncmp (s, decimal_point, dec_len) == 0)
#else
if (c == '.')
#endif

View File

@ -188,6 +188,7 @@ _wcstod_l (struct _reent *ptr, const wchar_t *nptr, wchar_t **endptr,
* corresponding position in the wide char string.
*/
if (endptr != NULL) {
const char *decimal_point = __get_numeric_locale(loc)->decimal_point;
/* The only valid multibyte char in a float converted by
strtod/wcstod is the radix char. What we do here is,
figure out if the radix char was in the valid leading
@ -198,10 +199,9 @@ _wcstod_l (struct _reent *ptr, const wchar_t *nptr, wchar_t **endptr,
just one byte long. The resulting difference (end - buf)
is then equivalent to the number of valid wide characters
in the input string. */
len = strlen (__localeconv_l (loc)->decimal_point);
len = strlen (decimal_point);
if (len > 1) {
char *d = strstr (buf,
__localeconv_l (loc)->decimal_point);
char *d = strstr (buf, decimal_point);
if (d && d < end)
end -= len - 1;
}

View File

@ -83,6 +83,7 @@ wcstold_l (const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
if (endptr != NULL)
{
const char *decimal_point = __get_numeric_locale(loc)->decimal_point;
/* The only valid multibyte char in a float converted by
strtold/wcstold is the radix char. What we do here is,
figure out if the radix char was in the valid leading
@ -93,10 +94,10 @@ wcstold_l (const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
just one byte long. The resulting difference (end - buf)
is then equivalent to the number of valid wide characters
in the input string. */
len = strlen (__localeconv_l (loc)->decimal_point);
len = strlen (decimal_point);
if (len > 1)
{
char *d = strstr (buf, __localeconv_l (loc)->decimal_point);
char *d = strstr (buf, decimal_point);
if (d && d < end)
end -= len - 1;