public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] stdlib: conditionalize locale usage
Date: Mon, 23 Aug 2021 08:03:24 +0000 (GMT)	[thread overview]
Message-ID: <20210823080324.38C5A3858D29@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bc0e8a996110550f65cd356d7da0ba1b5beb243e

commit bc0e8a996110550f65cd356d7da0ba1b5beb243e
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Mon Aug 23 09:56:22 2021 +0200

    stdlib: conditionalize locale usage
    
    _strtod_l as well as the gethex function both fetch the decimal point
    from the current LC_NUMERIC locale info.  This pulls in _C_numeric_locale
    unconditionally even on targets not supporting locales at all.
    
    Another problem is that strtod.c and gdtoa-gethex.c are ELIX 1, while
    locale information in general isn't.  This leads to potential build
    breakage on bare metal targets.
    
    Fix this by setting the decimal point to "." on all targets not
    defining __HAVE_LOCALE_INFO__.
    
    While at it, const'ify the entire local decimal point info in the
    affected functions.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 newlib/libc/stdlib/gdtoa-gethex.c | 12 +++++++++---
 newlib/libc/stdlib/strtod.c       |  7 ++++++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/stdlib/gdtoa-gethex.c b/newlib/libc/stdlib/gdtoa-gethex.c
index 1d3da2889..74f30e690 100644
--- a/newlib/libc/stdlib/gdtoa-gethex.c
+++ b/newlib/libc/stdlib/gdtoa-gethex.c
@@ -149,10 +149,16 @@ 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;
-	const unsigned char *decimalpoint = (unsigned char *)
+#ifdef __HAVE_LOCALE_INFO__
+	const unsigned char *decimalpoint = (const unsigned char *)
 				      __get_numeric_locale(loc)->decimal_point;
-	size_t decp_len = strlen ((const char *) decimalpoint);
-	unsigned char decp_end = decimalpoint[decp_len - 1];
+	const size_t decp_len = strlen ((const char *) decimalpoint);
+	const unsigned char decp_end = decimalpoint[decp_len - 1];
+#else
+	const unsigned char *decimalpoint = (const unsigned char *) ".";
+	const size_t decp_len = 1;
+	const unsigned char decp_end = (unsigned char) '.';
+#endif
 
 	havedig = 0;
 	s0 = *(const unsigned char **)sp + 2;
diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c
index 019416ca7..cd0222481 100644
--- a/newlib/libc/stdlib/strtod.c
+++ b/newlib/libc/stdlib/strtod.c
@@ -263,8 +263,13 @@ _strtod_l (struct _reent *ptr, const char *__restrict s00, char **__restrict se,
 #ifdef Honor_FLT_ROUNDS
 	int rounding;
 #endif
+#ifdef __HAVE_LOCALE_INFO__
 	const char *decimal_point = __get_numeric_locale(loc)->decimal_point;
-	int dec_len = strlen (decimal_point);
+	const int dec_len = strlen (decimal_point);
+#else
+	const char *decimal_point = ".";
+	const int dec_len = 1;
+#endif
 
 	delta = bs = bd = NULL;
 	sign = nz0 = nz = decpt = 0;


                 reply	other threads:[~2021-08-23  8:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210823080324.38C5A3858D29@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).