You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Farid Zaripov <Fa...@epam.com> on 2007/10/03 20:23:43 UTC

22.locale.moneypunct test fails on MSVC

  The 22.locale.moneypunct test fails on MSVC (and ICC/Windows)
due to bug of the CRT or native API.

  The following program aborts on assert (tested on all
MSVC's on Windows XP 32 and 64 bit). This program fails
only for some locales. So it fails with locname = "Catalan_Spain.1252"
but succeeds with locname = "Russian_Russia.1251".

-----------------------
#include <clocale>
#include <cstring>
#include <cassert>
#include <cstdio>

int main(int argc, char* argv[])
{
    const char* locname = "Catalan_Spain.1252";

    std::setlocale (LC_ALL, "C");

    std::setlocale (LC_MONETARY, locname);
    const lconv* pconv = std::localeconv ();
    char curr = pconv->currency_symbol [0];

    std::setlocale (LC_ALL, "C");

    std::setlocale (LC_ALL, locname);
    pconv = std::localeconv ();
    char curr2 = pconv->currency_symbol [0];

    std::printf ("curr = %d\n", int (curr));
    std::printf ("curr2 = %d\n", int (curr2));

    assert (curr == curr2);

    return 0;
}  
-----------------------

  The program output:
-----------------------
curr = -120
curr2 = -128
Assertion failed: curr == curr2, file
d:\_projects\locbug\locbug\locbug.cpp, line 29

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.
-----------------------

Farid.

Re: 22.locale.moneypunct test fails on MSVC

Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>> -----Original Message-----
>> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
>> Sent: Wednesday, October 03, 2007 11:21 PM
>> To: stdcxx-dev@incubator.apache.org
>> Subject: Re: 22.locale.moneypunct test fails on MSVC
>>
>> Farid Zaripov wrote:
>>>   The 22.locale.moneypunct test fails on MSVC (and 
>> ICC/Windows) due to 
>>> bug of the CRT or native API.
>>>
>>>   The following program aborts on assert (tested on all MSVC's on 
>>> Windows XP 32 and 64 bit). This program fails only for some 
>> locales. 
>>> So it fails with locname = "Catalan_Spain.1252"
>>> but succeeds with locname = "Russian_Russia.1251".
>> Hmm. That makes the LC_MONETARY category pretty much unusable 
>> on Windows. We need to open a bug with Microsoft and get this 
>> fixed.
> 
>   Now I think that it's not a bug of the MSVC. My system locale is
> Russian_Russia.1251 (codepage = 1251). When LC_MONETARY
> id used, the unicode value of the euro sign is converted into 1251
> codepage (using WideCharToMultiByte() API function). 
> 
>>>From etc/nls/charmaps/CP1251 (/x88 == -120):
> <U20AC>     /x88         EURO SIGN
> 
>   And when LC_ALL is used, the unicode value of the euro sign is
> converted into 1252 codepage.
> 
>>>From etc/nls/charmaps/CP1252 (/x80 == -128):
> <U20AC>     /x80         EURO SIGN
> 
>   The std::moneypunct<> facet uses setlocale (LC_ALL, ) when initializes
> the facet data, so I think the 22.locale.moneypunct.cpp test should use
> setlocale (LC_ALL, ) instead of setlocale (LC_MONETARY, ), or use
> setlocale (LC_CTYPE, ) before setlocale (LC_MONETARY, )..

You might very well be right. LC_MONETARY affects the values
of the punctuators but LC_CTYPE determines their multibyte
encoding.

Martin


RE: 22.locale.moneypunct test fails on MSVC

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Wednesday, October 03, 2007 11:21 PM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: 22.locale.moneypunct test fails on MSVC
> 
> Farid Zaripov wrote:
> >   The 22.locale.moneypunct test fails on MSVC (and 
> ICC/Windows) due to 
> > bug of the CRT or native API.
> > 
> >   The following program aborts on assert (tested on all MSVC's on 
> > Windows XP 32 and 64 bit). This program fails only for some 
> locales. 
> > So it fails with locname = "Catalan_Spain.1252"
> > but succeeds with locname = "Russian_Russia.1251".
> 
> Hmm. That makes the LC_MONETARY category pretty much unusable 
> on Windows. We need to open a bug with Microsoft and get this 
> fixed.

  Now I think that it's not a bug of the MSVC. My system locale is
Russian_Russia.1251 (codepage = 1251). When LC_MONETARY
id used, the unicode value of the euro sign is converted into 1251
codepage (using WideCharToMultiByte() API function). 

>From etc/nls/charmaps/CP1251 (/x88 == -120):
<U20AC>     /x88         EURO SIGN

  And when LC_ALL is used, the unicode value of the euro sign is
converted into 1252 codepage.

>From etc/nls/charmaps/CP1252 (/x80 == -128):
<U20AC>     /x80         EURO SIGN

  The std::moneypunct<> facet uses setlocale (LC_ALL, ) when initializes
the facet data, so I think the 22.locale.moneypunct.cpp test should use
setlocale (LC_ALL, ) instead of setlocale (LC_MONETARY, ), or use
setlocale (LC_CTYPE, ) before setlocale (LC_MONETARY, )..

Farid.

Re: 22.locale.moneypunct test fails on MSVC

Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>   The 22.locale.moneypunct test fails on MSVC (and ICC/Windows)
> due to bug of the CRT or native API.
> 
>   The following program aborts on assert (tested on all
> MSVC's on Windows XP 32 and 64 bit). This program fails
> only for some locales. So it fails with locname = "Catalan_Spain.1252"
> but succeeds with locname = "Russian_Russia.1251".

Hmm. That makes the LC_MONETARY category pretty much unusable
on Windows. We need to open a bug with Microsoft and get this
fixed. But we should also try to work around the bug. Does
using LC_ALL instead of LC_MONETARY work? If not, we might
need to step through their runtime library to see what causes
the bug and try to avoid running into it, maybe by using the
native Win32 API directly.

Martin

> 
> -----------------------
> #include <clocale>
> #include <cstring>
> #include <cassert>
> #include <cstdio>
> 
> int main(int argc, char* argv[])
> {
>     const char* locname = "Catalan_Spain.1252";
> 
>     std::setlocale (LC_ALL, "C");
> 
>     std::setlocale (LC_MONETARY, locname);
>     const lconv* pconv = std::localeconv ();
>     char curr = pconv->currency_symbol [0];
> 
>     std::setlocale (LC_ALL, "C");
> 
>     std::setlocale (LC_ALL, locname);
>     pconv = std::localeconv ();
>     char curr2 = pconv->currency_symbol [0];
> 
>     std::printf ("curr = %d\n", int (curr));
>     std::printf ("curr2 = %d\n", int (curr2));
> 
>     assert (curr == curr2);
> 
>     return 0;
> }  
> -----------------------
> 
>   The program output:
> -----------------------
> curr = -120
> curr2 = -128
> Assertion failed: curr == curr2, file
> d:\_projects\locbug\locbug\locbug.cpp, line 29
> 
> This application has requested the Runtime to terminate it in an unusual
> way.
> Please contact the application's support team for more information.
> -----------------------
> 
> Farid.
>