changeset 39947:9912dc28baf1

localename: Simplify support for per-thread locales on Solaris 11.4. * m4/intl-thread-locale.m4: Renamed from m4/intlsolaris.m4. (gt_INTL_THREAD_LOCALE_NAME): Renamed from gt_INTL_SOLARIS. Define HAVE_SOLARIS114_LOCALES instead of HAVE_NAMELESS_LOCALES. * lib/localename.c: Handle HAVE_SOLARIS114_LOCALES through Solaris specific code. * lib/localename-table.h: Update comments. * lib/localename-table.c: Update comments. * m4/localename.m4 (gl_LOCALENAME): Require gt_INTL_THREAD_LOCALE_NAME. Test for 'uselocale'. Don't invoke gt_INTL_SOLARIS. * m4/intl.m4 (AM_INTL_SUBDIR): Require gt_INTL_THREAD_LOCALE_NAME. Test for 'uselocale'. Set HAVE_NAMELESS_LOCALES. (gt_INTL_SUBDIR_CORE): Don't invoke gt_INTL_SOLARIS. Don't set HAVE_NAMELESS_LOCALES here. * modules/localename (Files): Add m4/intl-thread-locale.m4. Remove m4/intlsolaris.m4. * modules/gettext (Files): Likewise.
author Bruno Haible <bruno@clisp.org>
date Tue, 23 Oct 2018 22:18:24 +0200
parents d7d58557ca8b
children c01fb99adfe2
files ChangeLog lib/localename-table.c lib/localename-table.h lib/localename.c m4/intl-thread-locale.m4 m4/intl.m4 m4/intlsolaris.m4 m4/localename.m4 modules/gettext modules/localename
diffstat 10 files changed, 136 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Oct 23 01:08:10 2018 +0200
+++ b/ChangeLog	Tue Oct 23 22:18:24 2018 +0200
@@ -1,3 +1,23 @@
+2018-10-23  Bruno Haible  <bruno@clisp.org>
+
+	localename: Simplify support for per-thread locales on Solaris 11.4.
+	* m4/intl-thread-locale.m4: Renamed from m4/intlsolaris.m4.
+	(gt_INTL_THREAD_LOCALE_NAME): Renamed from gt_INTL_SOLARIS. Define
+	HAVE_SOLARIS114_LOCALES instead of HAVE_NAMELESS_LOCALES.
+	* lib/localename.c: Handle HAVE_SOLARIS114_LOCALES through Solaris
+	specific code.
+	* lib/localename-table.h: Update comments.
+	* lib/localename-table.c: Update comments.
+	* m4/localename.m4 (gl_LOCALENAME): Require gt_INTL_THREAD_LOCALE_NAME.
+	Test for 'uselocale'. Don't invoke gt_INTL_SOLARIS.
+	* m4/intl.m4 (AM_INTL_SUBDIR): Require gt_INTL_THREAD_LOCALE_NAME. Test
+	for 'uselocale'. Set HAVE_NAMELESS_LOCALES.
+	(gt_INTL_SUBDIR_CORE): Don't invoke gt_INTL_SOLARIS. Don't set
+	HAVE_NAMELESS_LOCALES here.
+	* modules/localename (Files): Add m4/intl-thread-locale.m4. Remove
+	m4/intlsolaris.m4.
+	* modules/gettext (Files): Likewise.
+
 2018-10-22  Bruno Haible  <bruno@clisp.org>
 
 	std-gnu11: Support Autoconf versions < 2.64.
--- a/lib/localename-table.c	Tue Oct 23 01:08:10 2018 +0200
+++ b/lib/localename-table.c	Tue Oct 23 22:18:24 2018 +0200
@@ -18,7 +18,7 @@
 
 #include <config.h>
 
-#if HAVE_USELOCALE && HAVE_NAMELESS_LOCALES /* Solaris >= 11.4 */
+#if HAVE_USELOCALE && HAVE_NAMELESS_LOCALES
 
 /* Specification.  */
 #include "localename-table.h"
--- a/lib/localename-table.h	Tue Oct 23 01:08:10 2018 +0200
+++ b/lib/localename-table.h	Tue Oct 23 22:18:24 2018 +0200
@@ -16,7 +16,7 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2018.  */
 
