While testing a grep snapshot on OpenBSD 6.3, I see a test failure of test-localename. The cause is that in OpenBSD >= 6.2, the locale_t type and uselocale() etc. are now available, but with a terribly dumbed- down implementation that makes it impossible to use these per-thread locales for anything real (including gettext()).
This patch adjusts the gnulib code so that it treats OpenBSD >= 6.2 like the platforms without locale_t and uselocale(). 2018-12-16 Bruno Haible <br...@clisp.org> localename: Fix test failure on OpenBSD >= 6.2. * m4/intl-thread-locale.m4 (gt_INTL_THREAD_LOCALE_NAME): Test for fake locale system. Define HAVE_FAKE_LOCALES in this case. * lib/localename.c (HAVE_GOOD_USELOCALE): New macro. Use it instead of HAVE_USELOCALE. * tests/test-localename.c (HAVE_GOOD_USELOCALE): New macro. Use it instead of HAVE_NEWLOCALE && HAVE_USELOCALE. * doc/posix-functions/uselocale.texi: Mention OpenBSD problem. Update platforms list. * doc/posix-functions/newlocale.texi: Likewise. * doc/posix-functions/duplocale.texi: Update platforms list. * doc/posix-functions/freelocale.texi: Likewise. diff --git a/doc/posix-functions/uselocale.texi b/doc/posix-functions/uselocale.texi index 07711df..2d8b947 100644 --- a/doc/posix-functions/uselocale.texi +++ b/doc/posix-functions/uselocale.texi @@ -14,5 +14,9 @@ Portability problems not fixed by Gnulib: @itemize @item This function is missing on many platforms: -Mac OS X 10.3, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 4.4. +Mac OS X 10.3, FreeBSD 9.0, NetBSD 5.0, OpenBSD 6.1, Minix 3.1.8, AIX 6.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 4.4. +@item +This function is useless because the @code{locale_t} type contains basically +no information on some platforms: +OpenBSD 6.3. @end itemize diff --git a/doc/posix-functions/newlocale.texi b/doc/posix-functions/newlocale.texi index c15b1bd..376f7e8 100644 --- a/doc/posix-functions/newlocale.texi +++ b/doc/posix-functions/newlocale.texi @@ -14,5 +14,9 @@ Portability problems not fixed by Gnulib: @itemize @item This function is missing on many platforms: -Mac OS X 10.3, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 4.4. +Mac OS X 10.3, FreeBSD 9.0, NetBSD 5.0, OpenBSD 6.1, Minix 3.1.8, AIX 6.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 4.4. +@item +This function is useless because the @code{locale_t} type contains basically +no information on some platforms: +OpenBSD 6.3. @end itemize diff --git a/doc/posix-functions/duplocale.texi b/doc/posix-functions/duplocale.texi index a328a67..000300b 100644 --- a/doc/posix-functions/duplocale.texi +++ b/doc/posix-functions/duplocale.texi @@ -21,5 +21,5 @@ Portability problems not fixed by Gnulib: @itemize @item This function is missing on many platforms: -Mac OS X 10.3, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 4.4. +Mac OS X 10.3, FreeBSD 9.0, NetBSD 5.0, OpenBSD 6.1, Minix 3.1.8, AIX 6.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 4.4. @end itemize diff --git a/doc/posix-functions/freelocale.texi b/doc/posix-functions/freelocale.texi index 50e448e..e4ff00f 100644 --- a/doc/posix-functions/freelocale.texi +++ b/doc/posix-functions/freelocale.texi @@ -14,5 +14,5 @@ Portability problems not fixed by Gnulib: @itemize @item This function is missing on many platforms: -Mac OS X 10.3, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 4.4. +Mac OS X 10.3, FreeBSD 9.0, NetBSD 5.0, OpenBSD 6.1, Minix 3.1.8, AIX 6.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 11.3, Cygwin, mingw, MSVC 14, Interix 3.5, BeOS, Android 4.4. @end itemize diff --git a/m4/intl-thread-locale.m4 b/m4/intl-thread-locale.m4 index d7ad0ac..0666e39 100644 --- a/m4/intl-thread-locale.m4 +++ b/m4/intl-thread-locale.m4 @@ -1,4 +1,4 @@ -# intl-thread-locale.m4 serial 2 +# intl-thread-locale.m4 serial 3 dnl Copyright (C) 2015-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -24,6 +24,57 @@ AC_DEFUN([gt_INTL_THREAD_LOCALE_NAME], AC_CHECK_FUNCS_ONCE([uselocale]) + dnl On OpenBSD >= 6.2, the locale_t type and the uselocale(), newlocale(), + dnl duplocale(), freelocale() functions exist but are effectively useless, + dnl because the locale_t value depends only on the LC_CTYPE category of the + dnl locale and furthermore contains only one bit of information (it + dnl distinguishes the "C" locale from the *.UTF-8 locales). See + dnl <https://cvsweb.openbsd.org/src/lib/libc/locale/newlocale.c?rev=1.1&content-type=text/x-cvsweb-markup>. + dnl In the setlocale() implementation they have thought about the programs + dnl that use the API ("Even though only LC_CTYPE has any effect in the + dnl OpenBSD base system, store complete information about the global locale, + dnl such that third-party software can access it"), but for uselocale() + dnl they did not think about the programs. + dnl In this situation, even the HAVE_NAMELESS_LOCALES support does not work. + dnl So, define HAVE_FAKE_LOCALES and disable all locale_t support. + if test $ac_cv_func_uselocale = yes; then + AC_CHECK_HEADERS_ONCE([xlocale.h]) + AC_CACHE_CHECK([for fake locale system (OpenBSD)], + [gt_cv_locale_fake], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include <locale.h> +#if HAVE_XLOCALE_H +# include <xlocale.h> +#endif +int main () +{ + locale_t loc1, loc2; + if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL) return 1; + if (setlocale (LC_ALL, "fr_FR.UTF-8") == NULL) return 1; + loc1 = newlocale (LC_ALL_MASK, "de_DE.UTF-8", (locale_t)0); + loc2 = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", (locale_t)0); + return !(loc1 == loc2); +}]])], + [gt_cv_locale_fake=yes], + [gt_cv_locale_fake=no], + [dnl Guess the locale system is fake only on OpenBSD. + case "$host_os" in + openbsd*) gt_cv_locale_fake="guessing yes" ;; + *) gt_cv_locale_fake="guessing no" ;; + esac + ]) + ]) + else + gt_cv_locale_fake=no + fi + case "$gt_cv_locale_fake" in + *yes) + AC_DEFINE([HAVE_FAKE_LOCALES], [1], + [Define if the locale_t type contains insufficient information, as on OpenBSD.]) + ;; + esac + if test $ac_cv_func_uselocale = yes; then AC_CACHE_CHECK([for Solaris 11.4 locale system], [gt_cv_locale_solaris114], diff --git a/lib/localename.c b/lib/localename.c index aa3cc13..28b3d61 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -35,7 +35,13 @@ #include "flexmember.h" -#if HAVE_USELOCALE +/* We cannot support uselocale() on platforms where the locale_t type is fake. + See intl-thread-locale.m4 for details. */ +#if HAVE_USELOCALE && !HAVE_FAKE_LOCALES +# define HAVE_GOOD_USELOCALE 1 +#endif + +#if HAVE_GOOD_USELOCALE /* Mac OS X 10.5 defines the locale_t type in <xlocale.h>. */ # if defined __APPLE__ && defined __MACH__ # include <xlocale.h> @@ -2623,8 +2629,8 @@ get_lcid (const char *locale_name) #endif -#if HAVE_USELOCALE /* glibc, Mac OS X, FreeBSD >= 9.1, AIX >= 7, - Solaris 11 OpenIndiana, or Solaris >= 11.4 */ +#if HAVE_GOOD_USELOCALE /* glibc, Mac OS X, FreeBSD >= 9.1, AIX >= 7, + Solaris 11 OpenIndiana, or Solaris >= 11.4 */ /* Simple hash set of strings. We don't want to drag in lots of hash table code here. */ @@ -2709,7 +2715,7 @@ struniq (const char *string) #endif -#if HAVE_USELOCALE && HAVE_NAMELESS_LOCALES +#if HAVE_GOOD_USELOCALE && HAVE_NAMELESS_LOCALES /* The 'locale_t' object does not contain the names of the locale categories. We have to associate them with the object through a hash table. @@ -3089,7 +3095,7 @@ freelocale (locale_t locale) #endif -#if defined IN_LIBINTL || HAVE_USELOCALE +#if defined IN_LIBINTL || HAVE_GOOD_USELOCALE /* Like gl_locale_name_thread, except that the result is not in storage of indefinite extent. */ @@ -3099,7 +3105,7 @@ static const char * gl_locale_name_thread_unsafe (int category, const char *categoryname) { -# if HAVE_USELOCALE +# if HAVE_GOOD_USELOCALE { locale_t thread_locale = uselocale (NULL); if (thread_locale != LC_GLOBAL_LOCALE) @@ -3212,7 +3218,7 @@ gl_locale_name_thread_unsafe (int category, const char *categoryname) const char * gl_locale_name_thread (int category, const char *categoryname) { -#if HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE const char *name = gl_locale_name_thread_unsafe (category, categoryname); if (name != NULL) return struniq (name); diff --git a/tests/test-localename.c b/tests/test-localename.c index 4e8d146..8c3c425 100644 --- a/tests/test-localename.c +++ b/tests/test-localename.c @@ -26,8 +26,12 @@ #include "macros.h" +#if HAVE_NEWLOCALE && HAVE_USELOCALE && !HAVE_FAKE_LOCALES +# define HAVE_GOOD_USELOCALE 1 +#endif + -#if HAVE_NEWLOCALE && HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE static struct { int cat; int mask; const char *string; } const categories[] = { @@ -70,7 +74,7 @@ test_locale_name (void) /* Get into a defined state, */ setlocale (LC_ALL, "en_US.UTF-8"); -#if HAVE_NEWLOCALE && HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE uselocale (LC_GLOBAL_LOCALE); #endif @@ -181,7 +185,7 @@ test_locale_name (void) ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); } -#if HAVE_NEWLOCALE && HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE /* Check that gl_locale_name considers the thread locale. */ { locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL); @@ -241,7 +245,7 @@ test_locale_name_thread (void) /* Get into a defined state, */ setlocale (LC_ALL, "en_US.UTF-8"); -#if HAVE_NEWLOCALE && HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE /* Check that gl_locale_name_thread returns NULL when no thread locale is set. */ uselocale (LC_GLOBAL_LOCALE); @@ -496,7 +500,7 @@ test_locale_name_posix (void) /* Get into a defined state, */ setlocale (LC_ALL, "en_US.UTF-8"); -#if HAVE_NEWLOCALE && HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE uselocale (LC_GLOBAL_LOCALE); #endif @@ -605,7 +609,7 @@ test_locale_name_posix (void) ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); } -#if HAVE_NEWLOCALE && HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE /* Check that gl_locale_name_posix ignores the thread locale. */ { locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL); @@ -634,7 +638,7 @@ test_locale_name_environ (void) /* Get into a defined state, */ setlocale (LC_ALL, "en_US.UTF-8"); -#if HAVE_NEWLOCALE && HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE uselocale (LC_GLOBAL_LOCALE); #endif @@ -719,7 +723,7 @@ test_locale_name_environ (void) name = gl_locale_name_environ (LC_MESSAGES, "LC_MESSAGES"); ASSERT (strcmp (name, "fr_FR.UTF-8") == 0); -#if HAVE_NEWLOCALE && HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE /* Check that gl_locale_name_environ ignores the thread locale. */ { locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL); @@ -754,7 +758,7 @@ test_locale_name_default (void) ASSERT (strcmp (name, "C") == 0); #endif -#if HAVE_NEWLOCALE && HAVE_USELOCALE +#if HAVE_GOOD_USELOCALE /* Check that gl_locale_name_default ignores the thread locale. */ { locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", NULL);