public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: bkoz@gcc.gnu.org
To: bkoz@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
	nobody@gcc.gnu.org, pcarlini@unitus.it
Subject: Re: libstdc++/6410: Trouble with non-Ascii monetary symbols and wchar_t
Date: Mon, 06 May 2002 07:54:00 -0000	[thread overview]
Message-ID: <20020506145432.18368.qmail@sources.redhat.com> (raw)

Synopsis: Trouble with non-Ascii monetary symbols and wchar_t

Responsible-Changed-From-To: unassigned->bkoz
Responsible-Changed-By: bkoz
Responsible-Changed-When: Mon May  6 07:54:31 2002
Responsible-Changed-Why:
    Perhaps not really mine, but I'll pretend.
State-Changed-From-To: open->analyzed
State-Changed-By: bkoz
State-Changed-When: Mon May  6 07:54:31 2002
State-Changed-Why:
    According to Ulrich's comments here:
    http://gcc.gnu.org/ml/libstdc++/2002-04/msg00244.html
    
    One solution would be to setlocale to de_DE@euro, for instance, in your testcase.
    
    I tried that, and it didn't work really well. Here's the patch I'm currently using. I don't really like it, one because it breaks the current library API, and two because it's not MT-safe. I think something like this might be useful just to the testsuites can be cleaned up, and then a solution for glibc 2.3/uselocale can be used (which won't break the API for 3.1)
    
    Sound like a plan?
    
    Here's the patch:
    
    2002-05-06  Benjamin Kosnik  <bkoz@redhat.com>
    
    	PR libstdc++/6410
    	* include/bits/locale_facets.h (moneypunct::moneypunct): Add const
    	char* name parameter.
    	* config/locale/gnu/monetary_members.cc: Use it.
    	* src/localename.cc (_Impl::_Impl(const char*, size_t)): Use it.
    
    Index: include/bits/locale_facets.h
    ===================================================================
    RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.h,v
    retrieving revision 1.43
    diff -c -p -r1.43 locale_facets.h
    *** include/bits/locale_facets.h	16 Apr 2002 00:45:25 -0000	1.43
    --- include/bits/locale_facets.h	6 May 2002 14:49:05 -0000
    *************** namespace std
    *** 1357,1364 ****
            { _M_initialize_moneypunct(); }
      
            explicit 
    !       moneypunct(__c_locale __cloc, size_t __refs = 0) : locale::facet(__refs)
    !       { _M_initialize_moneypunct(__cloc); }
      
            char_type
            decimal_point() const
    --- 1357,1365 ----
            { _M_initialize_moneypunct(); }
      
            explicit 
    !       moneypunct(__c_locale __cloc, const char* __name, size_t __refs = 0) 
    !       : locale::facet(__refs)
    !       { _M_initialize_moneypunct(__cloc, __name); }
      
            char_type
            decimal_point() const
    *************** namespace std
    *** 1438,1444 ****
      
            // For use at construction time only.
             void 
    !        _M_initialize_moneypunct(__c_locale __cloc = _S_c_locale);
          };
      
        template<typename _CharT, bool _Intl>
    --- 1439,1446 ----
      
            // For use at construction time only.
             void 
    !        _M_initialize_moneypunct(__c_locale __cloc = _S_c_locale, 
    ! 				const char* __name = NULL);
          };
      
        template<typename _CharT, bool _Intl>
    *************** namespace std
    *** 1455,1465 ****
      
        template<> 
          void
    !     moneypunct<char, true>::_M_initialize_moneypunct(__c_locale __cloc);
      
        template<> 
          void
    !     moneypunct<char, false>::_M_initialize_moneypunct(__c_locale __cloc);
      
      #ifdef _GLIBCPP_USE_WCHAR_T
        template<>
    --- 1457,1467 ----
      
        template<> 
          void
    !     moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*);
      
        template<> 
          void
    !     moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);
      
      #ifdef _GLIBCPP_USE_WCHAR_T
        template<>
    *************** namespace std
    *** 1470,1480 ****
      
        template<> 
          void
    !     moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale __cloc);
      
        template<> 
          void
    !     moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale __cloc);
      #endif
      
        template<typename _CharT, bool _Intl>
    --- 1472,1484 ----
      
        template<> 
          void
    !     moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale, 
    ! 							const char*);
      
        template<> 
          void
    !     moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale, 
    ! 							 const char*);
      #endif
      
        template<typename _CharT, bool _Intl>
    Index: config/locale/gnu/monetary_members.cc
    ===================================================================
    RCS file: /cvs/gcc/gcc/libstdc++-v3/config/locale/gnu/monetary_members.cc,v
    retrieving revision 1.2
    diff -c -p -r1.2 monetary_members.cc
    *** config/locale/gnu/monetary_members.cc	16 Apr 2002 00:45:18 -0000	1.2
    --- config/locale/gnu/monetary_members.cc	6 May 2002 14:49:06 -0000
    *************** namespace std
    *** 216,222 ****
      
        template<> 
          void
    !     moneypunct<char, true>::_M_initialize_moneypunct(__c_locale __cloc)
          {
            if (__cloc == _S_c_locale)
      	{
    --- 216,223 ----
      
        template<> 
          void
    !     moneypunct<char, true>::_M_initialize_moneypunct(__c_locale __cloc, 
    ! 						     const char*)
          {
            if (__cloc == _S_c_locale)
      	{
    *************** namespace std
    *** 260,266 ****
      
        template<> 
          void
    !     moneypunct<char, false>::_M_initialize_moneypunct(__c_locale __cloc)
          {
            if (__cloc == _S_c_locale)
      	{
    --- 261,268 ----
      
        template<> 
          void
    !     moneypunct<char, false>::_M_initialize_moneypunct(__c_locale __cloc, 
    ! 						      const char*)
          {
            if (__cloc == _S_c_locale)
      	{
    *************** namespace std
    *** 313,319 ****
      #ifdef _GLIBCPP_USE_WCHAR_T
        template<> 
          void
    !     moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale __cloc)
          {
            if (__cloc == _S_c_locale)
      	{
    --- 315,322 ----
      #ifdef _GLIBCPP_USE_WCHAR_T
        template<> 
          void
    !     moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale __cloc, 
    ! 							const char* __name)
          {
            if (__cloc == _S_c_locale)
      	{
    *************** namespace std
    *** 331,336 ****
    --- 334,343 ----
            else
      	{
      	  // Named locale.
    + 	  // XXX Fix me. Switch to named locale so that mbsrtowcs will work.
    + 	  char* __old = strdup(setlocale(LC_ALL, NULL));
    + 	  setlocale(LC_ALL, __name);
    + 
      	  _M_decimal_point = static_cast<wchar_t>(((union { const char *__s; unsigned int __w; }){ __s: __nl_langinfo_l(_NL_NUMERIC_DECIMAL_POINT_WC, __cloc)}).__w);
      
      	  _M_thousands_sep = static_cast<wchar_t>(((union { const char *__s; unsigned int __w; }){ __s: __nl_langinfo_l(_NL_NUMERIC_THOUSANDS_SEP_WC, __cloc)}).__w);
    *************** namespace std
    *** 391,402 ****
      	  char __nprecedes = *(__nl_langinfo_l(__INT_N_CS_PRECEDES, __cloc));
      	  char __nspace = *(__nl_langinfo_l(__INT_N_SEP_BY_SPACE, __cloc));
      	  _M_neg_format = _S_construct_pattern(__nprecedes, __nspace, __nposn);
      	}
          }
      
        template<> 
          void
    !     moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale __cloc)
          {
            if (__cloc == _S_c_locale)
      	{
    --- 398,414 ----
      	  char __nprecedes = *(__nl_langinfo_l(__INT_N_CS_PRECEDES, __cloc));
      	  char __nspace = *(__nl_langinfo_l(__INT_N_SEP_BY_SPACE, __cloc));
      	  _M_neg_format = _S_construct_pattern(__nprecedes, __nspace, __nposn);
    + 
    + 	  // XXX
    + 	  setlocale(LC_ALL, __old);
    + 	  free(__old);
      	}
          }
      
        template<> 
          void
    !     moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale __cloc, 
    ! 							 const char* __name)
          {
            if (__cloc == _S_c_locale)
      	{
    *************** namespace std
    *** 414,419 ****
    --- 426,435 ----
            else
      	{
      	  // Named locale.
    + 	  // XXX Fix me. Switch to named locale so that mbsrtowcs will work.
    + 	  char* __old = strdup(setlocale(LC_ALL, NULL));
    + 	  setlocale(LC_ALL, __name);
    + 
      	  _M_decimal_point = static_cast<wchar_t>(((union { const char *__s; unsigned int __w; }){ __s: __nl_langinfo_l(_NL_NUMERIC_DECIMAL_POINT_WC, __cloc)}).__w);
      	  _M_thousands_sep = static_cast<wchar_t>(((union { const char *__s; unsigned int __w; }){ __s: __nl_langinfo_l(_NL_NUMERIC_THOUSANDS_SEP_WC, __cloc)}).__w);
      	  _M_grouping = __nl_langinfo_l(GROUPING, __cloc);
    *************** namespace std
    *** 473,478 ****
    --- 489,498 ----
      	  char __nprecedes = *(__nl_langinfo_l(__N_CS_PRECEDES, __cloc));
      	  char __nspace = *(__nl_langinfo_l(__N_SEP_BY_SPACE, __cloc));
      	  _M_neg_format = _S_construct_pattern(__nprecedes, __nspace, __nposn);
    + 
    + 	  // XXX
    + 	  setlocale(LC_ALL, __old);
    + 	  free(__old);
      	}
          }
      
    Index: src/localename.cc
    ===================================================================
    RCS file: /cvs/gcc/gcc/libstdc++-v3/src/localename.cc,v
    retrieving revision 1.26
    diff -c -p -r1.26 localename.cc
    *** src/localename.cc	16 Apr 2002 00:45:32 -0000	1.26
    --- src/localename.cc	6 May 2002 14:49:06 -0000
    *************** namespace std
    *** 132,139 ****
          _M_init_facet(new num_get<char>);
          _M_init_facet(new num_put<char>);
          _M_init_facet(new std::collate<char>(__cloc));
    !     _M_init_facet(new moneypunct<char, false>(__cloc));
    !     _M_init_facet(new moneypunct<char, true>(__cloc));
          _M_init_facet(new money_get<char>);
          _M_init_facet(new money_put<char>);
          _M_init_facet(new __timepunct<char>(__cloc, __s));
    --- 132,139 ----
          _M_init_facet(new num_get<char>);
          _M_init_facet(new num_put<char>);
          _M_init_facet(new std::collate<char>(__cloc));
    !     _M_init_facet(new moneypunct<char, false>(__cloc, __s));
    !     _M_init_facet(new moneypunct<char, true>(__cloc, __s));
          _M_init_facet(new money_get<char>);
          _M_init_facet(new money_put<char>);
          _M_init_facet(new __timepunct<char>(__cloc, __s));
    *************** namespace std
    *** 148,155 ****
          _M_init_facet(new num_get<wchar_t>);
          _M_init_facet(new num_put<wchar_t>);
          _M_init_facet(new std::collate<wchar_t>(__cloc));
    !     _M_init_facet(new moneypunct<wchar_t, false>(__cloc));
    !     _M_init_facet(new moneypunct<wchar_t, true>(__cloc));
          _M_init_facet(new money_get<wchar_t>);
          _M_init_facet(new money_put<wchar_t>);
          _M_init_facet(new __timepunct<wchar_t>(__cloc, __s));
    --- 148,155 ----
          _M_init_facet(new num_get<wchar_t>);
          _M_init_facet(new num_put<wchar_t>);
          _M_init_facet(new std::collate<wchar_t>(__cloc));
    !     _M_init_facet(new moneypunct<wchar_t, false>(__cloc, __s));
    !     _M_init_facet(new moneypunct<wchar_t, true>(__cloc, __s));
          _M_init_facet(new money_get<wchar_t>);
          _M_init_facet(new money_put<wchar_t>);
          _M_init_facet(new __timepunct<wchar_t>(__cloc, __s));

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6410


             reply	other threads:[~2002-05-06 14:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-06  7:54 bkoz [this message]
2002-05-06  8:16 Paolo Carlini
2002-05-13  5:56 Paolo Carlini
2002-07-03  9:13 bkoz
2002-10-27  3:06 paolo

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=20020506145432.18368.qmail@sources.redhat.com \
    --to=bkoz@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    --cc=gcc-gnats@gcc.gnu.org \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    --cc=pcarlini@unitus.it \
    /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).