using xlocale to implement std::locale class

Sam Varshavchik mrsam@courier-mta.com
Wed May 4 11:20:00 GMT 2011


Jonathan Wakely writes:

> On 4 May 2011 07:07, Marc Glisse wrote:
> > On Wed, 4 May 2011, Takeshi Kobayakawa wrote:
> >
> >> Are there any effort to handle std::locale class with xlocale(extended
> >> locale support)? (here, xlocale.h has nothing to do with XLib' Xlocale.h)
> >
> > There has been for a while, in libstdc++-v3/config/locale/gnu/.
> >
> >> I am a navite linux programmers, but when I tried to port my code to
> >> darwin(MacOSX), I found one can not create locale object other than "C"
> >> locale. The libstdc++ seems to deal with darwin, so I would like to see
> >> std::locale object working better on darwin.
> >
> > I didn't know things were that bad...
>
> Locales need a lot of work everywhere except GNU/Linux.  There are
> thread safety issues, 64-bit issues, and failures to handle some
> wchar_t character classes on some platforms.

The messages facet is broken everywhere, including GNU/Linux. do_open()  
calls textdomain(), which sets the global message catalog domain, and  
do_get() calls gettext(), which uses the global message catalog domain.

Try to instantiate a second messages facet for a different catalog, then  
your first messages facet instance (whether it was open in the same thread  
or a different thread) is now bricked.

This effectively means that shared libraries cannot use the C++ library  
messages facet to access a message catalog for their own domain, because that  
would break the main app, if it also uses the messages facet.

The messages facet should not call textdomain(), but save the catalog name  
in a class member, and do_get() should use the thread-safe dgettext(),  
without stomping the global message catalog.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20110504/27a21382/attachment.sig>


More information about the Libstdc++ mailing list