This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH 1/6] reent: Initialize _locale pointer with &__globale_locale
- From: Corinna Vinschen <vinschen at redhat dot com>
- To: newlib at sourceware dot org
- Date: Mon, 13 Nov 2017 16:46:11 +0100
- Subject: [PATCH 1/6] reent: Initialize _locale pointer with &__globale_locale
- Authentication-results: sourceware.org; auth=none
- References: <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