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

Merged
babyhuey merged 1 commit from upstream-pr/1783 into main 2026-10-10 08:05:49 +00:00
babyhuey commented 2026-10-08 19:07:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T19:07:21Z.


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: #1781
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4791558074 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1783). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T19:07:21Z. --- ### 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #1781 - [x] AI-assisted: yes
popcoder565 commented 2026-10-09 15:46:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:46:04Z.


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 d70b8998 in one build with 38 other PRs that had no Windows run.

  • This PR's tests pass: guest_rune_locale. None of them reported skipping a case.
  • Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084265850 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1783#issuecomment-6084265850). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:46:04Z. --- 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` d70b8998 in one build with 38 other PRs that had no Windows run. - This PR's tests pass: `guest_rune_locale`. None of them reported skipping a case. - Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
github-actions[bot] commented 2026-10-09 22:10:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:10:52Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090098221 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1783#issuecomment-6090098221). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:10:52Z. --- <!-- progress-report --> ### Progress report (2f250f8 → 1bfb3cb) 📈 **System libraries**: 85.77% (+0.08%, +18 implemented functions) <details> <summary>✅ 18 implemented</summary> | 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` | </details>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1783
No description provided.