-#if HAVE_USELOCALE && HAVE_NAMELESS_LOCALES /* Solaris >= 11.4 */
+#if HAVE_USELOCALE && HAVE_NAMELESS_LOCALES
 
 # include <stddef.h>
 # include <locale.h>
--- a/lib/localename.c	Tue Oct 23 01:08:10 2018 +0200
+++ b/lib/localename.c	Tue Oct 23 22:18:24 2018 +0200
@@ -46,9 +46,13 @@
 # if !defined IN_LIBINTL
 #  include "glthread/lock.h"
 # endif
-# if defined __sun && HAVE_GETLOCALENAME_L
+# if defined __sun
+#  if HAVE_GETLOCALENAME_L
 /* Solaris >= 12.  */
 extern char * getlocalename_l(int, locale_t);
+#  elif HAVE_SOLARIS114_LOCALES
+#   include <sys/localedef.h>
+#  endif
 # endif
 # if HAVE_NAMELESS_LOCALES
 #  include <errno.h>
@@ -2704,7 +2708,7 @@
 #endif
 
 
-#if HAVE_USELOCALE && HAVE_NAMELESS_LOCALES /* Solaris >= 11.4 */
+#if HAVE_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.
@@ -3145,6 +3149,22 @@
 #   if HAVE_GETLOCALENAME_L
         /* Solaris >= 12.  */
         return getlocalename_l (category, thread_locale);
+#   elif HAVE_SOLARIS114_LOCALES
+        /* Solaris >= 11.4.  */
+        void *lcp = (*thread_locale)->core.data->lcp;
+        if (lcp != NULL)
+          switch (category)
+            {
+            case LC_CTYPE:
+            case LC_NUMERIC:
+            case LC_TIME:
+            case LC_COLLATE:
+            case LC_MONETARY:
+            case LC_MESSAGES:
+              return ((const char * const *) lcp)[category];
+            default: /* We shouldn't get here.  */
+              return "";
+            }
 #   elif HAVE_NAMELESS_LOCALES
         return get_locale_t_name (category, thread_locale);
 #   else
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m4/intl-thread-locale.m4	Tue Oct 23 22:18:24 2018 +0200
@@ -0,0 +1,77 @@
+# intl-thread-locale.m4 serial 1
+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,
+dnl with or without modifications, as long as this notice is preserved.
+dnl
+dnl This file can be used in projects which are not available under
+dnl the GNU General Public License or the GNU Library General Public
+dnl License but which still want to provide support for the GNU gettext
+dnl functionality.
+dnl Please note that the actual code of the GNU gettext library is covered
+dnl by the GNU Library General Public License, and the rest of the GNU
+dnl gettext package is covered by the GNU General Public License.
+dnl They are *not* in the public domain.
+
+dnl Check how to retrieve the name of a per-thread locale (POSIX locale_t).
+dnl Sets gt_nameless_locales.
+AC_DEFUN([gt_INTL_THREAD_LOCALE_NAME],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
+  dnl Persuade Solaris <locale.h> to define 'locale_t'.
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS_ONCE([uselocale])
+
+  if test $ac_cv_func_uselocale = yes; then
+    AC_CACHE_CHECK([for Solaris 11.4 locale system],
+      [gt_cv_locale_solaris114],
+      [case "$host_os" in
+         solaris*)
+           dnl Test whether <locale.h> defines locale_t as a typedef of
+           dnl 'struct _LC_locale_t **' (whereas Illumos defines it as a
+           dnl typedef of 'struct _locale *').
+           dnl Another possible test would be to include <sys/localedef.h>
+           dnl and test whether it defines the _LC_core_data_locale_t type.
+           dnl This type was added in Solaris 11.4.
+           AC_COMPILE_IFELSE(
+             [AC_LANG_PROGRAM([[
+                #include <locale.h>
+                struct _LC_locale_t *x;
+                locale_t y;
+              ]],
+              [[*y = x;]])],
+             [gt_cv_locale_solaris114=yes],
+             [gt_cv_locale_solaris114=no])
+           ;;
+         *) gt_cv_locale_solaris114=no ;;
+       esac
+      ])
+  fi
+  if test $gt_cv_locale_solaris114 = yes; then
+    gt_nameless_locales=yes
+    AC_DEFINE([HAVE_SOLARIS114_LOCALES], [1],
+      [Define if the locale_t type is as on Solaris 11.4.])
+  fi
+
+  dnl Solaris 12 will maybe provide getlocalename_l.  If it does, it will
+  dnl improve the implementation of gl_locale_name_thread(), by removing
+  dnl the use of undocumented structures.
+  if test $ac_cv_func_uselocale = yes; then
+    AC_CHECK_FUNCS([getlocalename_l])
+  fi
+
+  dnl This code is for future use, in case we some day have to port to a
+  dnl platform where the locale_t type does not provide access to the name of
+  dnl each locale category.  This code has the drawback that it requires the
+  dnl gnulib overrides of 'newlocale', 'duplocale', 'freelocale', which is a
+  dnl problem for GNU libunistring.  Therefore try hard to avoid enabling this
+  dnl code!
+  gt_nameless_locales=no
+  if false; then
+    gt_nameless_locales=yes
+    AC_DEFINE([HAVE_NAMELESS_LOCALES], [1],
+      [Define if the locale_t type does not contain the name of each locale category.])
+  fi
+])
--- a/m4/intl.m4	Tue Oct 23 01:08:10 2018 +0200
+++ b/m4/intl.m4	Tue Oct 23 22:18:24 2018 +0200
@@ -1,4 +1,4 @@
-# intl.m4 serial 33 (gettext-0.19.9)
+# intl.m4 serial 34 (gettext-0.19.9)
 dnl Copyright (C) 1995-2014, 2016-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,
