https://gcc.gnu.org/g:f330946fe9ad2fdcd80c6585a4d637f0c5227aa8
commit r17-6538-gf330946fe9ad2fdcd80c6585a4d637f0c5227aa8 Author: Jonathan Yong <[email protected]> Date: Sat Nov 21 02:11:15 2026 +0000 Revert "libgfortran: Copy saved LC_NUMERIC name before switching to "C" [PR128183]" This reverts commit 4ab39ca82231997cd925d4c4e04995e22836119e. Revert accidental push. libgfortran/ChangeLog: * io/transfer.c: Revert. gcc/testsuite/ChangeLog: * gfortran.dg/pr128183.f90: Revert. * gfortran.dg/pr128183_aux.c: Revert. Diff: --- gcc/testsuite/gfortran.dg/pr128183.f90 | 34 ---------------------------- gcc/testsuite/gfortran.dg/pr128183_aux.c | 39 -------------------------------- libgfortran/io/transfer.c | 12 +++------- libgfortran/io/unit.c | 5 ++-- 4 files changed, 5 insertions(+), 85 deletions(-) diff --git a/gcc/testsuite/gfortran.dg/pr128183.f90 b/gcc/testsuite/gfortran.dg/pr128183.f90 deleted file mode 100644 index e663206936ca..000000000000 --- a/gcc/testsuite/gfortran.dg/pr128183.f90 +++ /dev/null @@ -1,34 +0,0 @@ -! { dg-do run } -! { dg-additional-sources pr128183_aux.c } -! -! PR libfortran/128183 -! Formatted I/O must leave a non-"C" LC_NUMERIC unchanged. On targets without -! uselocale (e.g. MinGW-w64), libgfortran used to restore LC_NUMERIC through a -! pointer invalidated by its own setlocale (LC_NUMERIC, "C") call. Targets -! with uselocale never call setlocale during I/O, so on those targets this test -! cannot fail. The ' 1.5' check also catches a missing switch to "C" when the -! chosen locale uses a decimal comma. - -program pr128183 - use iso_c_binding, only: c_int - implicit none - interface - integer(c_int) function set_non_c_locale () bind(C) - import :: c_int - end function set_non_c_locale - integer(c_int) function locale_unchanged () bind(C) - import :: c_int - end function locale_unchanged - end interface - character(len=8) :: buf - integer :: i - - ! Nothing to test if no locale other than "C" is installed. - if (set_non_c_locale () == 0) stop - - do i = 1, 3 - write (buf, '(F4.1)') 1.5 - if (buf /= ' 1.5') stop 1 - if (locale_unchanged () == 0) stop 2 - end do -end program pr128183 diff --git a/gcc/testsuite/gfortran.dg/pr128183_aux.c b/gcc/testsuite/gfortran.dg/pr128183_aux.c deleted file mode 100644 index f35935d64a28..000000000000 --- a/gcc/testsuite/gfortran.dg/pr128183_aux.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Helper for pr128183.f90. */ - -#include <locale.h> -#include <string.h> - -static char saved_name[256]; - -/* Set LC_NUMERIC to an installed locale whose name is not "C". Windows names - come first, since targets without uselocale are mostly MinGW-w64. Return 0 - if there is none. */ - -int -set_non_c_locale (void) -{ - static const char *const names[] = { - "French", "German", "English", "C.UTF-8", "C.utf8", NULL - }; - - for (int i = 0; names[i] != NULL; i++) - { - const char *name = setlocale (LC_NUMERIC, names[i]); - if (name != NULL && strcmp (name, "C") != 0 - && strlen (name) < sizeof saved_name) - { - strcpy (saved_name, name); - return 1; - } - } - return 0; -} - -/* Return 1 if LC_NUMERIC is still the locale set by set_non_c_locale. */ - -int -locale_unchanged (void) -{ - const char *name = setlocale (LC_NUMERIC, NULL); - return name != NULL && strcmp (name, saved_name) == 0; -} diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 2c7992372cec..618c7ef8b60e 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -3757,13 +3757,8 @@ data_transfer_init_worker (st_parameter_dt *dtp, int read_flag) __gthread_mutex_lock (&old_locale_lock); if (!old_locale_ctr++) { - /* The next setlocale call may free this string; keep a copy. */ - const char *cur_locale = setlocale (LC_NUMERIC, NULL); - if (cur_locale != NULL && strcmp (cur_locale, "C") != 0) - { - old_locale = strdup (cur_locale); - setlocale (LC_NUMERIC, "C"); - } + old_locale = setlocale (LC_NUMERIC, NULL); + setlocale (LC_NUMERIC, "C"); } __gthread_mutex_unlock (&old_locale_lock); #endif @@ -4603,10 +4598,9 @@ finalize_transfer (st_parameter_dt *dtp) } #else __gthread_mutex_lock (&old_locale_lock); - if (!--old_locale_ctr && old_locale != NULL) + if (!--old_locale_ctr) { setlocale (LC_NUMERIC, old_locale); - free (old_locale); old_locale = NULL; } __gthread_mutex_unlock (&old_locale_lock); diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c index e0d23be41855..a79ae9d373a0 100644 --- a/libgfortran/io/unit.c +++ b/libgfortran/io/unit.c @@ -139,9 +139,8 @@ locale_t c_locale; traditional setlocale(). To prevent multiple concurrent threads doing formatted I/O from messing up the locale, we need to store a global old_locale, and a counter keeping track of how many threads - are currently doing formatted I/O. The first thread saves a copy of - the old locale name (NULL if it was already "C"), and the last one - restores it. */ + are currently doing formatted I/O. The first thread saves the old + locale, and the last one restores it. */ char *old_locale; int old_locale_ctr; #ifdef __GTHREAD_MUTEX_INIT
