* lib/uchar.in.h (_GL_LARGE_CHAR32_T): New macro.
(c32tob): New declaration.
* lib/c32tob.c: New file.
* m4/uchar.m4 (gl_UCHAR_MODULE_INDICATOR, gl_UCHAR_H_DEFAULTS): New
macros.
(gl_UCHAR_H): Require gl_UCHAR_H_DEFAULTS.
* modules/uchar (Depends-on): Add snippet/c++defs.
(Makefile.am): Include c++defs.h and substitute GNULIB_C32TOB in
uchar.h.
* modules/c32tob: New file.
* tests/test-uchar.c: Verify that _GL_LARGE_CHAR32_T is correctly
defined.
* tests/test-uchar-c++.cc: Include signature.h. Test the signature of
c32tob.
* modules/uchar-c++-tests (Files): Add tests/signature.h.
* doc/posix-functions/wctob.texi: Mention the new module.
+2020-01-01 Bruno Haible <bruno@clisp.org>
+
+ c32tob: New module.
+ * lib/uchar.in.h (_GL_LARGE_CHAR32_T): New macro.
+ (c32tob): New declaration.
+ * lib/c32tob.c: New file.
+ * m4/uchar.m4 (gl_UCHAR_MODULE_INDICATOR, gl_UCHAR_H_DEFAULTS): New
+ macros.
+ (gl_UCHAR_H): Require gl_UCHAR_H_DEFAULTS.
+ * modules/uchar (Depends-on): Add snippet/c++defs.
+ (Makefile.am): Include c++defs.h and substitute GNULIB_C32TOB in
+ uchar.h.
+ * modules/c32tob: New file.
+ * tests/test-uchar.c: Verify that _GL_LARGE_CHAR32_T is correctly
+ defined.
+ * tests/test-uchar-c++.cc: Include signature.h. Test the signature of
+ c32tob.
+ * modules/uchar-c++-tests (Files): Add tests/signature.h.
+ * doc/posix-functions/wctob.texi: Mention the new module.
+
2020-01-01 Bruno Haible <bruno@clisp.org>
locale C++ tests: Fix link error on AIX (regression from 2019-12-18).
Portability problems not fixed by Gnulib:
@itemize
@item
-On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and therefore cannot
-accommodate all Unicode characters.
+On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and
+therefore cannot accommodate all Unicode characters.
+However, the Gnulib function @code{c32tob}, provided by Gnulib module
+@code{c32tob}, operates on 32-bit wide characters and therefore does not have
+this limitation.
@end itemize
--- /dev/null
+/* Convert 32-bit wide character to unibyte character.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2020. */
+
+#include <config.h>
+
+/* Specification. */
+#include <uchar.h>
+
+int
+c32tob (wint_t wc)
+{
+#if _GL_LARGE_CHAR32_T
+ /* In all known encodings, unibyte characters correspond only to
+ characters in the BMP. */
+ if (wc != WEOF && (wchar_t) wc == wc)
+ return wctob ((wchar_t) wc);
+ else
+ return EOF;
+#else
+ return wctob (wc);
+#endif
+}
/* Get mbstate_t, size_t. */
#include <wchar.h>
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+
+
#if !@HAVE_UCHAR_H@
/* A 16-bit variant of wchar_t.
#endif
+/* Define if a 'char32_t' can hold more characters than a 'wchar_t'. */
+#if (defined _AIX && !defined __64BIT__) || defined _WIN32 || defined __CYGWIN__
+# define _GL_LARGE_CHAR32_T 1
+#endif
+
+
+/* Converts a 32-bit wide character to unibyte character.
+ Returns the single-byte representation of WC if it exists,
+ or EOF otherwise. */
+#if @GNULIB_C32TOB@
+_GL_FUNCDECL_SYS (c32tob, int, (wint_t wc));
+_GL_CXXALIAS_SYS (c32tob, int, (wint_t wc));
+_GL_CXXALIASWARN (c32tob);
+#endif
+
+
#endif /* _@GUARD_PREFIX@_UCHAR_H */
-# uchar.m4 serial 1
+# uchar.m4 serial 2
dnl Copyright (C) 2019-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
AC_DEFUN_ONCE([gl_UCHAR_H],
[
+ AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
+
gl_CHECK_NEXT_HEADERS([uchar.h])
if test $ac_cv_header_uchar_h = yes; then
HAVE_UCHAR_H=1
fi
AC_SUBST([HAVE_UCHAR_H])
])
+
+AC_DEFUN([gl_UCHAR_MODULE_INDICATOR],
+[
+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+ AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
+ gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+ dnl Define it also as a C macro, for the benefit of the unit tests.
+ gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_UCHAR_H_DEFAULTS],
+[
+ GNULIB_C32TOB=0; AC_SUBST([GNULIB_C32TOB])
+])
--- /dev/null
+Description:
+c32tob() function: convert 32-bit wide character to unibyte character.
+
+Files:
+lib/c32tob.c
+
+Depends-on:
+uchar
+wctob
+
+configure.ac:
+gl_UCHAR_MODULE_INDICATOR([c32tob])
+
+Makefile.am:
+lib_SOURCES += c32tob.c
+
+Include:
+<uchar.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
Depends-on:
include_next
+snippet/c++defs
stdint
wchar
Makefile.am:
BUILT_SOURCES += uchar.h
-uchar.h: uchar.in.h $(top_builddir)/config.status
+uchar.h: uchar.in.h $(top_builddir)/config.status $(CXXDEFS_H)
$(AM_V_GEN)rm -f $@-t $@ && \
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
-e 's|@''NEXT_UCHAR_H''@|$(NEXT_UCHAR_H)|g' \
+ -e 's/@''GNULIB_C32TOB''@/$(GNULIB_C32TOB)/g' \
+ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
< $(srcdir)/uchar.in.h; \
} > $@-t && \
mv $@-t $@
Files:
tests/test-uchar-c++.cc
tests/test-uchar-c++2.cc
+tests/signature.h
Status:
c++-test
#include <uchar.h>
+#include "signature.h"
+
+
+#if GNULIB_TEST_C32TOB
+SIGNATURE_CHECK (GNULIB_NAMESPACE::c32tob, int, (wint_t));
+#endif
+
int
main ()
/* Check that char32_t is at least 31 bits wide. */
verify ((char32_t)0x7FFFFFFF != (char32_t)0x3FFFFFFF);
+/* Check that _GL_LARGE_CHAR32_T is correctly defined. */
+#if _GL_LARGE_CHAR32_T
+verify (sizeof (char32_t) > sizeof (wchar_t));
+#else
+verify (sizeof (char32_t) == sizeof (wchar_t));
+#endif
+
int
main (void)
{