@@ -40,6 +40,7 @@
   AC_REQUIRE([gl_GLIBC21])dnl
   AC_REQUIRE([gl_XSIZE])dnl
   AC_REQUIRE([gl_FCNTL_O_FLAGS])dnl
+  AC_REQUIRE([gt_INTL_THREAD_LOCALE_NAME])
   AC_REQUIRE([gt_INTL_MACOSX])dnl
   AC_REQUIRE([gl_EXTERN_INLINE])dnl
   AC_REQUIRE([gt_GL_ATTRIBUTE])dnl
@@ -74,7 +75,7 @@
     ])
   AC_CHECK_HEADERS([features.h stddef.h stdlib.h string.h])
   AC_CHECK_FUNCS([asprintf fwprintf newlocale putenv setenv setlocale \
-    snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb])
+    snprintf strnlen uselocale wcslen wcsnlen mbrtowc wcrtomb])
 
   dnl Use the _snprintf function only if it is declared (because on NetBSD it
   dnl is defined as a weak alias of snprintf; we prefer to use the latter).
@@ -119,6 +120,13 @@
   AM_LANGINFO_CODESET
   gt_LC_MESSAGES
 
+  if test $gt_nameless_locales = yes; then
+    HAVE_NAMELESS_LOCALES=1
+  else
+    HAVE_NAMELESS_LOCALES=0
+  fi
+  AC_SUBST([HAVE_NAMELESS_LOCALES])
+
   dnl Compilation on mingw and Cygwin needs special Makefile rules, because
   dnl 1. when we install a shared library, we must arrange to export
   dnl    auxiliary pointer variables for every exported variable,
@@ -235,15 +243,6 @@
     stpcpy strcasecmp strdup strtoul tsearch argz_count argz_stringify \
     argz_next __fsetlocking])
 
