]> Savannah Git Hosting - gnulib.git/commitdiff
*c32*: Optimize on musl libc like on glibc.
authorBruno Haible <bruno@clisp.org>
Tue, 4 Apr 2023 10:34:12 +0000 (12:34 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 4 Apr 2023 10:34:12 +0000 (12:34 +0200)
* lib/uchar.in.h (_GL_WCHAR_T_IS_UCS4): New macro.
* lib/btoc32.c (btoc32): Test _GL_WCHAR_T_IS_UCS4 instead of __GLIBC__.
* lib/mbsrtoc32s.c: Likewise.
* lib/mbsnrtoc32s.c: Likewise.
* lib/c32tob.c (c32tob): Likewise.
* lib/c32srtombs.c: Likewise.
* lib/c32snrtombs.c: Likewise.
* lib/c32is-impl.h (FUNC): Likewise.

ChangeLog
lib/btoc32.c
lib/c32is-impl.h
lib/c32snrtombs.c
lib/c32srtombs.c
lib/c32tob.c
lib/mbsnrtoc32s.c
lib/mbsrtoc32s.c
lib/uchar.in.h

index 8ac34217ce13e422c37733d89f00f1434471ef96..8f7b5ca8e406152544a2246036a12ad69e5bce6f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2023-04-04  Bruno Haible  <bruno@clisp.org>
+
+       *c32*: Optimize on musl libc like on glibc.
+       * lib/uchar.in.h (_GL_WCHAR_T_IS_UCS4): New macro.
+       * lib/btoc32.c (btoc32): Test _GL_WCHAR_T_IS_UCS4 instead of __GLIBC__.
+       * lib/mbsrtoc32s.c: Likewise.
+       * lib/mbsnrtoc32s.c: Likewise.
+       * lib/c32tob.c (c32tob): Likewise.
+       * lib/c32srtombs.c: Likewise.
+       * lib/c32snrtombs.c: Likewise.
+       * lib/c32is-impl.h (FUNC): Likewise.
+
 2023-04-04  Bruno Haible  <bruno@clisp.org>
 
        uchar: Rename _GL_LARGE_CHAR32_T to _GL_SMALL_WCHAR_T.
index 45313819b951e53428d9722384f282c54c8bcd30..9ba8fb5a5ea09adfc3c16c0a1854588864b8521d 100644 (file)
@@ -27,7 +27,7 @@
 wint_t
 btoc32 (int c)
 {
-#if HAVE_WORKING_MBRTOC32 && !defined __GLIBC__
+#if HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4
   /* The char32_t encoding of a multibyte character may be different than its
      wchar_t encoding.  */
   if (c != EOF)
index 13a7dff58cd2e9ed25249871f841b5d6056a5d6e..d5e5362c0bc0ddb3f6eb5eec885c292d8f2d399c 100644 (file)
@@ -61,7 +61,7 @@ FUNC (wint_t wc)
 #elif HAVE_WORKING_MBRTOC32             /* glibc */
   /* mbrtoc32() is essentially defined by the system libc.  */
 
-# if defined __GLIBC__
+# if _GL_WCHAR_T_IS_UCS4
   /* The char32_t encoding of a multibyte character is known to be the same as
      the wchar_t encoding.  */
   return WCHAR_FUNC (wc);
index 644e171afe1efd3ebd6f210de176c7d4281de0f0..fd10fc15953822b6c356bed4b19d8970f6958532 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <wchar.h>
 
-#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_SMALL_WCHAR_T
+#if (HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4) || _GL_SMALL_WCHAR_T
 /* The char32_t encoding of a multibyte character may be different than its
    wchar_t encoding, or char32_t is wider than wchar_t.  */
 
index 093d151483454609c1a577a11ee6e5186c44f34e..50db58c3d30e71b461e147e4258f32bf52fd9205 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <wchar.h>
 
-#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_SMALL_WCHAR_T
+#if (HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4) || _GL_SMALL_WCHAR_T
 /* The char32_t encoding of a multibyte character may be different than its
    wchar_t encoding, or char32_t is wider than wchar_t.  */
 
index 75c46c1dcde5ded05c594279d58319073ce3e969..a18aac6efcf0248f226363a047fc8a4795fc6c77 100644 (file)
@@ -28,7 +28,7 @@
 int
 c32tob (wint_t wc)
 {
-#if HAVE_WORKING_MBRTOC32 && !defined __GLIBC__
+#if HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4
   /* The char32_t encoding of a multibyte character may be different than its
      wchar_t encoding.  */
   if (wc != WEOF)
index 81125fdc54a59083d3f8dbb85962749ff891d36f..c8084da3d9ca95d1663d1b60a664c13882cf5cd6 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <wchar.h>
 
-#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_SMALL_WCHAR_T
+#if (HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4) || _GL_SMALL_WCHAR_T
 /* The char32_t encoding of a multibyte character may be different than its
    wchar_t encoding, or char32_t is wider than wchar_t.  */
 
index b5f25239903b6f827616fe8e24a5ec482d6c5e42..9c5a5d096a12ecd9e2b161a1d4ecc7c7b648901a 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <wchar.h>
 
-#if (HAVE_WORKING_MBRTOC32 && !defined __GLIBC__) || _GL_SMALL_WCHAR_T
+#if (HAVE_WORKING_MBRTOC32 && !_GL_WCHAR_T_IS_UCS4) || _GL_SMALL_WCHAR_T
 /* The char32_t encoding of a multibyte character may be different than its
    wchar_t encoding, or char32_t is wider than wchar_t.  */
 
index adf9c551eb23dc76ab08074896ae07da34733694..46b4be4f6d99b2b49d3772d38d6acc60b39c46e7 100644 (file)
@@ -107,6 +107,22 @@ typedef uint_least32_t gl_char32_t;
 # define _GL_SMALL_WCHAR_T 1
 #endif
 
+/* Define if 'wchar_t', like 'char32_t',
+     - is a 32-bit type, and
+     - represents Unicode code points.
+   For this test, we can use __STDC_ISO_10646__ (defined by glibc, musl libc,
+   Cygwin) but need to consider _GL_SMALL_WCHAR_T, so as to exclude Cygwin.
+   We cannot use __STDC_UTF_16__ or __STDC_UTF_32__
+     - because these macros provide info about char16_t and char32_t (not
+       wchar_t!), and
+     - because GCC >= 4.9 defines these macros on all platforms, even on
+       FreeBSD and Solaris.
+   We should better not use __STD_UTF_16__, __STD_UTF_32__ either, because
+   these macros are misspellings, only defined by Android's <uchar.h>.  */
+#if defined __STDC_ISO_10646__ && !_GL_SMALL_WCHAR_T
+/* glibc, musl libc */
+# define _GL_WCHAR_T_IS_UCS4 1
+#endif
 
 /* Convert a single-byte character to a 32-bit wide character.  */
 #if @GNULIB_BTOC32@