From 3b6994ec5f5fb47ba87fb3dae154cad21017b30d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 5 Sep 2018 21:25:01 -0700 Subject: [PATCH] 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 --- newlib/libc/stdlib/gdtoa-gethex.c | 4 ++-- newlib/libc/stdlib/strtod.c | 6 +++--- newlib/libc/stdlib/strtodg.c | 6 +++--- newlib/libc/stdlib/wcstod.c | 6 +++--- newlib/libc/stdlib/wcstold.c | 5 +++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/newlib/libc/stdlib/gdtoa-gethex.c b/newlib/libc/stdlib/gdtoa-gethex.c index d160015e2..e0c2fff5e 100644 --- a/newlib/libc/stdlib/gdtoa-gethex.c +++ b/newlib/libc/stdlib/gdtoa-gethex.c @@ -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]; diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c index 2a76b10ce..8bb75ef0a 100644 --- a/newlib/libc/stdlib/strtod.c +++ b/newlib/libc/stdlib/strtod.c @@ -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); diff --git a/newlib/libc/stdlib/strtodg.c b/newlib/libc/stdlib/strtodg.c index c8e581cb7..013315946 100644 --- a/newlib/libc/stdlib/strtodg.c +++ b/newlib/libc/stdlib/strtodg.c @@ -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 diff --git a/newlib/libc/stdlib/wcstod.c b/newlib/libc/stdlib/wcstod.c index 810c5b3fd..375ffe288 100644 --- a/newlib/libc/stdlib/wcstod.c +++ b/newlib/libc/stdlib/wcstod.c @@ -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; } diff --git a/newlib/libc/stdlib/wcstold.c b/newlib/libc/stdlib/wcstold.c index 4876e119b..673d92811 100644 --- a/newlib/libc/stdlib/wcstold.c +++ b/newlib/libc/stdlib/wcstold.c @@ -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;