Skip to content

feat(libc): implement the C locale wide character class functions - #1783

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libc-wide-ctype
Oct 10, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libc-wide-ctype

Conversation

@babyhuey

@babyhuey babyhuey commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements the C locale wide character class functions in libc on top of the rune locale from #1781: iswalnum, iswalpha, iswblank, iswcntrl, iswdigit, iswgraph, iswlower, iswprint, iswpunct, iswspace, iswupper, iswxdigit, iswctype, wctype, towlower, towupper, btowc and wctob.

Following FreeBSD 11 _ctype.h, wctype.c, btowc.c, wctob.c and none.c for the C locale, the only one setlocale accepts:

  • isw* and iswctype test _CurrentRuneLocale->__runetype[c] for 0..255 and are false above 0xFF and for WEOF (the _ext ranges are empty). iswalnum is _CTYPE_A|_CTYPE_N.
  • wctype returns FreeBSD's _CTYPE_* masks for the twelve standard names and the BSD ideogram, special, phonogram, number and rune, and 0 for any other name.
  • towlower/towupper map 0..255 through __maplower/__mapupper and return anything else unchanged.
  • btowc(EOF) is WEOF; any other value is (unsigned char)c. wctob returns the value for 0..255 and EOF otherwise, including WEOF.

Found with tools/import_audit.py on the catalog homebrew titles: each of these is absent in 9 or 10 of 36 audited titles.

Builds on #1781, which has merged; this branch is now a single commit on main.

Tested

Linux (Ubuntu 24.04, GCC 13, Release): guest_rune_locale passes with --repeat until-fail:3. It now checks every isw*/iswctype against the narrow is* exports for 0..299 and WEOF, every wctype name and unknown names, towlower/towupper for 0..299 and WEOF, and btowc/wctob at EOF, 0, ASCII, 0xE9, negative bytes, 0x100, 0x20AC and WEOF. It fails when wctob drops its range check. check_conventions.py passes. Windows: both files compile with MinGW-w64 GCC 13 (-Wall -Wextra -fsyntax-only); not run on Windows.

import_audit.py with #1781 and this branch, absent imports before → after: PPSA19111 66 → 45, PPSA59322 ccleste 50 → 29, PPSA68091 Ruffle 71 → 50, PPSA97510 74 → 53, PPSA98510 74 → 53, PPSA99002 74 → 53, PPSA99010 vkQuake 51 → 30, PPSA99420 116 → 110, PPSA99728 28 → 26, PPSA99764 80 → 59, PPSA99810 64 → 43. No title run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: feat(libc): export the C rune locale #1781
  • AI-assisted: yes

@popcoder565

Copy link
Copy Markdown
Contributor

Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 10ff0cef, merged onto main d70b899 in one build with 38 other PRs that had no Windows run.

No title was run.

🤖 Addressed by Claude Code

@babyhuey
babyhuey force-pushed the feat/libc-wide-ctype branch 2 times, most recently from bf45df7 to 6341ce6 Compare October 9, 2026 21:31
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Progress report (2f250f8 → 1bfb3cb)

📈 System libraries: 85.77% (+0.08%, +18 implemented functions)

✅ 18 implemented
Library Name
libc btowc_nid_postfix
libc iswalnum_nid_postfix
libc iswalpha_nid_postfix
libc iswblank_nid_postfix
libc iswcntrl_nid_postfix
libc iswctype_nid_postfix
libc iswdigit_nid_postfix
libc iswgraph_nid_postfix
libc iswlower_nid_postfix
libc iswprint_nid_postfix
libc iswpunct_nid_postfix
libc iswspace_nid_postfix
libc iswupper_nid_postfix
libc iswxdigit_nid_postfix
libc towlower_nid_postfix
libc towupper_nid_postfix
libc wctob_nid_postfix
libc wctype_nid_postfix

@babyhuey
babyhuey force-pushed the feat/libc-wide-ctype branch 6 times, most recently from 38f15a2 to 0e6d328 Compare October 10, 2026 06:18
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@babyhuey
babyhuey force-pushed the feat/libc-wide-ctype branch from 0e6d328 to 1bfb3cb Compare October 10, 2026 07:19
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@oneandonlydean
oneandonlydean merged commit 4faa14e into boykopovar:main Oct 10, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants