Re: clar unit testing framework FTBFS on uclibc systems (wchar_t unsupported)
From: Patrick Steinhardt <hidden>
Date: 2024-10-17 13:54:35
Subsystem:
the rest · Maintainer:
Linus Torvalds
On Thu, Oct 17, 2024 at 03:33:51PM +0200, Patrick Steinhardt wrote:
On Thu, Oct 17, 2024 at 10:51:05AM +0700, Bagas Sanjaya wrote:quoted
Hi, Since clar unit testing framework was imported by commit 9b7caa2809cb (t: import the clar unit testing framework, 2024-09-04), Git FTBFS on uclibc systems built by Buildroot:Wait a second, that doesn't sound right to me. `wchar_t` is part of ISO C90, so any system not supporting it would basically be unsupported by us from my point of view. And indeed, uclibc _does_ support that type alright. I guess the issue is rather that we're relying on some kind of platform-specific behaviour and thus don't include the correct header. I'll have a look, thanks for the report!
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);