On 08/06/2012 06:24 AM, Daniel P. Berrange wrote:
On Mon, Aug 06, 2012 at 10:12:17AM +0200, Martin Kletzander wrote:
> libvirt creates invalid commands if wrong locale is selected. For
> example with locale that uses comma as a decimal point, JSON commands
> created with decimal numbers are invalid because comma separates the
> entries in JSON.
>
> But even when decimal point is affected, grouping is not, because for
> grouping to be enabled with *printf, there has to be a apostrophe flag
> specified (and supported).
> ---
> Fortunately, there should be no other place where output-formatting is
> affected by this problem.
>
> I tried to change this in various ways with this posted one being the
> cleanest from my point of view, because:
> - setting locale is per-proccess, not per-thread (not thread-safe)
Actually in glibc there is a per-thread locale:
I agree that we should be using uselocale() where appropriate, rather
than hacking with localeconv()->decimal_point. Also, we need to make
sure that whatever solution we come up with compiles on mingw (I'm
afraid that localeconv()->decimal_point is not portable enough, yet).
GLib has a g_ascii_dtostr() which forces uses of '.' as separator. Since
GLib is LGPLv2+ licensed, we can just copy their impl, which actually
uses GLibc's uselocale() if possible, otherwise has a fallback impl.
gnulib also has a module 'ftoastr' for printing an unambiguous
representation of floating point (one problem with the default precision
of %lf and friends is that it rounds, so more than one floating point
value will result in the same ambiguous output string), but alas that
module is GPL at the moment, and I'm not sure whether it has a way to
force the decimal point issue.
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org