libstdc++/6410: Trouble with non-Ascii monetary symbols and wchar_t
bkoz@gcc.gnu.org
bkoz@gcc.gnu.org
Mon May 6 07:54:00 GMT 2002
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
More information about the Gcc-bugs
mailing list