This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] Another idea for 6015


Hi again,

Ok, in the meanwhile I have learned many things... Unfortunately, it 
turns out that many strategies I had envisaged are completely 
unpractical... Now I got another one ;-)
I summarize the problem. We have this code:

  template<typename _Tv>
    int
    __convert_from_v(char* __out, const int __size, const char* __fmt,
		     _Tv __v, const __c_locale&, int __prec = -1)
    {
      int __ret;
      const char* __old = setlocale(LC_ALL, "C");
      if (__prec >= 0)
        __ret = snprintf(__out, __size, __fmt, __prec, __v);
      else
        __ret = snprintf(__out, __size, __fmt, __v);
      setlocale(LC_ALL, __old);
      return __ret;
    }

which, obviously is not MT-safe. When glibc2.3 will be out it will be 
easy to fix it, but the problems will still be there of glibc2.2 and 
non-glibc systems... We cannot drop supporting them!

I got this idea. It's dirty, I admit, but probably is the easiest to 
implement right now.

After the call to snprintf, on MT systems indeed (all of this may be 
conditionalized to only (MT && !glibc2.3)), we have a c-string __out, 
which possibly may be formatted according to a locale /different/ from 
"C". Ok. What about "cleaning" it? Of course I have to study in detail 
the C-locale documentation, but it should be not that difficult: a scan 
right to left adjusting the decimal separator and removing any thousands 
separators (anything different from a number counts) should be 90% of 
the work...

What do think? It's a bit of an ack, I admit, but it should be the last 
resort when MT && !glibc2.3, and it's feasible right now, it seems to me.

Ciao, P.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]