-  dnl For Solaris 11.4 and 12.
-  gt_INTL_SOLARIS
-  if test $gt_nameless_locales = yes; then
-    HAVE_NAMELESS_LOCALES=1
-  else
-    HAVE_NAMELESS_LOCALES=0
-  fi
-  AC_SUBST([HAVE_NAMELESS_LOCALES])
-
   dnl Use the *_unlocked functions only if they are declared.
   dnl (because some of them were defined without being declared in Solaris
   dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built
--- a/m4/intlsolaris.m4	Tue Oct 23 01:08:10 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-# intlsolaris.m4 serial 2
-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,
-dnl with or without modifications, as long as this notice is preserved.
-dnl
-dnl This file can be used in projects which are not available under
-dnl the GNU General Public License or the GNU Library General Public
-dnl License but which still want to provide support for the GNU gettext
-dnl functionality.
-dnl Please note that the actual code of the GNU gettext library is covered
-dnl by the GNU Library General Public License, and the rest of the GNU
-dnl gettext package is covered by the GNU General Public License.
-dnl They are *not* in the public domain.
-
-dnl Checks for special localename support needed on Solaris.
-dnl Sets gt_nameless_locales.
-AC_DEFUN([gt_INTL_SOLARIS],
-[
-  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
-
-  dnl Persuade Solaris <locale.h> to define 'locale_t'.
-  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
-
-  AC_CHECK_FUNCS_ONCE([uselocale])
-
-  gt_nameless_locales=no
-  if test $ac_cv_func_uselocale = yes; then
-    AC_CACHE_CHECK([for Solaris 11.4 locale system],
-      [gt_cv_locale_solaris114],
-      [case "$host_os" in
-         solaris*)
-           dnl Test whether <locale.h> defines locale_t as a typedef of
-           dnl 'struct _LC_locale_t **' (whereas Illumos defines it as a
-           dnl typedef of 'struct _locale *').
-           AC_COMPILE_IFELSE(
-             [AC_LANG_PROGRAM([[
-                #include <locale.h>
-                struct _LC_locale_t *x;
-                locale_t y;
-              ]],
-              [[*y = x;]])],
-             [gt_cv_locale_solaris114=yes],
-             [gt_cv_locale_solaris114=no])
-           ;;
-         *) gt_cv_locale_solaris114=no ;;
-       esac
-      ])
-  fi
-  if test $gt_cv_locale_solaris114 = yes; then
-    gt_nameless_locales=yes
-    AC_DEFINE([HAVE_NAMELESS_LOCALES], [1],
-      [Define if the locale_t type does not contain the name of each locale category.])
-  fi
-
-  dnl Solaris 12 will maybe provide getlocalename_l.  If it does, it will
-  dnl simplify the implementation of gl_locale_name_thread().  But the overrides
-  dnl of newlocale, duplocale, freelocale will still be necessary, in order to
-  dnl keep the libintl_locale_hash_table up-to-date, which may be used by
-  dnl libintl or gnulib code that was compiled on Solaris 11.4, before
-  dnl getlocalename_l was introduced.
-  if test $ac_cv_func_uselocale = yes; then
-    AC_CHECK_FUNCS([getlocalename_l])
-  fi
-])
--- a/m4/localename.m4	Tue Oct 23 01:08:10 2018 +0200
+++ b/m4/localename.m4	Tue Oct 23 22:18:24 2018 +0200
@@ -1,4 +1,4 @@
-# localename.m4 serial 4
+# localename.m4 serial 5
 dnl Copyright (C) 2007, 2009-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,
@@ -8,10 +8,11 @@
 [
   AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
   AC_REQUIRE([gt_LC_MESSAGES])
+  AC_REQUIRE([gt_INTL_THREAD_LOCALE_NAME])
   AC_REQUIRE([gt_INTL_MACOSX])
   AC_CHECK_HEADERS_ONCE([langinfo.h])
   AC_CHECK_FUNCS([setlocale])
-  AC_CHECK_FUNCS_ONCE([uselocale newlocale duplocale freelocale])
+  AC_CHECK_FUNCS_ONCE([newlocale duplocale freelocale])
   if test $ac_cv_func_newlocale != yes; then
     HAVE_NEWLOCALE=0
   fi
@@ -21,7 +22,6 @@
   if test $ac_cv_func_freelocale != yes; then
     HAVE_FREELOCALE=0
   fi
-  gt_INTL_SOLARIS
   if test $gt_nameless_locales = yes; then
     REPLACE_NEWLOCALE=1
     REPLACE_DUPLOCALE=1
--- a/modules/gettext	Tue Oct 23 01:08:10 2018 +0200
+++ b/modules/gettext	Tue Oct 23 22:18:24 2018 +0200
@@ -18,9 +18,9 @@
 m4/iconv.m4
 m4/intdiv0.m4
 m4/intl.m4
+m4/intl-thread-locale.m4
 m4/intldir.m4
 m4/intlmacosx.m4
-m4/intlsolaris.m4
 m4/intmax.m4
 m4/inttypes_h.m4
 m4/inttypes-pri.m4
--- a/modules/localename	Tue Oct 23 01:08:10 2018 +0200
+++ b/modules/localename	Tue Oct 23 22:18:24 2018 +0200
@@ -7,8 +7,8 @@
 lib/localename-table.h
 lib/localename-table.c
 m4/localename.m4
+m4/intl-thread-locale.m4
 m4/intlmacosx.m4
-m4/intlsolaris.m4
 m4/lcmessage.m4
 
 Depends-on: