m4-patches
[Top][All Lists]
Advanced

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

[PATCH] format: force C locale on floating point


From: Eric Blake
Subject: [PATCH] format: force C locale on floating point
Date: Fri, 13 Jan 2023 15:42:06 -0600

A minor release is not the time for format(`%.1f', `4.0') to complain
about 4.0 not being a number followed by outputting "4,0" in locales
where the decimal point is a comma.  Such a change belongs better in a
major release where more thought is put into locale-awareness across
the board.

* src/m4.c (main): Force LC_NUMERIC to c.
Reported-by: Bruno Haible in
https://lists.gnu.org/r/bug-m4/2021-06/msg00021.html
---
 NEWS     | 7 +++++++
 src/m4.c | 4 ++++
 2 files changed, 11 insertions(+)

diff --git a/NEWS b/NEWS
index 577402ad..90d3814b 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,13 @@ GNU M4 NEWS - User visible changes.
    `debugmode(t)') could read invalid memory when tracing a series of
    pushed macros that are popped during argument collection.

+** Fix regression introduced in 1.4.19 where the `format' builtin
+   inadvertently took on locale-dependent parsing and output of floating
+   point numbers as a side-effect of introducing message translations.
+   While it would be nice for m4 to be fully locale-aware, such a behavior
+   change belongs in a major version release such as 1.6, and not a minor
+   release.
+
 * Noteworthy changes in release 1.4.19 (2021-05-28) [stable]

 ** A number of portability improvements inherited from gnulib, including
diff --git a/src/m4.c b/src/m4.c
index 3c43e407..91750aba 100644
--- a/src/m4.c
+++ b/src/m4.c
@@ -419,6 +419,10 @@ main (int argc, char *const *argv)
   set_program_name (argv[0]);
   retcode = EXIT_SUCCESS;
   setlocale (LC_ALL, "");
+  /* m4 1.4.x does not want locale-aware decimal separators in the
+     format builtin; easiest is to override the user's choice of
+     LC_NUMERIC. */
+  setlocale (LC_NUMERIC, "C");
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
   atexit (close_stdin);
-- 
2.39.0




reply via email to

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