bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*c32*: Optimize on musl libc like on glibc


From: Bruno Haible
Subject: *c32*: Optimize on musl libc like on glibc
Date: Tue, 04 Apr 2023 12:37:48 +0200

glibc is not the only platform that defines __STDC_ISO_10646__ and thus
guarantees that wchar_t values are Unicode code points. musl libc does
that as well. (The mapping of bytes 0x80..0xFF to U+DF80..U+DFFF in the
C locale can be ignored in this context.)

So, the same optimizations apply to musl libc as to glibc.


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.

diff --git a/lib/btoc32.c b/lib/btoc32.c
index 45313819b9..9ba8fb5a5e 100644
--- a/lib/btoc32.c
+++ b/lib/btoc32.c
@@ -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)
diff --git a/lib/c32is-impl.h b/lib/c32is-impl.h
index 13a7dff58c..d5e5362c0b 100644
--- a/lib/c32is-impl.h
+++ b/lib/c32is-impl.h
@@ -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);
diff --git a/lib/c32snrtombs.c b/lib/c32snrtombs.c
index 644e171afe..fd10fc1595 100644
--- a/lib/c32snrtombs.c
+++ b/lib/c32snrtombs.c
@@ -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.  */
 
diff --git a/lib/c32srtombs.c b/lib/c32srtombs.c
index 093d151483..50db58c3d3 100644
--- a/lib/c32srtombs.c
+++ b/lib/c32srtombs.c
@@ -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.  */
 
diff --git a/lib/c32tob.c b/lib/c32tob.c
index 75c46c1dcd..a18aac6efc 100644
--- a/lib/c32tob.c
+++ b/lib/c32tob.c
@@ -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)
diff --git a/lib/mbsnrtoc32s.c b/lib/mbsnrtoc32s.c
index 81125fdc54..c8084da3d9 100644
--- a/lib/mbsnrtoc32s.c
+++ b/lib/mbsnrtoc32s.c
@@ -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.  */
 
diff --git a/lib/mbsrtoc32s.c b/lib/mbsrtoc32s.c
index b5f2523990..9c5a5d096a 100644
--- a/lib/mbsrtoc32s.c
+++ b/lib/mbsrtoc32s.c
@@ -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.  */
 
diff --git a/lib/uchar.in.h b/lib/uchar.in.h
index adf9c551eb..46b4be4f6d 100644
--- a/lib/uchar.in.h
+++ b/lib/uchar.in.h
@@ -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@






reply via email to

[Prev in Thread] Current Thread [Next in Thread]