feat(libc): implement wide ctype classification and uppercase #17836

Merged
B-Howell merged 6 commits from upstream-pr/17836 into main 2026-11-14 23:18:07 +00:00
B-Howell commented 2026-11-09 17:20:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-11-09T17:20:25Z.


What

Implements the five existing std::ctype<wchar_t> member exports in libSceLibcInternal:

  • do_is(mask, wchar_t) (rh7L-TliPoc)
  • do_is(first, last, masks) (D0lUMKU+ELI)
  • do_scan_not(mask, first, last) (Kbe+LHOer9o)
  • do_toupper(wchar_t) (JsZjB3TnZ8A)
  • do_toupper(first, last) (r1W-NtOi6E8)

The installed PS5 libc.prx disassembly shows classification and case mapping read through the facet object, conversion through its narrow/widen virtual slots, and do_scan_not dispatching through virtual scalar do_is. The range methods apply those operations per wide character. The implementation reads the facet-local tables and calls the facet conversion slots. The binary evidence is pinned to artifact SHA-256 A485B34EF160EE635D357F21F4A93586BED1CF499B82918C734DCFD78B04E443; field labels follow the corresponding Dinkumware model.

Against main e5d0293e382f692802e85ed3fb3fbc8f75f432d5, tools/progress.py (collect_libraries()) measures 13,574/38,637 (35.13%) before this change and 13,579/38,637 (35.15%) in the clean merge preview. The five implementations move libSceLibcInternal from 323 to 328 completed functions, with the total unchanged.

The wide ctype and wide numpunct test registrations merge cleanly in either order with #17765.

Tested

Windows 11 (WinLibs GCC 15.2.0, Release): the RED control ran guest_libc_internal_wide_ctype_red and produced the five expected named throws in order, with RED_EXPECTED_STUBS=5/5 and the ordinary 1/1 CTest failure. No crash or exception occurred. c840 restore configure completed.

WSL Ubuntu 22.04 (GCC 11.4.0, Release): the same RED selector produced all five expected named throws in order, with RED_EXPECTED_STUBS=5/5 and the ordinary 1/1 CTest failure. The c840 restore marker reports a clean source and successful configure.

Windows GREEN on 925c062e5967aaa4c64a1a3ac2c1cba33a21e359: guest_libc_internal_wide_ctype, guest_locale, and guest_rune_locale each passed 3/3. Public headers passed 65/65. The source and build configuration were restored to the baseline checkout after testing.

WSL GREEN on 925c062e5967aaa4c64a1a3ac2c1cba33a21e359: the same three guest tests each passed 3/3, and public headers passed 65/65. The source and build configuration were restored to the baseline checkout after testing.

