Re: [scc-dev] [PATCH 0/3] Fix unicode handling

From: <lhr_at_disroot.org>
Date: Wed, 9 Apr 2025 16:10:00 +0100

Sorry for my sudden absence, was busy IRL

> Reading the specs I realized (and I checked it with the libc from musl,
> freebsd and Dragonfly bsd) that mbrtowc is expected to be called many
> times until you get a full sequence.

You're right -- what do you know, I've been using it wrong all this time. I
did wonder what mbstate_t was for in a stateless encoding, I just thought it
for any libc that wants to handle Shift-JIS.

The new wchar all works well for me, but the libc tests fail because GCC complains
that "" is char* which is incompatible with wchar_t*. The patch below makes the

tests work with GCC (and corrects an include). Is using L"" literals alright? scc-cc
itself doesn't like them, but they are used elsewhere in the libc tests


---
diff --git a/tests/libc/execute/0044-wcslen.c b/tests/libc/execute/0044-wcslen.c
index 2c4b9c23..d9b2564f 100644
--- a/tests/libc/execute/0044-wcslen.c
+++ b/tests/libc/execute/0044-wcslen.c
_at_@ -1,6 +1,6 @@
 #include <assert.h>
 #include <stdio.h>
-#include <stdlib.h>
+#include <wchar.h>
 
 /*
 output:
diff --git a/tests/libc/execute/0048-wcscpy.c b/tests/libc/execute/0048-wcscpy.c
index 8194b0a1..98289a39 100644
--- a/tests/libc/execute/0048-wcscpy.c
+++ b/tests/libc/execute/0048-wcscpy.c
_at_@ -21,9 +21,9 @@ main()
 	assert(s == buf);
 	assert(!wcscmp(s, test));
 
-	s = wcscpy(buf, "");
+	s = wcscpy(buf, L"");
 	assert(s == buf);
-	assert(!wcscmp(s, ""));
+	assert(!wcscmp(s, L""));
 
 	puts("done");
 
diff --git a/tests/libc/execute/0057-wcschr.c b/tests/libc/execute/0057-wcschr.c
index d26cc032..862fd6ae 100644
--- a/tests/libc/execute/0057-wcschr.c
+++ b/tests/libc/execute/0057-wcschr.c
_at_@ -35,7 +35,7 @@ main()
 	p = wcschr(buf, 'h');
 	assert(p == NULL);
 
-	p = wcschr("", 'a');
+	p = wcschr(L"", 'a');
 	assert(p == NULL);
 
 	puts("done");
diff --git a/tests/libc/execute/0058-wcsrchr.c b/tests/libc/execute/0058-wcsrchr.c
index b67db7d1..cfb5f8ab 100644
--- a/tests/libc/execute/0058-wcsrchr.c
+++ b/tests/libc/execute/0058-wcsrchr.c
_at_@ -18,7 +18,7 @@ main()
 	assert(wcsrchr(buf, '1') == buf+5);
 	assert(wcsrchr(buf, '0') == buf);
 	assert(wcsrchr(buf, '3') == buf+3);
-	assert(wcsrchr("",  '0') == NULL);
+	assert(wcsrchr(L"",  '0') == NULL);
 	assert(wcsrchr(buf, 'a')  == NULL);
 	assert(wcsrchr(buf, 0) == buf+6);
 	puts("done");
-- 
2.48.1
--
To unsubscribe send a mail to scc-dev+unsubscribe_at_simple-cc.org
Received on Wed 09 Apr 2025 - 17:10:00 CEST

This archive was generated by hypermail 2.3.0 : Wed 09 Apr 2025 - 17:20:01 CEST