From 292c9d538173e08b3f9cf76a92bc3f32c98702bb Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 28 Oct 2021 17:54:35 +0200 Subject: [PATCH] Force uselocale if glibc is in use For some reason on a current glibc 2.33, the configure check fails. The man page says we'd have to define XOPEN_SOURCE>=700, but I don't want to do that since it changes a bunch of other things, and it didn't work in my tests. So we just force it, since we know it works (since glibc 2.3). This is a performance difference of ~20% for printf, so it's a reasonably big deal. --- src/builtin_printf.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/builtin_printf.cpp b/src/builtin_printf.cpp index 51b9566c8..460a06819 100644 --- a/src/builtin_printf.cpp +++ b/src/builtin_printf.cpp @@ -751,11 +751,12 @@ maybe_t builtin_printf(parser_t &parser, io_streams_t &streams, const wchar return STATUS_INVALID_ARGS; } -#if defined(HAVE_USELOCALE) +#if defined(HAVE_USELOCALE) || defined(__GLIBC__) // We use a locale-dependent LC_NUMERIC here, // unlike the rest of fish (which uses LC_NUMERIC=C). // Because we do output as well as wcstod (which would have wcstod_l), // we need to set the locale here. + // (glibc has uselocale since 2.3, but our configure checks fail us) locale_t prev_locale = uselocale(fish_numeric_locale()); #else // NetBSD does not have uselocale, @@ -776,7 +777,7 @@ maybe_t builtin_printf(parser_t &parser, io_streams_t &streams, const wchar argv += args_used; } while (args_used > 0 && argc > 0 && !state.early_exit); -#if defined(HAVE_USELOCALE) +#if defined(HAVE_USELOCALE) || defined(__GLIBC__) uselocale(prev_locale); #else setlocale(LC_NUMERIC, prev_locale);