This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, libfortran] PR 47007, 61847 Locale failures in libgfortran


On Wed, Nov 5, 2014 at 12:48 PM, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> Hi,
>
> the attached patch fixes a few locale related failures in libgfortran,
> in the case where the POSIX 2008 extended locale functionality and
> extensions strto{f,d,ld}_l are present.
>
> These failures typically occur when libgfortran is used from a program
> which has set the locale with setlocale(), and the locale uses a
> different decimal separator than the C locale. The patch fixes this by
> creating a C locale which is then used by strto{f,d,ld}_l, and also is
> installed as the per-thread locale when starting a formatted IO, then
> reset to the previous value when the IO is done. I have chosen to not
> fallback to calling setlocale() in case the POSIX 2008 locale stuff
> isn't available, as that could create nasty hard to debug race
> conditions in a multi-threaded program.
>
> (I think Jerry's proposed patch which checks the locale for the
> decimal separator is still useful as a fallback in case the POSIX 2008
> locale stuff isn't available)

Hi,

updated patch attached. Since the patch sets the per-thread locale
with uselocale, using the non-standard strto{f,d,ld}_l functions isn't
necessary. When getting rid of this part of the original patch, I
noticed a few failures due to the uselocale() calls being in the wrong
places. These are fixed in the updated patch. Also Jakub's suggestion
has been incorporated. Further, investigation revealed that some
targets (Darwin and Freebsd) have the extended locale functionality in
xlocale.h rather than locale.h as POSIX 2008 specifies. So check for
that header. Finally, as we set the per-thread locale to "C", we'd
lose localized error messages. So the updated patch fixes this by
updating the gf_strerror() function as well.

Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

2014-11-06  Janne Blomqvist  <jb@gcc.gnu.org>

    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.
    (st_parameter_dt): Add old_locale member.
    * io/transfer.c (data_transfer_init): Set thread locale to
    c_locale if doing formatted transfer.
    (finalize_transfer): Reset thread locale to previous.
    * io/unit.c (c_locale): New variable.
    (init_units): Init c_locale.
    (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.

-- 
Janne Blomqvist

Attachment: locale.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]