This patch migrates the 'quotearg' module from wchar_t to char32_t. Note about the link dependency updates: - Adding $(LIBUNISTRING) is needed to avoid link errors on macOS, FreeBSD, NetBSD, Solaris when module 'libunistring-optional' is present and a libunistring is installed. - Adding $(LIBC32CONV) is needed to avoid link errors on macOS, FreeBSD when the module 'uchar-c23' is present. Packages that don't use 'libunistring-optional' nor 'uchar-c23' don't need to change their *_LDADD variables.
2023-07-01 Bruno Haible <br...@clisp.org> quotearg: Overcome wchar_t limitations. * lib/quotearg.c: Include <uchar.h> instead of <wchar.h>, <wctype.h>. (quotearg_buffer_restyled): Use mbrtoc32, c32isprint instead of mbrtowc, iswprint. * modules/quotearg (Files): Remove m4/mbstate_t.m4, m4/mbrtowc.m4 (redundant). (Depends-on): Add uchar, mbrtoc32, c32isprint. Remove wchar, wctype-h, mbrtowc. (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/quotearg-tests (Makefile.am): Link test-quotearg with $(LIBUNISTRING) $(LIBC32CONV). * modules/quotearg-simple (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/quotearg-simple-tests (Makefile.am): Link test-quotearg-simple with $(LIBUNISTRING) $(LIBC32CONV). -- * modules/quote (Link): Add $(LIBUNISTRING) $(LIBC32CONV). -- * modules/acl (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/acl-tests (Makefile.am): Link test-set-mode-acl and test-copy-acl with $(LIBUNISTRING) $(LIBC32CONV). * modules/copy-file (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/copy-file-tests (Makefile.am): Link test-copy-file with $(LIBUNISTRING) $(LIBC32CONV). -- * modules/argmatch (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/argmatch-tests (Makefile.am): Link test-argmatch with $(LIBUNISTRING) $(LIBC32CONV). * modules/backup-rename (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/backupfile (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/human (Link): Add $(LIBUNISTRING) $(LIBC32CONV). -- * modules/sh-quote (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/sh-quote-tests (Makefile.am): Link test-sh-quote with $(LIBUNISTRING) $(LIBC32CONV). * modules/system-quote (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/system-quote-tests (Makefile.am): Link test-system-quote-main with $(LIBUNISTRING) $(LIBC32CONV). * modules/csharpcomp (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/csharpexec (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/javacomp (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/javaexec (Link): Add $(LIBUNISTRING) $(LIBC32CONV). -- * modules/string-desc-quotearg (Link): New section. * modules/string-desc-quotearg-tests (Makefile.am): Link test-string-desc-quotearg with $(LIBUNISTRING) $(LIBC32CONV). -- * modules/xmemcoll (Link): Add $(LIBUNISTRING) $(LIBC32CONV). -- * modules/closeout (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/readtokens-tests (Makefile.am): Link test-readtokens with $(LIBUNISTRING) $(LIBC32CONV). -- * modules/closein (Link): Add $(LIBUNISTRING) $(LIBC32CONV). * modules/closein-tests (Makefile.am): Link test-closein with $(LIBUNISTRING) $(LIBC32CONV). * modules/yesno-tests (Makefile.am): Link test-yesno with $(LIBUNISTRING) $(LIBC32CONV). diff --git a/lib/quotearg.c b/lib/quotearg.c index 975bd61dd0..c4133f10d6 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -41,8 +41,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> -#include <wchar.h> -#include <wctype.h> +#include <uchar.h> #include "gettext.h" #define _(msgid) gettext (msgid) @@ -535,7 +534,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, case '`': case '|': /* A shell special character. In theory, '$' and '`' could be the first bytes of multibyte characters, which means - we should check them with mbrtowc, but in practice this + we should check them with mbrtoc32, but in practice this doesn't happen so it's not worth worrying about. */ if (quoting_style == shell_always_quoting_style && elide_outer_quotes) @@ -620,9 +619,9 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, do { - wchar_t w; - size_t bytes = mbrtowc (&w, &arg[i + m], - argsize - (i + m), &mbstate); + char32_t w; + size_t bytes = mbrtoc32 (&w, &arg[i + m], + argsize - (i + m), &mbstate); if (bytes == 0) break; else if (bytes == (size_t) -1) @@ -639,6 +638,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, } else { + if (bytes == (size_t) -3) + bytes = 0; /* Work around a bug with older shells that "see" a '\' that is really the 2nd byte of a multibyte character. In practice the problem is limited to ASCII @@ -659,7 +660,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, } } - if (! iswprint (w)) + if (! c32isprint (w)) printable = false; m += bytes; } diff --git a/modules/acl b/modules/acl index bcc1f4906c..2e410fbe6a 100644 --- a/modules/acl +++ b/modules/acl @@ -21,7 +21,9 @@ Include: "acl.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise $(LIB_ACL) $(QCOPY_ACL_LIB) diff --git a/modules/acl-tests b/modules/acl-tests index 2ee34c6523..7cb39e9758 100644 --- a/modules/acl-tests +++ b/modules/acl-tests @@ -25,6 +25,6 @@ TESTS += \ test-copy-acl.sh test-copy-acl-1.sh test-copy-acl-2.sh TESTS_ENVIRONMENT += USE_ACL=$(USE_ACL) check_PROGRAMS += test-set-mode-acl test-copy-acl test-sameacls -test_set_mode_acl_LDADD = $(LDADD) $(LIB_ACL) @LIBINTL@ $(MBRTOWC_LIB) -test_copy_acl_LDADD = $(LDADD) $(LIB_ACL) $(QCOPY_ACL_LIB) @LIBINTL@ $(MBRTOWC_LIB) +test_set_mode_acl_LDADD = $(LDADD) $(LIB_ACL) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) +test_copy_acl_LDADD = $(LDADD) $(LIB_ACL) $(QCOPY_ACL_LIB) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) test_sameacls_LDADD = $(LDADD) $(LIB_ACL) @LIBINTL@ $(MBRTOWC_LIB) diff --git a/modules/argmatch b/modules/argmatch index f07012644b..8b02b10b9d 100644 --- a/modules/argmatch +++ b/modules/argmatch @@ -27,7 +27,9 @@ Include: "argmatch.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/argmatch-tests b/modules/argmatch-tests index 2f70d491d2..11bce80102 100644 --- a/modules/argmatch-tests +++ b/modules/argmatch-tests @@ -9,5 +9,5 @@ configure.ac: Makefile.am: TESTS += test-argmatch check_PROGRAMS += test-argmatch -test_argmatch_LDADD = $(LDADD) @LIBINTL@ $(MBRTOWC_LIB) +test_argmatch_LDADD = $(LDADD) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) diff --git a/modules/backup-rename b/modules/backup-rename index 6f6ab87a4b..b352d9aea7 100644 --- a/modules/backup-rename +++ b/modules/backup-rename @@ -36,7 +36,9 @@ Include: "backupfile.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/backupfile b/modules/backupfile index 08bf1d2526..b02cdc1cb1 100644 --- a/modules/backupfile +++ b/modules/backupfile @@ -37,7 +37,9 @@ Include: "backupfile.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/closein b/modules/closein index b5f3ce332f..42ff50d0fe 100644 --- a/modules/closein +++ b/modules/closein @@ -21,7 +21,9 @@ Include: "closein.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/closein-tests b/modules/closein-tests index d40156cb6d..189d09feed 100644 --- a/modules/closein-tests +++ b/modules/closein-tests @@ -12,4 +12,4 @@ configure.ac: Makefile.am: TESTS += test-closein.sh check_PROGRAMS += test-closein -test_closein_LDADD = $(LDADD) @LIBINTL@ $(MBRTOWC_LIB) +test_closein_LDADD = $(LDADD) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) diff --git a/modules/closeout b/modules/closeout index 05f17957d9..b4ccefe443 100644 --- a/modules/closeout +++ b/modules/closeout @@ -23,7 +23,9 @@ Include: "closeout.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/copy-file b/modules/copy-file index a73e2a474c..231f31c8ed 100644 --- a/modules/copy-file +++ b/modules/copy-file @@ -38,7 +38,9 @@ Include: Link: $(LIB_ACL) $(QCOPY_ACL_LIB) +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/copy-file-tests b/modules/copy-file-tests index 087797c727..563cf95e33 100644 --- a/modules/copy-file-tests +++ b/modules/copy-file-tests @@ -18,4 +18,4 @@ Makefile.am: TESTS += test-copy-file.sh test-copy-file-1.sh test-copy-file-2.sh TESTS_ENVIRONMENT += USE_ACL=$(USE_ACL) check_PROGRAMS += test-copy-file -test_copy_file_LDADD = $(LDADD) $(LIB_ACL) $(QCOPY_ACL_LIB) $(CLOCK_TIME_LIB) @LIBINTL@ $(MBRTOWC_LIB) +test_copy_file_LDADD = $(LDADD) $(LIB_ACL) $(QCOPY_ACL_LIB) $(CLOCK_TIME_LIB) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) diff --git a/modules/csharpcomp b/modules/csharpcomp index 244a802965..97783d67c2 100644 --- a/modules/csharpcomp +++ b/modules/csharpcomp @@ -28,7 +28,9 @@ Include: "csharpcomp.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise $(LIBTHREAD) License: diff --git a/modules/csharpexec b/modules/csharpexec index ee82df8dd9..cb30c938fb 100644 --- a/modules/csharpexec +++ b/modules/csharpexec @@ -28,7 +28,9 @@ Include: "csharpexec.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise $(LIBTHREAD) License: diff --git a/modules/human b/modules/human index a281fa4bf0..0c09f8206c 100644 --- a/modules/human +++ b/modules/human @@ -27,7 +27,9 @@ Include: "human.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/javacomp b/modules/javacomp index f3ce944100..d93cde52e3 100644 --- a/modules/javacomp +++ b/modules/javacomp @@ -43,7 +43,9 @@ Include: "javacomp.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise $(GETRANDOM_LIB) $(LIBTHREAD) diff --git a/modules/javaexec b/modules/javaexec index 4859e76254..e54dcffd22 100644 --- a/modules/javaexec +++ b/modules/javaexec @@ -29,7 +29,9 @@ Include: "javaexec.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise $(LIBTHREAD) License: diff --git a/modules/quote b/modules/quote index d9533a2de7..2b74111596 100644 --- a/modules/quote +++ b/modules/quote @@ -17,7 +17,9 @@ Include: "quote.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/quotearg b/modules/quotearg index db0903fa97..6e823fa9c6 100644 --- a/modules/quotearg +++ b/modules/quotearg @@ -5,16 +5,15 @@ Files: lib/quotearg.h lib/quotearg.c lib/quote.h -m4/mbstate_t.m4 -m4/mbrtowc.m4 m4/quotearg.m4 Depends-on: attribute c-strcaseeq +c32isprint extensions gettext-h -mbrtowc +mbrtoc32 mbsinit memcmp minmax @@ -22,8 +21,7 @@ quotearg-simple localcharset stdbool stdint -wchar -wctype-h +uchar xalloc configure.ac: @@ -36,7 +34,9 @@ Include: "quotearg.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/quotearg-simple b/modules/quotearg-simple index 240192329a..e3d532defa 100644 --- a/modules/quotearg-simple +++ b/modules/quotearg-simple @@ -13,7 +13,9 @@ Makefile.am: Include: Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/quotearg-simple-tests b/modules/quotearg-simple-tests index 7f2f03f345..ba15ef2d4b 100644 --- a/modules/quotearg-simple-tests +++ b/modules/quotearg-simple-tests @@ -19,4 +19,4 @@ AC_CHECK_FUNCS_ONCE([mprotect]) Makefile.am: TESTS += test-quotearg-simple check_PROGRAMS += test-quotearg-simple -test_quotearg_simple_LDADD = $(LDADD) @LIBINTL@ $(MBRTOWC_LIB) +test_quotearg_simple_LDADD = $(LDADD) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) diff --git a/modules/quotearg-tests b/modules/quotearg-tests index 0ff8b4d402..d297f0b0aa 100644 --- a/modules/quotearg-tests +++ b/modules/quotearg-tests @@ -29,4 +29,4 @@ TESTS_ENVIRONMENT += \ LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \ host_os='@host_os@' check_PROGRAMS += test-quotearg -test_quotearg_LDADD = $(LDADD) $(SETLOCALE_LIB) @LIBINTL@ $(MBRTOWC_LIB) +test_quotearg_LDADD = $(LDADD) $(SETLOCALE_LIB) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) diff --git a/modules/readtokens-tests b/modules/readtokens-tests index 1637125569..189cde252c 100644 --- a/modules/readtokens-tests +++ b/modules/readtokens-tests @@ -11,4 +11,4 @@ configure.ac: Makefile.am: TESTS += test-readtokens.sh check_PROGRAMS += test-readtokens -test_readtokens_LDADD = $(LDADD) @LIBINTL@ $(MBRTOWC_LIB) +test_readtokens_LDADD = $(LDADD) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) diff --git a/modules/sh-quote b/modules/sh-quote index c3e23dc878..834601ba86 100644 --- a/modules/sh-quote +++ b/modules/sh-quote @@ -19,7 +19,9 @@ Include: "sh-quote.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/sh-quote-tests b/modules/sh-quote-tests index 1bded043f2..b2eccc58c7 100644 --- a/modules/sh-quote-tests +++ b/modules/sh-quote-tests @@ -8,4 +8,4 @@ configure.ac: Makefile.am: TESTS += test-sh-quote check_PROGRAMS += test-sh-quote -test_sh_quote_LDADD = $(LDADD) @LIBINTL@ $(MBRTOWC_LIB) +test_sh_quote_LDADD = $(LDADD) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) diff --git a/modules/string-desc-quotearg b/modules/string-desc-quotearg index 17e0fa5abf..915859cf3d 100644 --- a/modules/string-desc-quotearg +++ b/modules/string-desc-quotearg @@ -18,6 +18,11 @@ lib_SOURCES += string-desc-quotearg.c Include: "string-desc-quotearg.h" +Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise +$(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise + License: GPL diff --git a/modules/string-desc-quotearg-tests b/modules/string-desc-quotearg-tests index 2fa97ee4cb..04115df8ec 100644 --- a/modules/string-desc-quotearg-tests +++ b/modules/string-desc-quotearg-tests @@ -9,4 +9,4 @@ configure.ac: Makefile.am: TESTS += test-string-desc-quotearg check_PROGRAMS += test-string-desc-quotearg -test_string_desc_quotearg_LDADD = $(LDADD) @LIBINTL@ $(MBRTOWC_LIB) +test_string_desc_quotearg_LDADD = $(LDADD) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) diff --git a/modules/system-quote b/modules/system-quote index b1c860261b..cd933986a1 100644 --- a/modules/system-quote +++ b/modules/system-quote @@ -20,7 +20,9 @@ Include: "system-quote.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/system-quote-tests b/modules/system-quote-tests index e5850614f5..8ac3a67357 100644 --- a/modules/system-quote-tests +++ b/modules/system-quote-tests @@ -18,7 +18,7 @@ configure.ac: Makefile.am: TESTS += test-system-quote.sh check_PROGRAMS += test-system-quote-main test-system-quote-child -test_system_quote_main_LDADD = $(LDADD) @LIBINTL@ $(MBRTOWC_LIB) +test_system_quote_main_LDADD = $(LDADD) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV) # The test-system-quote-child program must be a real executable, not a libtool # wrapper script, and should link against as few libraries as possible. # Therefore don't link it against any libraries other than -lc. diff --git a/modules/xmemcoll b/modules/xmemcoll index 2ce12cc208..a8ff50bee6 100644 --- a/modules/xmemcoll +++ b/modules/xmemcoll @@ -22,7 +22,9 @@ Include: "xmemcoll.h" Link: +$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise $(MBRTOWC_LIB) +$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise License: GPL diff --git a/modules/yesno-tests b/modules/yesno-tests index f66e068e00..9431c634f7 100644 --- a/modules/yesno-tests +++ b/modules/yesno-tests @@ -12,4 +12,4 @@ configure.ac: Makefile.am: TESTS += test-yesno.sh check_PROGRAMS += test-yesno -test_yesno_LDADD = $(LDADD) @LIBINTL@ $(MBRTOWC_LIB) +test_yesno_LDADD = $(LDADD) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB) $(LIBC32CONV)