unistdio/*: Fix test failures when libunistring is installed
On a NetBSD machine which happens to have libunistring installed, I see these test failures: FAIL: test-u8-vasnprintf1 = ../../gltests/unistdio/test-u8-printf1.h:93: assertion 'u8_strcmp (result, expected) == 0' failed FAIL test-u8-vasnprintf1 (exit status: 134) FAIL: unistdio/test-u8-vasnprintf2.sh = ../../gltests/unistdio/test-u8-printf1.h:93: assertion 'u8_strcmp (result, expected) == 0' failed [1] Abort trap (core dumped) LC_ALL=${testlocale} ${CHECKER} ./test-u8-vasn... FAIL unistdio/test-u8-vasnprintf2.sh (exit status: 1) FAIL: unistdio/test-u8-vasnprintf3.sh = ../../gltests/unistdio/test-u8-printf1.h:93: assertion 'u8_strcmp (result, expected) == 0' failed [1] Abort trap (core dumped) LC_ALL=${testlocale} ${CHECKER} ./test-u8-vasn... FAIL unistdio/test-u8-vasnprintf3.sh (exit status: 1) FAIL: test-u8-vasprintf1 ../../gltests/unistdio/test-u8-printf1.h:93: assertion 'u8_strcmp (result, expected) == 0' failed FAIL test-u8-vasprintf1 (exit status: 134) FAIL: test-u8-vsnprintf1 ../../gltests/unistdio/test-u8-printf1.h:93: assertion 'u8_strcmp (result, expected) == 0' failed FAIL test-u8-vsnprintf1 (exit status: 134) FAIL: test-u8-vsprintf1 === ../../gltests/unistdio/test-u8-printf1.h:93: assertion 'u8_strcmp (result, expected) == 0' failed FAIL test-u8-vsprintf1 (exit status: 134) etc. The cause is that the patch from https://lists.gnu.org/archive/html/bug-gnulib/2023-01/msg00233.html modified the behaviour of these function, in a way that is visible to the test suite. The fix is to make sure that these functions' implementations are not taken from older versions of libunistring. 2023-04-07 Bruno Haible unistdio/*: Fix test failures (regression 2023-01-28). * modules/unistdio/*printf (configure.ac): Bump required libunistring version number. diff --git a/modules/unistdio/u16-asnprintf b/modules/unistdio/u16-asnprintf index 441ff2dc79..67bf35701a 100644 --- a/modules/unistdio/u16-asnprintf +++ b/modules/unistdio/u16-asnprintf @@ -11,7 +11,7 @@ unistdio/base unistdio/u16-vasnprintf configure.ac: -gl_LIBUNISTRING_MODULE([0.9], [unistdio/u16-asnprintf]) +gl_LIBUNISTRING_MODULE([1.2], [unistdio/u16-asnprintf]) Makefile.am: if LIBUNISTRING_COMPILE_UNISTDIO_U16_ASNPRINTF diff --git a/modules/unistdio/u16-asprintf b/modules/unistdio/u16-asprintf index daa397ebb5..e1616684c7 100644 --- a/modules/unistdio/u16-asprintf +++ b/modules/unistdio/u16-asprintf @@ -10,7 +10,7 @@ unistdio/base unistdio/u16-vasprintf configure.ac: -gl_LIBUNISTRING_MODULE([0.9], [unistdio/u16-asprintf]) +gl_LIBUNISTRING_MODULE([1.2], [unistdio/u16-asprintf]) Makefile.am: if LIBUNISTRING_COMPILE_UNISTDIO_U16_ASPRINTF diff --git a/modules/unistdio/u16-snprintf b/modules/unistdio/u16-snprintf index b02b0d63b6..600c52cad6 100644 --- a/modules/unistdio/u16-snprintf +++ b/modules/unistdio/u16-snprintf @@ -10,7 +10,7 @@ unistdio/base unistdio/u16-vsnprintf configure.ac: -gl_LIBUNISTRING_MODULE([0.9], [unistdio/u16-snprintf]) +gl_LIBUNISTRING_MODULE([1.2], [unistdio/u16-snprintf]) Makefile.am: if LIBUNISTRING_COMPILE_UNISTDIO_U16_SNPRINTF diff --git a/modules/unistdio/u16-sprintf b/modules/unistdio/u16-sprintf index 9139f2f3da..358ac7cc0e 100644 --- a/modules/unistdio/u16-sprintf +++ b/modules/unistdio/u16-sprintf @@ -10,7 +10,7 @@ unistdio/base unistdio/u16-vsprintf configure.ac: -gl_LIBUNISTRING_MODULE([0.9], [unistdio/u16-sprintf]) +gl_LIBUNISTRING_MODULE([1.2], [unistdio/u16-sprintf]) Makefile.am: if LIBUNISTRING_COMPILE_UNISTDIO_U16_SPRINTF diff --git a/modules/unistdio/u16-u16-asnprintf b/modules/unistdio/u16-u16-asnprintf index 597f59618f..6eb694cf4f 100644 --- a/modules/unistdio/u16-u16-asnprintf +++ b/modules/unistdio/u16-u16-asnprintf @@ -11,7 +11,7 @@ unistdio/base unistdio/u16-u16-vasnprintf configure.ac: -gl_LIBUNISTRING_MODULE([0.9], [unistdio/u16-u16-asnprintf]) +gl_LIBUNISTRING_MODULE([1.2], [unistdio/u16-u16-asnprintf]) Makefile.am: if LIBUNISTRING_COMPILE_UNISTDIO_U16_U16_ASNPRINTF diff --git a/modules/unistdio/u16-u16-asprintf b/modules/unistdio/u16-u16-asprintf index b81688dcb6..7b8febd5de 100644 --- a/modules/unistdio/u16-u16-asprintf +++ b/modules/unistdio/u16-u16-asprintf @@ -10,7 +10,7 @@ unistdio/base unistdio/u16-u16-vasprintf configure.ac: -gl_LIBUNISTRING_MODULE([0.9], [unistdio/u16-u16-asprintf]) +gl_LIBUNISTRING_MODULE([1.2], [unistdio/u16-u16-asprintf]) Makefile.am: if LIBUNISTRING_COMPILE_UNISTDIO_U16_U16_ASPRINTF diff --git a/modules/unistdio/u16-u16-snprintf b/modules/unistdio/u16-u16-snprintf index b55ed6ab13..3aae4244df 100644 --- a/modules/unistdio/u16-u16-snprintf +++ b/modules/unistdio/u16-u16-snprintf @@ -10,7 +10,7 @@ unistdio/base unistdio/u16-u16-vsnprintf configure.ac: -gl_LIBUNISTRING_MODULE([0.9], [unistdio/u16-u16-snprintf])
Re: Fix trim2 uninitialized GCC warning
I wrote: > trim: Add tests. > * tests/test-trim.c: New file. > * tests/test-trim1.sh: New file. > * tests/test-trim2.sh: New file. > * tests/test-trim3.sh: New file. > * modules/trim-tests: New file. On NetBSD, I see a link error: gcc -Wno-error -g -O2 -L/home/bruno/lib -L/usr/pkg/lib -o test-trim test-trim.o libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a libtests.a /home/bruno/lib/libunistring.so -Wl,-rpath -Wl,/home/bruno/lib -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm ld: ../gllib/libgnu.a(xalloc-die.o): in function `xalloc_die': /home/bruno/testdir-all/build/gllib/../../gllib/xalloc-die.c:34: undefined reference to `libintl_gettext' ld: ../gllib/libgnu.a(error.o): in function `print_errno_message': /home/bruno/testdir-all/build/gllib/../../gllib/error.c:193: undefined reference to `libintl_gettext' gmake[4]: *** [Makefile:20818: test-trim] Error 1 This patch fixes it. 2023-04-07 Bruno Haible trim tests: Fix link error. * modules/trim-tests (Makefile.am): Link test-trim also against libintl. diff --git a/modules/trim-tests b/modules/trim-tests index 326b800c3f..ece746d2df 100644 --- a/modules/trim-tests +++ b/modules/trim-tests @@ -19,4 +19,4 @@ TESTS_ENVIRONMENT += \ LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \ LOCALE_ZH_CN='@LOCALE_ZH_CN@' check_PROGRAMS += test-trim -test_trim_LDADD = $(LDADD) $(LIBUNISTRING) $(MBRTOWC_LIB) +test_trim_LDADD = $(LDADD) $(LIBUNISTRING) @LIBINTL@ $(MBRTOWC_LIB)
stdio: Fix the value of _PRINTF_NAN_LEN_MAX on OpenBSD
On OpenBSD 6.5, I see a test failure of 'test-stdio'. The _PRINTF_NAN_LEN_MAX check fails because the printed representation of NaN, here, is "-nan"; however, gnulib's stdio.h had defined _PRINTF_NAN_LEN_MAX to 3. This patch fixes the value. 2023-04-07 Bruno Haible stdio: Fix the value of _PRINTF_NAN_LEN_MAX on OpenBSD. * lib/stdio.in.h (_PRINTF_NAN_LEN_MAX): Define to 4 on OpenBSD. diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 69242b6c36..f318014978 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -209,12 +209,11 @@ #ifndef _PRINTF_NAN_LEN_MAX # if defined __FreeBSD__ || defined __DragonFly__ \ || defined __NetBSD__ \ - || defined __OpenBSD__ \ || (defined __APPLE__ && defined __MACH__) /* On BSD systems, a NaN value prints as just "nan", without a sign. */ # define _PRINTF_NAN_LEN_MAX 3 -# elif (__GLIBC__ >= 2) || MUSL_LIBC || defined __sun || defined __CYGWIN__ -/* glibc, musl libc, Solaris libc, and Cygwin produce "[-]nan". */ +# elif (__GLIBC__ >= 2) || MUSL_LIBC || defined __OpenBSD__ || defined __sun || defined __CYGWIN__ +/* glibc, musl libc, OpenBSD, Solaris libc, and Cygwin produce "[-]nan". */ # define _PRINTF_NAN_LEN_MAX 4 # elif defined _AIX /* AIX produces "[-]NaNQ". */
vasnwprintf-posix: Work around %La bug in glibc 2.15 and Haiku
On glibc 2.15 and Haiku (2022), I am seeing a test failure: ../../gltests/test-vasnwprintf-posix.c:521: assertion 'wcscmp (result, L"0x1.922p+1 33") == 0 || wcscmp (result, L"0x3.244p+0 33") == 0 || wcscmp (result, L"0x6.488p-1 33") == 0 || wcscmp (result, L"0xc.91p-2 33") == 0' failed FAIL test-vasnwprintf-posix (exit status: 134) Here, instead of L"0xc.91p-2 33", the result is L"0xc.c9p-2 33", which is off by more than 2%. The value is wrong for many more 'long double' arguments, as can be seen from the attached test program and output. Interestingly, for %a and %La in narrow format strings, and for %a in wide format strings, there is no bug. On the glibc side, the bug is fixed in glibc 2.17 and newer. Nevertheless, I am adding the workaround since it affects many argument values and a recent Haiku as well. 2023-04-07 Bruno Haible vasnwprintf-posix: Work around %La bug in glibc 2.15 and Haiku. * m4/printf.m4 (gl_SWPRINTF_DIRECTIVE_LA): New macro. * m4/vasnprintf.m4 (gl_PREREQ_VASNWPRINTF): Invoke gl_SWPRINTF_DIRECTIVE_LA and define NEED_WPRINTF_DIRECTIVE_LA accordingly. * lib/vasnprintf.c: When compiling vasnwprintf, if NEED_WPRINTF_DIRECTIVE_LA, handle the %La and %LA directives ourselves. * doc/posix-functions/swprintf.texi: Mention the %La bug. diff --git a/doc/posix-functions/swprintf.texi b/doc/posix-functions/swprintf.texi index cd20d0e702..fe36bc215a 100644 --- a/doc/posix-functions/swprintf.texi +++ b/doc/posix-functions/swprintf.texi @@ -36,6 +36,12 @@ accommodate all Unicode characters. @item On Windows, this function does not take a buffer size as second argument. @item +This function produces wrong values for the @samp{La} directive +on some platforms: +glibc 2.15, +@c https://dev.haiku-os.org/ticket/18353 +Haiku. +@item This function does not support size specifiers as in C23 (@code{w8}, @code{w16}, @code{w32}, @code{w64}, @code{wf8}, @code{wf16}, @code{wf32}, @code{wf64}) on some platforms: diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 6eb056d0e9..efd610ebe4 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -103,7 +103,7 @@ #include "attribute.h" -#if NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE +#if NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE || (NEED_WPRINTF_DIRECTIVE_LA && WIDE_CHAR_VERSION) # include # include "float+.h" #endif @@ -113,7 +113,7 @@ # include "isnand-nolibm.h" #endif -#if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE +#if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || (NEED_WPRINTF_DIRECTIVE_LA && WIDE_CHAR_VERSION) # include # include "isnanl-nolibm.h" # include "fpucw.h" @@ -125,7 +125,7 @@ # include "printf-frexp.h" #endif -#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE +#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || (NEED_WPRINTF_DIRECTIVE_LA && WIDE_CHAR_VERSION) # include # include "isnanl-nolibm.h" # include "printf-frexpl.h" @@ -357,7 +357,7 @@ local_wctomb (char *s, wchar_t wc) # endif #endif -#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE +#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE || (NEED_WPRINTF_DIRECTIVE_LA && WIDE_CHAR_VERSION) /* Determine the decimal-point character according to the current locale. */ # ifndef decimal_point_char_defined # define decimal_point_char_defined 1 @@ -3929,14 +3929,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, length += count; } #endif -#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE +#if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE || (NEED_WPRINTF_DIRECTIVE_LA && WIDE_CHAR_VERSION) else if ((dp->conversion == 'a' || dp->conversion == 'A') # if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) && (0 # if NEED_PRINTF_DOUBLE || a.arg[dp->arg_index].type == TYPE_DOUBLE # endif -# if NEED_PRINTF_LONG_DOUBLE +# if NEED_PRINTF_LONG_DOUBLE || (NEED_WPRINTF_DIRECTIVE_LA && WIDE_CHAR_VERSION) || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # endif ) @@ -4056,7 +4056,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, p = tmp; if (type == TYPE_LONGDOUBLE) { -# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE +# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || (NEED_WPRINTF_DIRECTIVE_LA && WIDE_CHAR_VERSION) long double arg = a.arg[dp->arg_index].a.a_longdouble; if (isnanl (arg)) diff --git a/m4/printf.m4 b/m4/printf.m4 index cf4e225cfe..f513da0c84 100644 --- a/m4/printf.m4 +++ b/m4/printf.m4 @@
stdio: Fix compilation error in C++ mode on macOS
Building a testdir of vasnwprintf-posix on macOS 12.5, I get these two compilation errors: In file included from ../../gltests/test-assert-h-c++.cc:26: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:37: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:214: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:15: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/string:519: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__debug:14: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iosfwd:98: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__mbstate_t.h:29: In file included from ../gllib/wchar.h:80: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/wchar.h:123: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/wchar.h:90: ../gllib/stdio.h:1508:19: error: no member named 'getw' in the global namespace _GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream)); ~~^~~ ../gllib/stdlib.h:404:20: note: expanded from macro '_GL_CXXALIAS_SYS' return ::func; \ ~~^ In file included from ../../gltests/test-assert-h-c++.cc:26: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:37: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:214: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:15: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/string:519: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__debug:14: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iosfwd:98: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__mbstate_t.h:29: In file included from ../gllib/wchar.h:80: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/wchar.h:123: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/wchar.h:90: ../gllib/stdio.h:1751:19: error: no member named 'putw' in the global namespace _GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream)); ~~^~ ../gllib/stdlib.h:404:20: note: expanded from macro '_GL_CXXALIAS_SYS' return ::func; \ ~~^ This cause is that the declarations of these two functions in /usr/include/stdio.h are dependent on the value of _POSIX_C_SOURCE. Apparently this macro has different value in a C++ compilation unit than in C. This patch fixes the errors. 2023-04-07 Bruno Haible stdio: Fix compilation error in C++ mode on macOS. * lib/stdio.in.h (getw, putw): Repeat the declaration even if the function is already supposed to be declared. diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 0ed3e7595c..69242b6c36 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -998,6 +998,10 @@ _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); _GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream)); # else # if @HAVE_DECL_GETW@ +# if defined __APPLE__ && defined __MACH__ +/* The presence of the declaration depends on _POSIX_C_SOURCE. */ +_GL_FUNCDECL_SYS (getw, int, (FILE *restrict stream)); +# endif _GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream)); # endif # endif @@ -1241,6 +1245,10 @@ _GL_CXXALIASWARN (puts); _GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream)); # else # if @HAVE_DECL_PUTW@ +# if defined __APPLE__ && defined __MACH__ +/* The presence of the declaration depends on _POSIX_C_SOURCE. */ +_GL_FUNCDECL_SYS (putw, int, (int w, FILE *restrict stream)); +# endif _GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream)); # endif # endif
vasnwprintf-posix tests: Avoid test failure on mingw
On mingw, in a testdir of vasnwprintf-posix, I see a test failure: ../../gltests/test-vasnwprintf-posix.c:4209: assertion 'wcscmp (result, L"000303c 33") == 0' failed FAIL test-vasnwprintf-posix.exe (exit status: 3) This patch fixes it. 2023-04-07 Bruno Haible vasnwprintf-posix tests: Avoid test failure on mingw. * tests/test-vasnwprintf-posix.c (test_function): For mingw, change two expected test results. diff --git a/tests/test-vasnwprintf-posix.c b/tests/test-vasnwprintf-posix.c index 125b9386a4..67e6654e5c 100644 --- a/tests/test-vasnwprintf-posix.c +++ b/tests/test-vasnwprintf-posix.c @@ -4205,7 +4205,7 @@ test_function (wchar_t * (*my_asnwprintf) (wchar_t *, size_t *, const wchar_t *, ASSERT (result != NULL); /* Neither ISO C nor POSIX specify that the '0' flag is ignored when a width and a precision are both present. But most implementations do so. */ -#if MUSL_LIBC || defined __MINGW32__ +#if MUSL_LIBC ASSERT (wcscmp (result, L"000303c 33") == 0); #else ASSERT (wcscmp (result, L" 00303c 33") == 0); @@ -4291,7 +4291,7 @@ test_function (wchar_t * (*my_asnwprintf) (wchar_t *, size_t *, const wchar_t *, ASSERT (result != NULL); /* Neither ISO C nor POSIX specify that the '0' flag is ignored when a width and a precision are both present. But most implementations do so. */ -#if MUSL_LIBC || defined __MINGW32__ +#if MUSL_LIBC ASSERT (wcscmp (result, L"0x0303c 33") == 0); #else ASSERT (wcscmp (result, L" 0x00303c 33") == 0);