feat(libc): implement the ctype<char> widen and narrow members #15714

Merged
B-Howell merged 3 commits from upstream-pr/15714 into main 2026-11-07 15:36:56 +00:00
B-Howell commented 2026-11-04 09:07:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-11-04T09:07:41Z.


What

Implements the four std::ctype<char> widen and narrow members that libSceLibcInternal declared as stubs throwing through NotImplemented_nid_no_patch in InventoryExports2.cpp:

Symbol NID Behaviour
_ZNKSt5ctypeIcE8do_widenEc zwcNQT0Avck returns the character
_ZNKSt5ctypeIcE8do_widenEPKcS2_Pc W5OtP+WC800 copies [first, last) to the destination, returns last
_ZNKSt5ctypeIcE9do_narrowEcc 4SnCJmLL27U returns the character, ignores the default
_ZNKSt5ctypeIcE9do_narrowEPKcS2_cPc -nCVE3kBjjA copies [first, last) to the destination, returns last

The reference is the Dinkumware ctype<char> in microsoft/STL stl/inc/xlocale at e1ed302. There, do_widen(char _Byte) is return _Byte;, the range form is _CSTD memcpy(_Dest, _First, static_cast<size_t>(_Last - _First)); return _Last;, and the two do_narrow forms do the same while ignoring the default character. An empty range returns last without calling memcpy, so a null destination is accepted for it. The facet pointer is not read. The NIDs were checked by computing them from the mangled names with the repository's NID algorithm.

libc already calls the widen and widenRange slots of guest ctype<char> vtables through GuestLocale::CtypeVtable (num_put widens its digits through widenRange at 0x48). This change adds narrow and narrowRange after them at 0x50 and 0x58, the declaration order in xlocale (do_widen(char), do_widen(range), do_narrow(char, char), do_narrow(range)), with static_asserts for all four offsets.

Changes:

  • core/libs/prx/libc/src/LocaleSupport.cpp: the four members, next to collate<char>::transform. They are declared in prx/libc/include/Api.hpp.
  • core/libs/prx/libc/include/GuestLocale.hpp: the narrow and narrowRange slots, plus offset asserts for widen, narrow and narrowRange.
  • core/libs/prx/libSceLibcInternal/InventoryExports2.cpp: the four stubs are removed.
  • core/libs/tests/GuestLocale.cpp: CheckCtypeCharConversions puts the four exports into a CtypeVtable and calls them through a facet. It checks every char value for both single forms (with ? and \0 defaults), a full range and a sub-range that include \0, \x7f, \x80 and \xff with an untouched guard byte after the destination, and empty ranges with a null destination.
  • docs/dev/debt/libSceLibcInternal.md: the four "signatures and behavior are unverified" entries are removed. docs/dev/debt/libc.md: a Functional entry records the reference, the empty-range rule, the slot layout, and that the console libc.prx bodies were not read and the exported ctype<char> vtable object stays zeroed.

tools/progress.py collect_libraries(): origin/main has 9913 done of 37146 (libc 1628 done and 19 todo, libSceLibcInternal 92 done and 1045 todo). This branch has 9917 done (libc 1632 done and 19 todo, libSceLibcInternal 92 done and 1041 todo). Done goes up by 4 and no new todo appears.

Tested

