Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: math and locale

On Nov 20,  3:18pm, Clint Adams wrote:
} Subject: PATCH: math and locale
} This alleviates the decimal point problem by making it
} locale-independent.  This reverses the previous fix
} which introduced new problems.

Here's the equivalent against 3.1.6-bart-8, for those of you who, like me,
never applied Clint's previous patch and hence don't need to reverse it.

I'm mildly concerned that setting and restoring the locale is an excessive
overhead, especially if it's a no-op (prev_local is already "POSIX" or "C").
Can anyone reassure me?

I also wonder whether "C" would not be a better choice than "POSIX" here.

Index: Src/math.c
@@ -184,6 +184,9 @@
 static int
+#ifdef USE_LOCALE
+    char *prev_locale;
     int cct = 0;
     yyval.type = MN_INTEGER;
@@ -356,7 +359,14 @@
 		if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') {
 		    /* it's a float */
 		    yyval.type = MN_FLOAT;
+#ifdef USE_LOCALE
+		    prev_locale = setlocale(LC_NUMERIC, NULL);
+		    setlocale(LC_NUMERIC, "POSIX");
 		    yyval.u.d = strtod(ptr, &nptr);
+#ifdef USE_LOCALE
+		    setlocale(LC_NUMERIC, prev_locale);
 		    if (ptr == nptr || *nptr == '.') {
 			zerr("bad floating point constant", NULL, 0);
 			return EOI;

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Messages sorted by: Reverse Date, Date, Thread, Author