bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnulib] Re: Bug in getloadavg


From: Dave Love
Subject: [Bug-gnulib] Re: Bug in getloadavg
Date: Thu, 18 Mar 2004 14:37:48 +0000
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.2 (gnu/linux)

Richard Stallman <address@hidden> writes:

> If he is right, the change of yours installed 2003-06-05
> has a bug.  However, if he is right, the change also is
> unnecessary, and you probably would not have thought it
> was necessary.
>
> Can you explain why you thought it was necessary?

It wasn't strictly necessary.  I was merging the gnulib version, which
is what has the bug.  It should do this (following the example in
libc.info):

--- getloadavg.c~       Wed Sep  3 16:00:11 2003
+++ getloadavg.c        Thu Mar 18 12:35:26 2004
@@ -593,6 +592,7 @@
   char ldavgbuf[40];
   double load_ave[3];
   int fd, count;
+  char *old_locale, *saved_locale;
 
   fd = open (LINUX_LDAV_FILE, O_RDONLY);
   if (fd == -1)
@@ -603,10 +603,14 @@
     return -1;
 
   /* The following sscanf must use the C locale.  */
+  
+  old_locale = setlocale (LC_NUMERIC, NULL);
+  saved_locale = xstrdup (old_locale);
   setlocale (LC_NUMERIC, "C");
   count = sscanf (ldavgbuf, "%lf %lf %lf",
                  &load_ave[0], &load_ave[1], &load_ave[2]);
-  setlocale (LC_NUMERIC, "");
+  setlocale (LC_NUMERIC, saved_locale);
+  xfree (saved_locale);
   if (count < 1)
     return -1;
 
When it's fixed, Emacs should import a fresh copy from gnulib, since
that has had more changes, but I don't have an up-to-date copy, and
subversions won't talk to me.

> Date: Mon, 26 Jan 2004 14:24:21 +0100 (CET)
> From: "address@hidden" <address@hidden>
> To: address@hidden
> Subject: Bug fixup for unneeded setlocale in getloadavg.c
> Reply-To: address@hidden
> Sender: address@hidden
>
>   Hello.
>
>   Firstly, I don't know exactly where I must send this bug correction. 
> So I send it here, I hope it's the correct place.  And I havn't
> subscribe at any list, so please, forward response at <fgeorges AT
> fgeorges.org>, tks.
>
>   The bug is about a recent modiffication of the file
> <src/getloadavg.c>.  Between 1.45 and 1.46 
>
> version (currently, it's the 1.47), the three following lines were
> added (the two first, and the 
>
> last one) (line 605 in the 1.47) :
>
>     /* The following sscanf must use the C locale.  */
>     setlocale (LC_NUMERIC, "C");
>     count = sscanf (...);
>     setlocale (LC_NUMERIC, "");
>
>   But <src/emacs.c> says (line 2175 in 1.330) :
>
>     /* Recover from setlocale (LC_ALL, "").  */
>     void
>     fixup_locale ()
>     {
>       /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
>          so that numbers are read and printed properly for Emacs Lisp. 
> */
>       setlocale (LC_NUMERIC, "C");
>     }
>
> In `main´, we call `setlocale (LC_ALL, "") ;´, and then
> `fixup_locale()´.
>
>   So the code in gatloadavg.c set the locale for Emacs (and for the
> Lisp Printer and the Lisp 
>
> Reader) to the default one.  For example, at home, I have the `$LANG´
> environnement variable set 
>
> to "french".  BOOM !
>
>   I think the fixup is trivial : emacs.c says explicitely that the
> locale for `LC_NUMERIC´ is the 
>
> "C" one, so removing the `setlocale()´ calls from getloadavg.c is all
> we need.
>
>   emacs.c says also, line 1000 in 1.330 :
>
>     /* fixup_locale must wait until later, since it builds strings. */
>
>   Why ?
>
>   Hope it helps,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]