From 212f1cc9109aa0deb9e5d990bb2dba2b167618fb Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 12:31:21 +0300 Subject: Keep installed headers from shadowing or polluting host names The pkg-config file put include/term on the host's include path, so ncurses' term.h could be picked up in place of ours. Hosts now write and the package adds only its include directory. The installed Unicode API had unprefixed names that collide with host symbols and macros. Rename them: term_ for functions, types, and static tables, TERM_ for macros and include guards. unicode_data.inc and tools/generate_unicode.py are renamed to match. The generator's inputs here are Unicode 15.1 and the checked-in table is 18.0.0, so the table data was not regenerated. Only the declarations were checked against the generator. utf8.h casts the malloc result so it compiles as C++. header_test.sh now includes with only include/ on the path. It also checks that a host which defines unicode_width, UTF8_ACCEPT, GRAPHEME_MAX_LEN, in_ranges, and similar names compiles with the Unicode headers as C11 and C++, in both declaration orders. Co-Authored-By: Claude Haiku 5.5 --- tests/unicode/unicode_test.c | 68 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'tests/unicode/unicode_test.c') diff --git a/tests/unicode/unicode_test.c b/tests/unicode/unicode_test.c index 7fc6e3e..e3cf5a7 100644 --- a/tests/unicode/unicode_test.c +++ b/tests/unicode/unicode_test.c @@ -16,17 +16,17 @@ static void test_utf8_decode_one(void) for (size_t i = 0; i < sizeof(valid) / sizeof(*valid); i++) { uint32_t cp = 0xdeadbeef; for (int n = 0; n < valid[i].len; n++) { - int r = utf8_decode_one(valid[i].bytes, n, &cp); + int r = term_utf8_decode_one(valid[i].bytes, n, &cp); assert(r == 0); assert(cp == 0xdeadbeef); } - int r = utf8_decode_one(valid[i].bytes, valid[i].len, &cp); + int r = term_utf8_decode_one(valid[i].bytes, valid[i].len, &cp); assert(r == valid[i].len); assert(cp == valid[i].cp); char followed[8]; memcpy(followed, valid[i].bytes, valid[i].len); memcpy(followed + valid[i].len, "next", 4); - r = utf8_decode_one(followed, valid[i].len + 4, &cp); + r = term_utf8_decode_one(followed, valid[i].len + 4, &cp); assert(r == valid[i].len); assert(cp == valid[i].cp); } @@ -38,7 +38,7 @@ static void test_utf8_decode_one(void) }; for (size_t i = 0; i < sizeof(invalid) / sizeof(*invalid); i++) { uint32_t cp = 0xdeadbeef; - int r = utf8_decode_one(invalid[i], strlen(invalid[i]), &cp); + int r = term_utf8_decode_one(invalid[i], strlen(invalid[i]), &cp); assert(r == 0); assert(cp == 0xdeadbeef); } @@ -48,24 +48,24 @@ static void test_scalar_roundtrips(void) { for (uint32_t cp = 0; cp <= 0x10ffff; cp++) { if (cp >= 0xd800 && cp <= 0xdfff) continue; - char bytes[UTF8_MAX_BYTES]; - int len = utf8_encode(cp, bytes); - uint32_t scalar = 0, streamed = 0, state = UTF8_ACCEPT; - int r = utf8_decode_one(bytes, (size_t)len, &scalar); + char bytes[TERM_UTF8_MAX_BYTES]; + int len = term_utf8_encode(cp, bytes); + uint32_t scalar = 0, streamed = 0, state = TERM_UTF8_ACCEPT; + int r = term_utf8_decode_one(bytes, (size_t)len, &scalar); assert(r == len); assert(scalar == cp); for (int i = 0; i < len; i++) { - utf8_decode(&state, &streamed, (unsigned char)bytes[i]); - if (i + 1 < len) assert(state != UTF8_ACCEPT && state != UTF8_REJECT); + term_utf8_decode(&state, &streamed, (unsigned char)bytes[i]); + if (i + 1 < len) assert(state != TERM_UTF8_ACCEPT && state != TERM_UTF8_REJECT); } - assert(state == UTF8_ACCEPT && streamed == cp); + assert(state == TERM_UTF8_ACCEPT && streamed == cp); } static const uint32_t invalid[] = {0xd800, 0xdfff, 0x110000, UINT32_MAX}; for (size_t i = 0; i < sizeof(invalid) / sizeof(*invalid); i++) { - char bytes[UTF8_MAX_BYTES]; - int len = utf8_encode(invalid[i], bytes); + char bytes[TERM_UTF8_MAX_BYTES]; + int len = term_utf8_encode(invalid[i], bytes); uint32_t cp = 0; - int r = utf8_decode_one(bytes, len, &cp); + int r = term_utf8_decode_one(bytes, len, &cp); assert(len == 3 && r == len && cp == 0xfffd); } } @@ -74,26 +74,26 @@ static void test_utf8_sanitize(void) { char dst[64]; - utf8_sanitize(dst, sizeof(dst), "hello \xe2\x82\xac\xf0\x9f\x98\x80"); + term_utf8_sanitize(dst, sizeof(dst), "hello \xe2\x82\xac\xf0\x9f\x98\x80"); assert(!strcmp(dst, "hello \xe2\x82\xac\xf0\x9f\x98\x80")); - utf8_sanitize(dst, sizeof(dst), "a\xff\x80" "b\xed\xa0\x80" "c\xe2\x82"); + term_utf8_sanitize(dst, sizeof(dst), "a\xff\x80" "b\xed\xa0\x80" "c\xe2\x82"); assert(!strcmp(dst, "abc")); - utf8_sanitize(dst, sizeof(dst), ""); + term_utf8_sanitize(dst, sizeof(dst), ""); assert(!strcmp(dst, "")); - utf8_sanitize(dst, sizeof(dst), "\xff\xfe"); + term_utf8_sanitize(dst, sizeof(dst), "\xff\xfe"); assert(!strcmp(dst, "")); - utf8_sanitize(dst, 6, "ab\xe2\x82\xac" "cd"); + term_utf8_sanitize(dst, 6, "ab\xe2\x82\xac" "cd"); assert(!strcmp(dst, "ab\xe2\x82\xac")); - utf8_sanitize(dst, 5, "ab\xe2\x82\xac" "cd"); + term_utf8_sanitize(dst, 5, "ab\xe2\x82\xac" "cd"); assert(!strcmp(dst, "abcd")); memset(dst, 'x', sizeof(dst)); - utf8_sanitize(dst, 4, "abcdef"); + term_utf8_sanitize(dst, 4, "abcdef"); assert(!strcmp(dst, "abc")); memset(dst, 'x', sizeof(dst)); - utf8_sanitize(dst, 0, "abc"); + term_utf8_sanitize(dst, 0, "abc"); assert(dst[0] == 'x'); } @@ -101,30 +101,30 @@ static void test_utf8_sanitize(void) * stays unused. */ static void test_ground_invalid_subparts(void) { - uint32_t state = UTF8_ACCEPT, codep = 0, cp = 0xdead; - int n = utf8_decode_ground(&state, &codep, "\xe2\x80\x1b\xac", 4, &cp); + uint32_t state = TERM_UTF8_ACCEPT, codep = 0, cp = 0xdead; + int n = term_utf8_decode_ground(&state, &codep, "\xe2\x80\x1b\xac", 4, &cp); assert(n == 2); assert(cp == 0xFFFD); - assert(state == UTF8_ACCEPT); - n = utf8_decode_ground(&state, &codep, "\xac", 1, &cp); + assert(state == TERM_UTF8_ACCEPT); + n = term_utf8_decode_ground(&state, &codep, "\xac", 1, &cp); assert(n == 1); assert(cp == 0xFFFD); - assert(state == UTF8_ACCEPT); - n = utf8_decode_ground(&state, &codep, "\xe2\x82z", 3, &cp); + assert(state == TERM_UTF8_ACCEPT); + n = term_utf8_decode_ground(&state, &codep, "\xe2\x82z", 3, &cp); assert(n == 2); assert(cp == 0xFFFD); - assert(state == UTF8_ACCEPT); - n = utf8_decode_ground(&state, &codep, "\xe2\x82", 2, &cp); + assert(state == TERM_UTF8_ACCEPT); + n = term_utf8_decode_ground(&state, &codep, "\xe2\x82", 2, &cp); assert(n == 2); assert(cp == 0); - assert(state != UTF8_ACCEPT); + assert(state != TERM_UTF8_ACCEPT); - state = UTF8_ACCEPT; + state = TERM_UTF8_ACCEPT; codep = 0; - n = utf8_decode_ground(&state, &codep, "\xe2\x82\xac", 3, &cp); + n = term_utf8_decode_ground(&state, &codep, "\xe2\x82\xac", 3, &cp); assert(n == 3); assert(cp == 0x20ac); - assert(state == UTF8_ACCEPT); + assert(state == TERM_UTF8_ACCEPT); } int main(void) -- cgit v1.2.3