WSL GREEN on 284b05dc74e (ordinary merge of main 85c79e72218, which implements the other ctype<wchar_t> members in Ctype.cpp; the stub-removal conflict in InventoryExports2 kept both sides' removals): guest_libc_internal_wide_ctype and main's guest_libc_internal_ctype passed 2/2.

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 under Silent stubs in their library's technical debt file
  • 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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5228069673 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17836). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-11-09T17:20:25Z. --- ### What Implements the five existing `std::ctype<wchar_t>` member exports in `libSceLibcInternal`: - `do_is(mask, wchar_t)` (`rh7L-TliPoc`) - `do_is(first, last, masks)` (`D0lUMKU+ELI`) - `do_scan_not(mask, first, last)` (`Kbe+LHOer9o`) - `do_toupper(wchar_t)` (`JsZjB3TnZ8A`) - `do_toupper(first, last)` (`r1W-NtOi6E8`) The installed PS5 `libc.prx` disassembly shows classification and case mapping read through the facet object, conversion through its narrow/widen virtual slots, and `do_scan_not` dispatching through virtual scalar `do_is`. The range methods apply those operations per wide character. The implementation reads the facet-local tables and calls the facet conversion slots. The binary evidence is pinned to artifact SHA-256 `A485B34EF160EE635D357F21F4A93586BED1CF499B82918C734DCFD78B04E443`; field labels follow the corresponding Dinkumware model. Against main `e5d0293e382f692802e85ed3fb3fbc8f75f432d5`, `tools/progress.py` (`collect_libraries()`) measures 13,574/38,637 (35.13%) before this change and 13,579/38,637 (35.15%) in the clean merge preview. The five implementations move `libSceLibcInternal` from 323 to 328 completed functions, with the total unchanged. The wide ctype and wide numpunct test registrations merge cleanly in either order with #17765. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 (WinLibs GCC 15.2.0, Release): the RED control ran `guest_libc_internal_wide_ctype_red` and produced the five expected named throws in order, with `RED_EXPECTED_STUBS=5/5` and the ordinary 1/1 CTest failure. No crash or exception occurred. c840 restore configure completed. WSL Ubuntu 22.04 (GCC 11.4.0, Release): the same RED selector produced all five expected named throws in order, with `RED_EXPECTED_STUBS=5/5` and the ordinary 1/1 CTest failure. The c840 restore marker reports a clean source and successful configure. Windows GREEN on `925c062e5967aaa4c64a1a3ac2c1cba33a21e359`: `guest_libc_internal_wide_ctype`, `guest_locale`, and `guest_rune_locale` each passed 3/3. Public headers passed 65/65. The source and build configuration were restored to the baseline checkout after testing. WSL GREEN on `925c062e5967aaa4c64a1a3ac2c1cba33a21e359`: the same three guest tests each passed 3/3, and public headers passed 65/65. The source and build configuration were restored to the baseline checkout after testing. WSL GREEN on `284b05dc74e` (ordinary merge of `main` `85c79e72218`, which implements the other `ctype<wchar_t>` members in `Ctype.cpp`; the stub-removal conflict in `InventoryExports2` kept both sides' removals): `guest_libc_internal_wide_ctype` and main's `guest_libc_internal_ctype` passed 2/2. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
milescoviello commented 2026-11-09 17:53:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-09T17:53:53Z.

Review: COMMENTED


Read at 925c062e59 against main, without building it (a title run is using this host). The facet layout and the per-element loops follow the description. One gap in how these get reached on main:

All five functions go through the facet's own do_narrow (slot 14) and, for upper case, do_widen (slot 12). For std::ctype<wchar_t> on main those two are still the throwing stubs:

  • _ZNKSt5ctypeIwE9do_narrowEwc (V+c0E+Uqcww) and _ZNKSt5ctypeIwE8do_widenEc (h3PbnNnZ-gI) in InventoryExports2.cpp:436-449.
  • The library's own vtable, _ZTVSt5ctypeIwE (libc/src/LocaleSupport.cpp:659), is 18 zero slots.

So a facet that inherits narrow/widen from the base class throws NotImplemented inside do_is. One built on the library's vtable has a null slot 14. The test's fixture brings its own narrow/widen, so it doesn't cover this.

do_narrow(wchar_t, char) and do_widen(char) are probably small enough to add here. Otherwise, a line in the debt entry saying these five need a facet that overrides narrow and widen would make the limit visible.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5830246776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17836#pullrequestreview-5830246776). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-09T17:53:53Z. **Review:** COMMENTED --- Read at `925c062e59` against `main`, without building it (a title run is using this host). The facet layout and the per-element loops follow the description. One gap in how these get reached on `main`: All five functions go through the facet's own `do_narrow` (slot 14) and, for upper case, `do_widen` (slot 12). For `std::ctype<wchar_t>` on `main` those two are still the throwing stubs: - `_ZNKSt5ctypeIwE9do_narrowEwc` (`V+c0E+Uqcww`) and `_ZNKSt5ctypeIwE8do_widenEc` (`h3PbnNnZ-gI`) in `InventoryExports2.cpp:436-449`. - The library's own vtable, `_ZTVSt5ctypeIwE` (`libc/src/LocaleSupport.cpp:659`), is 18 zero slots. So a facet that inherits narrow/widen from the base class throws `NotImplemented` inside `do_is`. One built on the library's vtable has a null slot 14. The test's fixture brings its own narrow/widen, so it doesn't cover this. `do_narrow(wchar_t, char)` and `do_widen(char)` are probably small enough to add here. Otherwise, a line in the debt entry saying these five need a facet that overrides narrow and widen would make the limit visible. AI-assisted: yes (Claude Code)
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!17836
No description provided.