Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] string_of_float -> float_of_string locale dependency bug
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] string_of_float -> float_of_string locale dependency bug
> Hello!
> /tmp% echo $LANG
> ru_RU.KOI8-R
> /tmp% ocaml -I /usr/local/lib/ocaml/3.07/camomile/ bigarray.cma camomile.cma
>         Objective Caml version 3.07+2
> # float_of_string "0,";;
> - : float = 0.
> # string_of_float 0,;;
> Syntax error
> # string_of_float 0.;;
> Fatal error: exception Failure("float_of_string")

Do you have the same error if you don't load camomile.cma?  From a
quick test here, I believe not.

The Caml runtime system does depend on the LC_NUMERIC locale begin set
to its default value "C", but it ensures that this is the case by never
calling setlocale(LC_ALL, "") nor setlocale(LC_NUMERIC, "").

Third-party libraries can invalidate this invariant by calling e.g.
setlocale(LC_ALL, "").  Two possibilities:

- The library doesn't really need LC_ALL, e.g. it would be enough
  to set LC_CTYPE or LC_COLLATE and leave LC_NUMERIC unchanged.
  In this case, the library should be fixed.

- The library really needs to set LC_NUMERIC, in which case it's
  impossible to use that library with the Caml toplevel.

The C library API for internationalization is largely broken, and as
you can see there is nothing we can do to work around the fact that
the current locale is a global variable for the whole program.

- Xavier Leroy

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: