This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use __uselocale in ctype_members.cc


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]