Only the focused test target and the libraries were built. No title was run.

  • Windows 11, WinLibs GCC 15.2.0 (MinGW-w64), Release: ctest -R '^(guest_locale|conventions_unknown_nids|conventions_debt_length|conventions_doc_links|debt_split)$' ran 3 times, and each run passed 5 of 5 tests with 0 failures.
  • WSL Ubuntu 22.04, GCC 11.4.0, Release: the same 5 tests ran 3 times, and each run passed 5 of 5 with 0 failures.
  • guest_locale is the guest test that holds the new check. conventions_unknown_nids, conventions_debt_length, conventions_doc_links and debt_split are the repository's checker self-tests for the conventions and the debt-file split. They were run because both debt files changed.
  • Negative control on both platforms: main's production LocaleSupport.cpp, Api.hpp, GuestLocale.hpp and InventoryExports2.cpp plus the new test fail to build guest_locale_tests. The errors say the four _ZNKSt5ctypeIcE…_nid_postfix functions are not declared and that GuestLocale::CtypeVtable has no member narrow or narrowRange.
  • python3 tools/check_conventions.py --base origin/main printed "All conventions checks passed."
  • python3 tools/pr_overlap.py --branch feat/r2-ctype-char-widen found no PR exporting the same functions and no PR adding the same files. It found file-level matches only, in LocaleSupport.cpp, GuestLocale.cpp, GuestLocale.hpp, Api.hpp and the libSceLibcInternal debt file (for example #10165, #12510, #12511, #12518, #12704 and #13486). I also grepped the added lines of all 1814 open PRs against main for these four symbols, their NIDs and narrowRange. None of them has a match.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5151798613 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15714). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-11-04T09:07:41Z. --- ### What Implements the four `std::ctype<char>` widen and narrow members that libSceLibcInternal declared as stubs throwing through `NotImplemented_nid_no_patch` in `InventoryExports2.cpp`: | Symbol | NID | Behaviour | | --- | --- | --- | | `_ZNKSt5ctypeIcE8do_widenEc` | `zwcNQT0Avck` | returns the character | | `_ZNKSt5ctypeIcE8do_widenEPKcS2_Pc` | `W5OtP+WC800` | copies `[first, last)` to the destination, returns `last` | | `_ZNKSt5ctypeIcE9do_narrowEcc` | `4SnCJmLL27U` | returns the character, ignores the default | | `_ZNKSt5ctypeIcE9do_narrowEPKcS2_cPc` | `-nCVE3kBjjA` | copies `[first, last)` to the destination, returns `last` | The reference is the Dinkumware `ctype<char>` in [microsoft/STL `stl/inc/xlocale` at e1ed302](https://github.com/microsoft/STL/blob/e1ed302683e5e822f663fbb0f44cee7e9ddc6af0/stl/inc/xlocale#L2818-L2838). There, `do_widen(char _Byte)` is `return _Byte;`, the range form is `_CSTD memcpy(_Dest, _First, static_cast<size_t>(_Last - _First)); return _Last;`, and the two `do_narrow` forms do the same while ignoring the default character. An empty range returns `last` without calling `memcpy`, so a null destination is accepted for it. The facet pointer is not read. The NIDs were checked by computing them from the mangled names with the repository's NID algorithm. libc already calls the `widen` and `widenRange` slots of guest `ctype<char>` vtables through `GuestLocale::CtypeVtable` (`num_put` widens its digits through `widenRange` at 0x48). This change adds `narrow` and `narrowRange` after them at 0x50 and 0x58, the declaration order in `xlocale` (`do_widen(char)`, `do_widen(range)`, `do_narrow(char, char)`, `do_narrow(range)`), with `static_assert`s for all four offsets. Changes: - `core/libs/prx/libc/src/LocaleSupport.cpp`: the four members, next to `collate<char>::transform`. They are declared in `prx/libc/include/Api.hpp`. - `core/libs/prx/libc/include/GuestLocale.hpp`: the `narrow` and `narrowRange` slots, plus offset asserts for `widen`, `narrow` and `narrowRange`. - `core/libs/prx/libSceLibcInternal/InventoryExports2.cpp`: the four stubs are removed. - `core/libs/tests/GuestLocale.cpp`: `CheckCtypeCharConversions` puts the four exports into a `CtypeVtable` and calls them through a facet. It checks every `char` value for both single forms (with `?` and `\0` defaults), a full range and a sub-range that include `\0`, `\x7f`, `\x80` and `\xff` with an untouched guard byte after the destination, and empty ranges with a null destination. - `docs/dev/debt/libSceLibcInternal.md`: the four "signatures and behavior are unverified" entries are removed. `docs/dev/debt/libc.md`: a Functional entry records the reference, the empty-range rule, the slot layout, and that the console `libc.prx` bodies were not read and the exported `ctype<char>` vtable object stays zeroed. `tools/progress.py` `collect_libraries()`: origin/main has 9913 done of 37146 (libc 1628 done and 19 todo, libSceLibcInternal 92 done and 1045 todo). This branch has 9917 done (libc 1632 done and 19 todo, libSceLibcInternal 92 done and 1041 todo). Done goes up by 4 and no new todo appears. ### 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. --> Only the focused test target and the libraries were built. No title was run. - Windows 11, WinLibs GCC 15.2.0 (MinGW-w64), Release: `ctest -R '^(guest_locale|conventions_unknown_nids|conventions_debt_length|conventions_doc_links|debt_split)$'` ran 3 times, and each run passed 5 of 5 tests with 0 failures. - WSL Ubuntu 22.04, GCC 11.4.0, Release: the same 5 tests ran 3 times, and each run passed 5 of 5 with 0 failures. - `guest_locale` is the guest test that holds the new check. `conventions_unknown_nids`, `conventions_debt_length`, `conventions_doc_links` and `debt_split` are the repository's checker self-tests for the conventions and the debt-file split. They were run because both debt files changed. - Negative control on both platforms: main's production `LocaleSupport.cpp`, `Api.hpp`, `GuestLocale.hpp` and `InventoryExports2.cpp` plus the new test fail to build `guest_locale_tests`. The errors say the four `_ZNKSt5ctypeIcE…_nid_postfix` functions are not declared and that `GuestLocale::CtypeVtable` has no member `narrow` or `narrowRange`. - `python3 tools/check_conventions.py --base origin/main` printed "All conventions checks passed." - `python3 tools/pr_overlap.py --branch feat/r2-ctype-char-widen` found no PR exporting the same functions and no PR adding the same files. It found file-level matches only, in `LocaleSupport.cpp`, `GuestLocale.cpp`, `GuestLocale.hpp`, `Api.hpp` and the libSceLibcInternal debt file (for example #10165, #12510, #12511, #12518, #12704 and #13486). I also grepped the added lines of all 1814 open PRs against main for these four symbols, their NIDs and `narrowRange`. None of them has a match. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/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!15714
No description provided.