On Thu, Oct 17, 2024 at 03:54:28PM +0200, Patrick Steinhardt wrote: > Okay, uclibc indeed has _optional_ support for `wchar_t`. But what > really throws me off: "include/wchar.h" from uclibc has the following > snippet right at the top: > > #ifndef __UCLIBC_HAS_WCHAR__ > #error Attempted to include wchar.h when uClibc built without wide char support. > #endif > > We unconditionally include <wchar.h>, and your system does not seem to > have support for it built in. So why doesn't the `#error` trigger? It's > also not like this is a recent error, it has been added with 581deed72 > (The obligatory forgotten files..., 2002-05-06). > > We can do something like the below patch in clar, but I'd first like to > understand why your platform seems to be broken in such a way. > > Patrick > > diff --git a/clar.c b/clar.c > index 64879cf..06fe3d1 100644 > --- a/clar.c > +++ b/clar.c > @@ -9,6 +9,11 @@ > #define _DARWIN_C_SOURCE > #define _DEFAULT_SOURCE > > +#if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_WCHAR__) > +#else > +# define HAVE_WCHAR > +#endif > + > #include <errno.h> > #include <setjmp.h> > #include <stdlib.h> > @@ -16,7 +21,9 @@ > #include <string.h> > #include <math.h> > #include <stdarg.h> > +#ifdef HAVE_WCHAR > #include <wchar.h> > +#endif > #include <time.h> > #include <inttypes.h> > > @@ -766,6 +773,7 @@ void clar__assert_equal( > } > } > } > +#ifdef HAVE_WCHAR > else if (!strcmp("%ls", fmt)) { > const wchar_t *wcs1 = va_arg(args, const wchar_t *); > const wchar_t *wcs2 = va_arg(args, const wchar_t *); > @@ -801,6 +809,7 @@ void clar__assert_equal( > } > } > } > +#endif // HAVE_WCHAR > else if (!strcmp("%"PRIuMAX, fmt) || !strcmp("%"PRIxMAX, fmt)) { > uintmax_t sz1 = va_arg(args, uintmax_t), sz2 = va_arg(args, uintmax_t); > is_equal = (sz1 == sz2); > Hi, On Buildroot site, Edgar Bonet (Cc:'ed) suggests to improve your patch by wrapping strcmps [1]: ---- >8 ---- diff --git a/t/unit-tests/clar/clar.c b/t/unit-tests/clar/clar.c index cef0f023c2..6de0b415b1 100644 --- a/t/unit-tests/clar/clar.c +++ b/t/unit-tests/clar/clar.c @@ -18,6 +18,13 @@ #include <sys/types.h> #include <sys/stat.h> +#if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_WCHAR__) + /* uClibc can be built without wchar support, in which case the + installed <wchar.h> is a stub that does not define wchar_t. */ +#else +# define HAVE_WCHAR +#endif + #ifdef _WIN32 # define WIN32_LEAN_AND_MEAN # include <windows.h> @@ -763,6 +770,7 @@ void clar__assert_equal( } } } +#ifdef HAVE_WCHAR else if (!strcmp("%ls", fmt)) { const wchar_t *wcs1 = va_arg(args, const wchar_t *); const wchar_t *wcs2 = va_arg(args, const wchar_t *); @@ -798,6 +806,7 @@ void clar__assert_equal( } } } +#endif // HAVE_WCHAR else if (!strcmp("%"PRIuZ, fmt) || !strcmp("%"PRIxZ, fmt)) { size_t sz1 = va_arg(args, size_t), sz2 = va_arg(args, size_t); is_equal = (sz1 == sz2); Thanks. [1]: https://lore.kernel.org/buildroot/f517190c-6fcd-4101-afa6-f6ea521feb9e@xxxxxxxxxxxxxxxx/ -- An old man doll... just what I always wanted! - Clara
Attachment:
signature.asc
Description: PGP signature