From: Bruno H. <br...@cl...> - 2011-08-24 16:01:59
|
Sam wrote: > BTW, could you please explain this comment: > > /* Given the above, the following line is only needed for those platforms > for which gettext is compiled with HAVE_LOCALE_NULL defined. */ On glibc systems, setlocale(cat,NULL) is known to return a locale string in the expected format, and locales can be created by users. Therefore gettext() uses setlocale(); on the other platforms gettext() relies on the environment variables and the setlocale() call is therefore actually redundant. > also, could you please confirm that this is necessary: > > /* Invalidate the gettext internal caches. */ > textdomain(textdomain(NULL)); textdomain(textdomain(NULL)) has the effect of incrementing the (hidden) variable _nl_msg_cat_cntr. gettext has a cache that stores translations, indexed by (domain, category) pairs. This cache is invalidated when _nl_msg_cat_cntr is incremented. This is necessary when the encoding has changed. > >> setlocale(5, "fr_FR") = NULL > > This explains it. > > what's inexplicable is that the error is silently ignored. The error is silently ignored because the return value of setlocale() is ignored. > >> Apparently because "locale -a" does not list fr_FR. > > > > But it will likely have the locale "fr_FR.UTF-8" (or "fr_FR.utf8" > > which is the name under which it is stored on disk)? > > no, all I have is C, POSIX and a bunch of en_* locales (I am an > English-only bigot, remember? ;-) OK, then my proposed code would not help on your system. But some Linux distros are now shipping only *.UTF-8 locales, no fr_FR locale any more. > so when called during startup it will be a warning, not an error. > My point is that ignoring errors is always wrong. > If setting locale fails, the user should be notified about it OK, fine with me. > At any rate, apparently you do not object to moving init_language past > initmem and letting it indicate a failure as long as it does not prevent > clisp from starting up. I'm not sure there aren't GETTEXT or GETTEXTL calls during initmem or the rest of the start-up. If there are some, it seems safer to me to - continue to call init_language as early as it is now, - but store its result or success in some variable, and - emit the warning message after everything is initialized. > Now, what _is_ a failure? > > 1. setlocale --> NULL Yes, this is a failure. It means the system does not support translations in the specified locale. > 2. textdomain --> NULL ==> errno Indicates a malloc failure. > 3. bindtextdomain --> NULL ==> errno Likewise. > 4. bind_textdomain_codeset --> errno != 0 (may return NULL on success!) This function can fail if malloc fails. I'm not aware that it could return NULL on success. Bruno |