From 9cbecd06be8bba398595990b0ecb4156d4a19aad Mon Sep 17 00:00:00 2001 From: Janne Blomqvist Date: Mon, 10 Nov 2014 02:17:16 +0200 Subject: PR 47007 and 61847 Locale failures in libgfortran. 2014-11-10 Janne Blomqvist PR libfortran/47007 PR libfortran/61847 * config.h.in: Regenerated. * configure: Regenerated. * configure.ac (AC_CHECK_HEADERS_ONCE): Check for xlocale.h. (AC_CHECK_FUNCS_ONCE): Check for newlocale, freelocale, uselocale, strerror_l. * io/io.h (locale.h): Include. (xlocale.h): Include if present. (c_locale): New variable. (old_locale): New variable. (old_locale_ctr): New variable. (old_locale_lock): New variable. (st_parameter_dt): Add old_locale member. * io/transfer.c (data_transfer_init): Set locale to "C" if doing formatted transfer. (finalize_transfer): Reset locale to previous. * io/unit.c (c_locale): New variable. (old_locale): New variable. (old_locale_ctr): New variable. (old_locale_lock): New variable. (init_units): Init c_locale, init old_locale_lock. (close_units): Free c_locale. * runtime/error.c (locale.h): Include. (xlocale.h): Include if present. (gf_strerror): Use strerror_l if available. Reset locale to LC_GLOBAL_LOCALE for strerror_r branch. 2014-11-10 Janne Blomqvist PR libfortran/47007 PR libfortran/61847 * gfortran.texi: Add note about locale issues to thread-safety section. From-SVN: r217273 --- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/gfortran.texi | 24 ++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'gcc/fortran') diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 3a8e658ee86..576e69407f1 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2014-11-10 Janne Blomqvist + + PR libfortran/47007 + PR libfortran/61847 + * gfortran.texi: Add note about locale issues to thread-safety + section. + 2014-11-04 Bernd Schmidt * f95-lang.c (gfc_init_builtin_functions): Use type index 2 for diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index 41d6559fab0..0d19e7a2b3a 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -1223,10 +1223,26 @@ implemented with the @code{system} function, which need not be thread-safe. It is the responsibility of the user to ensure that @code{system} is not called concurrently. -Finally, for platforms not supporting thread-safe POSIX functions, -further functionality might not be thread-safe. For details, please -consult the documentation for your operating system. - +For platforms not supporting thread-safe POSIX functions, further +functionality might not be thread-safe. For details, please consult +the documentation for your operating system. + +The GNU Fortran runtime library uses various C library functions that +depend on the locale, such as @code{strtod} and @code{snprintf}. In +order to work correctly in locale-aware programs that set the locale +using @code{setlocale}, the locale is reset to the default ``C'' +locale while executing a formatted @code{READ} or @code{WRITE} +statement. On targets supporting the POSIX 2008 per-thread locale +functions (e.g. @code{newlocale}, @code{uselocale}, +@code{freelocale}), these are used and thus the global locale set +using @code{setlocale} or the per-thread locales in other threads are +not affected. However, on targets lacking this functionality, the +global LC_NUMERIC locale is set to ``C'' during the formatted I/O. +Thus, on such targets it's not safe to call @code{setlocale} +concurrently from another thread while a Fortran formatted I/O +operation is in progress. Also, other threads doing something +dependent on the LC_NUMERIC locale might not work correctly if a +formatted I/O operation is in progress in another thread. @node Data consistency and durability @section Data consistency and durability -- cgit v1.2.1