This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Use __uselocale in ctype_members.cc
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Paolo Carlini <pcarlini at unitus dot it>
- Cc: Ulrich Drepper <drepper at redhat dot com>, bkoz at redhat dot com, mark at codesourcery dot com, libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org, roland at redhat dot com
- Date: Mon, 2 Sep 2002 10:19:35 -0400
- Subject: [PATCH] Use __uselocale in ctype_members.cc
- References: <20020830123828.Y1013@sunsite.ms.mff.cuni.cz> <20020901063834.A7920@devserv.devel.redhat.com> <3D71F990.6050000@unitus.it> <3D725033.2060103@redhat.com> <3D7254D5.60201@unitus.it>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Sun, Sep 01, 2002 at 07:56:37PM +0200, Paolo Carlini wrote:
> Ulrich Drepper wrote:
>
> > Paolo Carlini wrote:
> >
> >> I'm not sure about the details, but must probably something must be done
> >> also about the wcsrtombs calls still present in
> >> config/locale/gnu/ctype_members.cc (ctype<wchar_t>::do_narrow),
> >
> > Yes, but this is another issue.
>
> Indeed, mine was just a reminder.
> More generally, I see now that there are various mbsrtowcs calls that
> probably must be fixed too. After Jakub's checkins I volunteer to work
> on those, if nobody beats me.
This is what I found. As ctype<wchar_t> facet does not get the locale name
passed to it (just __c_locale), there is no short fix for glibc before 2.3
I'm afraid (the only one I can think of is query _nl_langinfo_l(CODESET, _M_c_locale_ctype);
and call iconv directly).
There are 2 more wc/mb conversion calls in src/codecvt.cc...
Passes make check on i386-redhat-linux with current CVS glibc.
Ok to commit?
2002-09-02 Jakub Jelinek <jakub@redhat.com>
* config/locale/gnu/ctype_members.cc (ctype<wchar_t>::do_widen(char)):
Switch to _M_c_locale_ctype around btowc call.
(ctype<wchar_t>::do_widen(const char*, const char *, wchar_t*)):
Switch to _M_c_locale_ctype around mbsrtowcs call.
(ctype<wchar_t>::do_narrow(char)): Switch to _M_c_locale_ctype around
wctob call.
(ctype<wchar_t>::do_narrow(const char*, const char *, wchar_t*)):
Switch to _M_c_locale_ctype around wcsrtombs call.
--- libstdc++-v3/config/locale/gnu/ctype_members.cc.jj 2002-08-30 12:09:12.000000000 +0200
+++ libstdc++-v3/config/locale/gnu/ctype_members.cc 2002-09-02 15:25:15.000000000 +0200
@@ -166,15 +166,30 @@ namespace std
wchar_t
ctype<wchar_t>::
do_widen(char __c) const
- { return btowc(__c); }
-
+ {
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+ __c_locale __old = __uselocale(_M_c_locale_ctype);
+#endif
+ wchar_t __ret = btowc(__c);
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+ __uselocale(__old);
+#endif
+ return __ret;
+ }
+
const char*
ctype<wchar_t>::
do_widen(const char* __lo, const char* __hi, wchar_t* __dest) const
{
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+ __c_locale __old = __uselocale(_M_c_locale_ctype);
+#endif
mbstate_t __state;
memset(static_cast<void*>(&__state), 0, sizeof(mbstate_t));
mbsrtowcs(__dest, &__lo, __hi - __lo, &__state);
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+ __uselocale(__old);
+#endif
return __hi;
}
@@ -182,7 +197,13 @@ namespace std
ctype<wchar_t>::
do_narrow(wchar_t __wc, char __dfault) const
{
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+ __c_locale __old = __uselocale(_M_c_locale_ctype);
+#endif
int __c = wctob(__wc);
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+ __uselocale(__old);
+#endif
return (__c == EOF ? __dfault : static_cast<char>(__c));
}
@@ -191,6 +212,9 @@ namespace std
do_narrow(const wchar_t* __lo, const wchar_t* __hi, char __dfault,
char* __dest) const
{
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+ __c_locale __old = __uselocale(_M_c_locale_ctype);
+#endif
size_t __offset = 0;
while (true)
{
@@ -208,6 +232,9 @@ namespace std
else
break;
}
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+ __uselocale(__old);
+#endif
return __hi;
}
#endif // _GLIBCPP_USE_WCHAR_T
Jakub