[RFC] PR6015, snprintf, glibc2.3 and all that...
Paolo Carlini
pcarlini@unitus.it
Thu Apr 4 01:34:00 GMT 2002
Ulrich Drepper wrote:
>>Is there a general "philosophical" point about this which you can
>>possibly explain to me?
>>
>
>I don't know what you mean. We will have the uselocale() stuff in glibc
>2.3. Until then the locale model is basically broken by design wrt
>threads and since the locale data must be used by all the variouses
>interfaces of the libc it also means that those interfaces are also
>broken wrt threads. Everybody who has to do with locales knows this.
>It's just that nobody took the initiative to fix this. The uselocale()
>stuff has a good chance of getting wider acceptance.
>
Yes. And of course v3 will use it on platforms which have glibc
installed. But consider all the others... In order to have MT-safe
output operations we don't really need a full printf locale sensitive.
We just need a /basic/ printing facility which only knows about
"C"-locale. I can only agree with you that locales are broken vs
MT-threading, but really we don't need them /at all/ for Stage1 of
number formatting according to the C++ standard. As I wrote elsewhere,
the scheme proposed by Benjamin:
template<typename _Tv>
int
__convert_from_v(char* __out, const int __size, const char* __fmt,
_Tv __v, const __c_locale& __cloc, int __prec = -1)
{
int __ret;
__c_locale __old = __uselocale(__cloc);
if (__prec >= 0)
__ret = snprintf(__out, __size, __fmt, __prec, __v);
else
__ret = snprintf(__out, __size, __fmt, __v);
__uselocale(__old);
return __ret;
}
is cute, nice, MT-safe, and it will work (with glibc2.3) but I'm still
getting a feeling of "overkilling"... Don't you?
Ciao, P.
More information about the Libstdc++
mailing list