git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: clar unit testing framework FTBFS on uclibc systems (wchar_t unsupported)

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 17, 2024, 13:54 UTC
Message-ID
<ZxEXFI80i4Q_4NJT@pks.im>
In-Reply-To
<ZxESP0xHV4cK64i0@pks.im>
On Thu, Oct 17, 2024 at 03:33:51PM +0200, Patrick Steinhardt wrote:
Show 14 quoted lines
> On Thu, Oct 17, 2024 at 10:51:05AM +0700, Bagas Sanjaya wrote:
> > 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);
Previous: Patrick SteinhardtNext: Taylor Blau
Message 3 of 18 in “clar unit testing framework FTBFS on uclibc systems (wchar_t unsupported)”
  1. Bagas SanjayaOct 17, 2024
  2. Patrick SteinhardtOct 17, 2024
  3. Patrick SteinhardtOct 17, 2024
  4. Taylor BlauOct 17, 2024
  5. brian m. carlsonOct 17, 2024
  6. Jeff KingOct 18, 2024
  7. Patrick SteinhardtOct 18, 2024
  8. Jeff KingOct 18, 2024
  9. Patrick SteinhardtOct 18, 2024
  10. Taylor BlauOct 18, 2024
  11. Patrick SteinhardtOct 21, 2024
  12. Jeff KingOct 21, 2024
  13. Taylor BlauOct 21, 2024
  14. brian m. carlsonOct 18, 2024
  15. Jeff KingOct 21, 2024
  16. Jeff KingOct 21, 2024
  17. Bagas SanjayaOct 18, 2024
  18. Patrick SteinhardtOct 21, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.