public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Subject: [PATCH 1/6] reent: Initialize _locale pointer with &__globale_locale
Date: Mon, 13 Nov 2017 15:46:00 -0000	[thread overview]
Message-ID: <20171113154616.25189-2-vinschen@redhat.com> (raw)
In-Reply-To: <20171113154616.25189-1-vinschen@redhat.com>

From: Corinna Vinschen <corinna@vinschen.de>

This simplifies __get_current_locale for usage as an inline function
in the next step.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
---
 newlib/libc/include/sys/reent.h | 5 +++--
 newlib/libc/locale/setlocale.h  | 2 +-
 newlib/libc/locale/uselocale.c  | 4 ++--
 winsup/cygwin/cygtls.cc         | 1 +
 winsup/cygwin/dcrt0.cc          | 1 +
 5 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index c045ca549584..0051b970e087 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -38,6 +38,7 @@ typedef __uint32_t __ULong;
 struct _reent;
 
 struct __locale_t;
+extern struct __locale_t __global_locale;
 
 /*
  * If _REENT_SMALL is defined, we make struct _reent as small as possible,
@@ -431,7 +432,7 @@ extern const struct __sFILE_fake __sf_fake_stderr;
     _NULL, \
     0, \
     0, \
-    _NULL, \
+    &__globale_locale, \
     _NULL, \
     _NULL, \
     0, \
@@ -664,7 +665,7 @@ extern __FILE __sf[3];
     0, \
     "", \
     0, \
-    _NULL, \
+    &__global_locale, \
     0, \
     _NULL, \
     _NULL, \
diff --git a/newlib/libc/locale/setlocale.h b/newlib/libc/locale/setlocale.h
index 85a38d58664f..7f648caafded 100644
--- a/newlib/libc/locale/setlocale.h
+++ b/newlib/libc/locale/setlocale.h
@@ -227,7 +227,7 @@ __get_locale_r (struct _reent *r)
 _ELIDABLE_INLINE struct __locale_t *
 __get_current_locale (void)
 {
-  return _REENT->_locale ?: __get_global_locale ();
+  return _REENT->_locale;
 }
 
 /* Only access fixed "C" locale using this function.  Fake for !_MB_CAPABLE
diff --git a/newlib/libc/locale/uselocale.c b/newlib/libc/locale/uselocale.c
index 810590fc027c..0246f5f0698c 100644
--- a/newlib/libc/locale/uselocale.c
+++ b/newlib/libc/locale/uselocale.c
@@ -61,10 +61,10 @@ _uselocale_r (struct _reent *p, struct __locale_t *newloc)
   struct __locale_t *current_locale;
 
   current_locale = __get_locale_r (p);
-  if (!current_locale)
+  if (!current_locale || current_locale == &__global_locale)
     current_locale = LC_GLOBAL_LOCALE;
   if (newloc == LC_GLOBAL_LOCALE)
-    p->_locale = NULL;
+    p->_locale = &__global_locale;
   else if (newloc)
     p->_locale = newloc;
   return current_locale;
diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc
index 1a2213d1f686..7c5936a109a5 100644
--- a/winsup/cygwin/cygtls.cc
+++ b/winsup/cygwin/cygtls.cc
@@ -64,6 +64,7 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *))
 	  local_clib.__cleanup = _GLOBAL_REENT->__cleanup;
 	  local_clib.__sglue._niobs = 3;
 	  local_clib.__sglue._iobs = &_GLOBAL_REENT->__sf[0];
+	  local_clib._locale = &__global_locale;
 	}
     }
 
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index ea6adcbbd2e5..70198e27453d 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -740,6 +740,7 @@ dll_crt0_0 ()
   _impure_ptr->_stdin = &_impure_ptr->__sf[0];
   _impure_ptr->_stdout = &_impure_ptr->__sf[1];
   _impure_ptr->_stderr = &_impure_ptr->__sf[2];
+  _impure_ptr->_locale = &__global_locale;
   user_data->impure_ptr = _impure_ptr;
   user_data->impure_ptr_ptr = &_impure_ptr;
 
-- 
2.9.5

  parent reply	other threads:[~2017-11-13 15:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-13 15:46 [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
2017-11-13 15:46 ` [PATCH 5/6] Cygwin: cygtls: move local_clib member to start of class Corinna Vinschen
2017-11-13 15:46 ` [PATCH 2/6] newlib: ctype.h: Remove empty #if block Corinna Vinschen
2017-11-13 15:46 ` [PATCH 6/6] Cygwin: ___getreent: Expose assembler inline implementation into userspace Corinna Vinschen
2017-11-13 15:46 ` Corinna Vinschen [this message]
2017-11-13 15:52 ` [PATCH 4/6] Cygwin: expose CYGTLS_PADSIZE as __CYGTLS_PADSIZE in userspace Corinna Vinschen
2017-11-13 15:59 ` [PATCH 3/6] newlib: Expose locale structs and function in new header sys/_locale.h Corinna Vinschen
2017-11-13 20:02 ` [PATCH 0/6] newlib/Cygwin: Allow more inlining of locale_t stuff Corinna Vinschen
2017-11-14  7:56   ` Sebastian Huber
2017-11-14  9:19     ` Corinna Vinschen

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=20171113154616.25189-2-vinschen@redhat.com \
    --to=vinschen@redhat.com \
    --cc=newlib@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).