From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18430 invoked by alias); 6 May 2002 14:54:36 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 18369 invoked by uid 61); 6 May 2002 14:54:32 -0000 Date: Mon, 06 May 2002 07:54:00 -0000 Message-ID: <20020506145432.18368.qmail@sources.redhat.com> To: bkoz@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, pcarlini@unitus.it From: bkoz@gcc.gnu.org Reply-To: bkoz@gcc.gnu.org, bkoz@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, pcarlini@unitus.it, gcc-gnats@gcc.gnu.org Subject: Re: libstdc++/6410: Trouble with non-Ascii monetary symbols and wchar_t X-SW-Source: 2002-05/txt/msg00151.txt.bz2 List-Id: 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 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 --- 1439,1446 ---- // For use at construction time only. void ! _M_initialize_moneypunct(__c_locale __cloc = _S_c_locale, ! const char* __name = NULL); }; template *************** namespace std *** 1455,1465 **** template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale __cloc); template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale __cloc); #ifdef _GLIBCPP_USE_WCHAR_T template<> --- 1457,1467 ---- template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale, const char*); template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale, const char*); #ifdef _GLIBCPP_USE_WCHAR_T template<> *************** namespace std *** 1470,1480 **** template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale __cloc); template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale __cloc); #endif template --- 1472,1484 ---- template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale, ! const char*); template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale, ! const char*); #endif template 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::_M_initialize_moneypunct(__c_locale __cloc) { if (__cloc == _S_c_locale) { --- 216,223 ---- template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale __cloc, ! const char*) { if (__cloc == _S_c_locale) { *************** namespace std *** 260,266 **** template<> void ! moneypunct::_M_initialize_moneypunct(__c_locale __cloc) { if (__cloc == _S_c_locale) { --- 261,268 ---- template<> void ! moneypunct::_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::_M_initialize_moneypunct(__c_locale __cloc) { if (__cloc == _S_c_locale) { --- 315,322 ---- #ifdef _GLIBCPP_USE_WCHAR_T template<> void ! moneypunct::_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(((union { const char *__s; unsigned int __w; }){ __s: __nl_langinfo_l(_NL_NUMERIC_DECIMAL_POINT_WC, __cloc)}).__w); _M_thousands_sep = static_cast(((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::_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::_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(((union { const char *__s; unsigned int __w; }){ __s: __nl_langinfo_l(_NL_NUMERIC_DECIMAL_POINT_WC, __cloc)}).__w); _M_thousands_sep = static_cast(((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); _M_init_facet(new num_put); _M_init_facet(new std::collate(__cloc)); ! _M_init_facet(new moneypunct(__cloc)); ! _M_init_facet(new moneypunct(__cloc)); _M_init_facet(new money_get); _M_init_facet(new money_put); _M_init_facet(new __timepunct(__cloc, __s)); --- 132,139 ---- _M_init_facet(new num_get); _M_init_facet(new num_put); _M_init_facet(new std::collate(__cloc)); ! _M_init_facet(new moneypunct(__cloc, __s)); ! _M_init_facet(new moneypunct(__cloc, __s)); _M_init_facet(new money_get); _M_init_facet(new money_put); _M_init_facet(new __timepunct(__cloc, __s)); *************** namespace std *** 148,155 **** _M_init_facet(new num_get); _M_init_facet(new num_put); _M_init_facet(new std::collate(__cloc)); ! _M_init_facet(new moneypunct(__cloc)); ! _M_init_facet(new moneypunct(__cloc)); _M_init_facet(new money_get); _M_init_facet(new money_put); _M_init_facet(new __timepunct(__cloc, __s)); --- 148,155 ---- _M_init_facet(new num_get); _M_init_facet(new num_put); _M_init_facet(new std::collate(__cloc)); ! _M_init_facet(new moneypunct(__cloc, __s)); ! _M_init_facet(new moneypunct(__cloc, __s)); _M_init_facet(new money_get); _M_init_facet(new money_put); _M_init_facet(new __timepunct(__cloc, __s)); http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6410