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 --- src/text_run.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/text_run.c') diff --git a/src/text_run.c b/src/text_run.c index 028b160..c48b73e 100644 --- a/src/text_run.c +++ b/src/text_run.c @@ -19,7 +19,7 @@ static int width_run_count; void term_text_tables_init(void) { for (uint32_t cp = 0; cp < 65536; cp++) { - int w = unicode_width(cp); + int w = term_unicode_width(cp); unicode_fast_class[cp] = (w == 1 || w == 2) && !cluster_contextual(cp) ? (uint8_t)w : 0; unicode_width_bmp[cp] = (int8_t)w; @@ -92,7 +92,7 @@ static TERM_MAYBE_UNUSED bool width_cache_extend(struct width_cache *wc, const u int term_text_class(uint32_t cp) { assert(term_tables_ready()); - return TERM_EXPECT(cp < 65536, 1) ? (int)unicode_width_bmp[cp] : unicode_width(cp); + return TERM_EXPECT(cp < 65536, 1) ? (int)unicode_width_bmp[cp] : term_unicode_width(cp); } #if defined(TERM_KERNEL_AVX512) @@ -189,10 +189,10 @@ static inline bool classify_3byte_block(__m512i in, struct width_ranges *ranges, _mm512_loadu_si512(utf8_3byte_bits)) & UTF8_3BYTE_SPAN, 0)) return false; *cps = utf8_3byte_decode(_mm512_permutexvar_epi8(_mm512_loadu_si512(utf8_3byte_shuffle), in)); - if (_mm512_cmplt_epu32_mask(*cps, _mm512_set1_epi32((int)UTF8_3BYTE_MIN)) || + if (_mm512_cmplt_epu32_mask(*cps, _mm512_set1_epi32((int)TERM_UTF8_3BYTE_MIN)) || _mm512_cmple_epu32_mask( - _mm512_sub_epi32(*cps, _mm512_set1_epi32((int)UTF8_SURROGATE_LO)), - _mm512_set1_epi32((int)(UTF8_SURROGATE_HI - UTF8_SURROGATE_LO)))) + _mm512_sub_epi32(*cps, _mm512_set1_epi32((int)TERM_UTF8_SURROGATE_LO)), + _mm512_set1_epi32((int)(TERM_UTF8_SURROGATE_HI - TERM_UTF8_SURROGATE_LO)))) return false; __mmask16 covered = width_ranges_cover(ranges, *cps); if (TERM_EXPECT(covered != 0xFFFF || wc->klass == 0, 0)) { @@ -289,7 +289,7 @@ text_3byte_blocks(uint8_t * restrict dst, const char * restrict buf, int len, in struct text_run_bytes term_text_run_bytes(uint8_t *restrict dst, const char *restrict buf, int len, int max_cols, uint32_t last, struct width_cache *restrict wc) { - if (TERM_EXPECT(last == 0x200D || grapheme_is_handle(last), 0)) + if (TERM_EXPECT(last == 0x200D || term_grapheme_is_handle(last), 0)) return (struct text_run_bytes){ .last = last, .narrow = true }; /* Unlike term_text_run(), this fills up to the edge and up to the end of * buf: the cells path writes those characters one by one with the same @@ -335,7 +335,7 @@ struct text_run_bytes term_text_run_bytes(uint8_t *restrict dst, const char *res } #endif uint32_t cp; - int bytes = utf8_decode_one(buf + i, (size_t)(len - i), &cp); + int bytes = term_utf8_decode_one(buf + i, (size_t)(len - i), &cp); if (!bytes) break; int w = bytes < 4 ? unicode_fast_class[cp] : term_text_class(cp); @@ -493,9 +493,9 @@ static inline int decode_3byte_quads(uint64_t **dst_io, const char *buf, int len _mm_and_si128(_mm_srli_epi32(packed, 2), _mm_set1_epi32(0x0FC0))), _mm_and_si128(_mm_srli_epi32(packed, 4), _mm_set1_epi32(0xF000))); __m128i bad = _mm_or_si128( - _mm_cmplt_epi32(cps, _mm_set1_epi32((int)UTF8_3BYTE_MIN)), + _mm_cmplt_epi32(cps, _mm_set1_epi32((int)TERM_UTF8_3BYTE_MIN)), _mm_cmpeq_epi32(_mm_and_si128(cps, _mm_set1_epi32(0xF800)), - _mm_set1_epi32((int)UTF8_SURROGATE_LO))); + _mm_set1_epi32((int)TERM_UTF8_SURROGATE_LO))); if (_mm_movemask_epi8(bad)) break; alignas(16) uint32_t cp[4]; @@ -530,7 +530,7 @@ text_run_body(struct cell *restrict row, const char *restrict buf, int len, int { int i = 0; int cx = 0; - if (TERM_EXPECT(last == 0x200D || grapheme_is_handle(last), 0)) + if (TERM_EXPECT(last == 0x200D || term_grapheme_is_handle(last), 0)) return (struct text_run_result){0, 0, last}; const struct cell_bases bases = cell_bases_make(fg, bg, flags); @@ -593,14 +593,14 @@ text_run_body(struct cell *restrict row, const char *restrict buf, int len, int } #endif uint32_t cp; - int bytes = utf8_decode_one(buf + i, (size_t)(len - i), &cp); + int bytes = term_utf8_decode_one(buf + i, (size_t)(len - i), &cp); if (!bytes) break; int w = bytes < 4 ? unicode_fast_class[cp] : term_text_class(cp); if (w <= 0 || (bytes == 4 && can_extend_cluster(last, cp, w))) break; #if defined(TERM_KERNEL_AVX512) if (isa == TERM_ISA_AVX512 && bytes == 3 && w == 2 && i + 6 <= len && cx + 4 <= max_cols) { uint32_t next_cp; - if (utf8_decode_one(buf + i + 3, (size_t)(len - i - 3), &next_cp) == 3 && + if (term_utf8_decode_one(buf + i + 3, (size_t)(len - i - 3), &next_cp) == 3 && unicode_fast_class[next_cp] == 2) { store_wide_pair(dst, fg, bg, flags, cp, next_cp); dst += 8; -- cgit v1.2.3