feat(libSceLibcInternal): implement the num_get<char> and num_get<wchar_t> get members #15788

Closed
B-Howell wants to merge 1 commit from upstream-pr/15788 into main
B-Howell commented 2026-11-04 14:51:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-11-04T14:51:18Z.


What

The 22 public get overloads of num_get<char, istreambuf_iterator<char>> and num_get<wchar_t, istreambuf_iterator<wchar_t>> in libSceLibcInternal threw from the Pending3 placeholders in Err.cpp. They now return do_get through the facet's own vtable. These are the calls std::istream and std::wistream operator>> make through use_facet<num_get<...>> for bool, the integer types, the floating types and void*.

Value type Slot char NID (was) wchar_t NID (was)
bool 0x20 OWO5cpNw3NA (Pending3_056) vW-nnV62ea4 (Pending3_081)
unsigned short 0x28 gozsp4urvq8 (Pending3_063) bZ+lKHGvOr8 (Pending3_088)
unsigned int 0x30 N1VqUWz2OEI (Pending3_060) Y3hBU5FYmhM (Pending3_085)
long 0x38 I2UzwkwwEPs (Pending3_061) -m2YPwVCwJQ (Pending3_086)
unsigned long 0x40 2bfL3yIBi5k (Pending3_062) 94ZLp2+AOq0 (Pending3_087)
long long 0x48 4hiQK82QuLc (Pending3_064) cG5hQhjFGog (Pending3_089)
unsigned long long 0x50 eZfFLyWCkvg (Pending3_065) banNSumaAZ0 (Pending3_090)
float 0x58 6RGkooTERsE (Pending3_059) 2mb8FYgER+E (Pending3_084)
double 0x60 mAwXCpkWaYc (Pending3_057) +hjXHfvy1Mg (Pending3_082)
long double 0x68 wUCRGap1j0U (Pending3_058) xLZr4GJRMLo (Pending3_083)
void* 0x70 my9ujasm6-0 (Pending3_055) zomvAQ5RFdA (Pending3_080)

Each NID matches tools/nid_names.py compute_nid of its mangled name, for example _ZNKSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE3getES3_S3_RSt8ios_baseRNSt5_IosbIiE8_IostateERb gives OWO5cpNw3NA. The others differ in the character type (Ic/Iw) and the last letters (t, j, l, m, x, y, f, d, e, Pv). All 22 were checked.

What each get does:

  • [facet.num.get.members]: get returns do_get(in, end, str, err, val). The first microsoft/STL commit does the same for all eleven overloads (xlocnum L308-L361): return do_get(_First, _Last, _Iosbase, _State, _Val);.
  • The forwarder calls the slot for its value type in the vtable of the facet it is given, so a derived facet's override is reached.

The slot order is an inference. The console's libSceLibcInternal.sprx was not read. The standard synopsis ([locale.num.get]) declares do_get for bool, long, long long, unsigned short, unsigned int, unsigned long, unsigned long long, float, double, long double and void*. This PR uses the microsoft/STL (Dinkumware) order instead, the order of the do_get declarations in xlocnum L365-L636: bool, unsigned short, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double, void*, starting after the four FacetVtable slots at 0x20. The evidence for that choice is indirect:

  • main's GuestLocale::NumPutVtable, which libc hands to guests as g_numPutVtable (LocaleSupport.cpp), already lays out num_put in the microsoft/STL order (putLong, putUnsignedLong, putLongLong), not the standard's (long, long long, unsigned long);
  • libc declares _ZTVSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE and _ZTVSt7num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE with 17 entries: offset-to-top and RTTI, 4 facet slots and 11 do_get slots. That fixes the count, not the order.

If the console's order differs, the forwarders call the wrong do_get. The debt entry says so, and the test pins every slot, so a later change to the order fails it.

Changes:

  • GuestLocale.hpp: new GuestLocale::InputIterator, an opaque, trivially copyable 16-byte value for istreambuf_iterator, with static_asserts on its size and triviality. Nothing reads its fields. istreambuf_iterator<char> and istreambuf_iterator<wchar_t> are both 16 bytes (pointer, bool, element padded; the members are _Strbuf, _Got and _Val in streambuf L519-L521) with no user-declared copy constructor or destructor, so both are passed and returned in two integer registers like this struct.
  • GuestLocale.hpp: new GuestLocale::NumGetVtable with all eleven slots, a static_assert on every slot offset (0x20 to 0x70) and on the size (0x78). The ios_base::iostate& argument is _Iosb<int>::_Iostate& in the mangled names and is passed as std::int32_t*.
  • New NumGet.cpp with the 22 forwarders, and the 22 placeholders removed from Err.cpp.
  • docs/dev/debt/libSceLibcInternal.md: the 22 per-NID "prototype and behavior are unverified" entries are removed and one entry records what is still open.

The InputIterator block in GuestLocale.hpp (and its <type_traits> include) is byte-for-byte the block of the time_get and money_get/money_put PRs from the same batch, at the same place, so the three merge in any order. git merge-tree --write-tree of each pair, of all three, and of each against main is clean, and the merged header has one InputIterator.

Still not done:

  • Neither libc nor libSceLibcInternal builds a num_get facet or implements do_get, so today these calls reach only a facet the title provides. The facet constructors, _Init, _Getcat, _Getifld, _Getffld and the do_get members still throw.
  • No title was seen calling these exports.

Tested

No title was run. I added the guest test guest_libc_internal_num_get (core/libs/tests/GuestLibcInternalNumGet.cpp). It loads libSceLibcInternal, calls each of the 22 exports with a facet whose vtable records every call, and checks:

  • each of the 22 exports calls the do_get slot of its own value type exactly once (every slot of the vtable records a different index, so a forwarder bound to a wrong slot, or a wrong slot order, fails);
  • the facet, both 16-byte iterators word for word, the stream, the state pointer and the value pointer arrive unchanged;
  • the export returns the iterator do_get returns and leaves the state do_get wrote;
  • with a second vtable standing in for a derived facet, every export reaches the derived slot, not a fixed one.
    The header static_asserts pin every slot offset (0x20 to 0x70) and the size.

Results:

  • Windows 11, WinLibs GCC 15.2.0 (MinGW), Release: ctest -R '^guest_libc_internal_num_get$' passed 3 of 3 runs (1/1 each), and once more after the negative-control restore. public_headers passed.
  • Linux, WSL Ubuntu 22.04, GCC 11.4.0, Release: a fresh clone of b11c7bf84f with this commit applied (git write-tree equal to the commit's tree) passed ctest -R '^(guest_libc_internal_num_get|public_headers)$' 3 of 3 runs (2/2 each), and 1 of 1 after the restore.
  • Negative control: with main's Err.cpp put back and NumGet.cpp emptied, keeping the new test, the test fails on both hosts with sceLibcInternalPending3_056_nid_no_patch not implemented (Windows exit code 0xc0000409, Linux subprocess aborted).
  • Conventions: python3 tools/check_conventions.py --base origin/main with this title and body: "All conventions checks passed."
  • Progress: tools/progress.py collect_libraries() for libSceLibcInternal: done 92 to 114 (+22), todo 1045 to 1023. Overall done 9921 to 9943 of 37146; the total does not change, so no new todo.
  • Overlap: python3 tools/pr_overlap.py --branch feat/r4-num-get-members failed closed. It reported one PR with conflicting lines: our own #15712 (collate<wchar_t> members), whose Pending3_049-054 removals in Err.cpp and debt lines sit right next to this PR's. It implements different functions; whichever lands second rebases. No PR has the same exports or new files. It could not compare 8 PRs that conflict with main: #5021, #13486, #13778, #13782, #14212, #14401, #14837 and #14936. I grepped the added and removed lines of every file patch of each one (from the REST files API; for #14212's docs/dev/debt/libSceLibcInternal.md, whose patch the API omits, git diff of the fetched PR head against its merge base) for the 44 NIDs of this batch, the Pending3_055-065, Pending3_080-090 and Pending4 stub names it removes, the num_get/time_get/money_get/money_put member mangled names, InputIterator, NumGetVtable, TimeGetVtable, MoneyGetVtable, MoneyPutVtable and the new file names. None has a match. #15712's lines have no match either.

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:5156316579 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15788). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-11-04T14:51:18Z. --- ### What The 22 public `get` overloads of `num_get<char, istreambuf_iterator<char>>` and `num_get<wchar_t, istreambuf_iterator<wchar_t>>` in libSceLibcInternal threw from the `Pending3` placeholders in `Err.cpp`. They now return `do_get` through the facet's own vtable. These are the calls `std::istream` and `std::wistream` `operator>>` make through `use_facet<num_get<...>>` for `bool`, the integer types, the floating types and `void*`. | Value type | Slot | `char` NID (was) | `wchar_t` NID (was) | |---|---|---|---| | `bool` | 0x20 | `OWO5cpNw3NA` (`Pending3_056`) | `vW-nnV62ea4` (`Pending3_081`) | | `unsigned short` | 0x28 | `gozsp4urvq8` (`Pending3_063`) | `bZ+lKHGvOr8` (`Pending3_088`) | | `unsigned int` | 0x30 | `N1VqUWz2OEI` (`Pending3_060`) | `Y3hBU5FYmhM` (`Pending3_085`) | | `long` | 0x38 | `I2UzwkwwEPs` (`Pending3_061`) | `-m2YPwVCwJQ` (`Pending3_086`) | | `unsigned long` | 0x40 | `2bfL3yIBi5k` (`Pending3_062`) | `94ZLp2+AOq0` (`Pending3_087`) | | `long long` | 0x48 | `4hiQK82QuLc` (`Pending3_064`) | `cG5hQhjFGog` (`Pending3_089`) | | `unsigned long long` | 0x50 | `eZfFLyWCkvg` (`Pending3_065`) | `banNSumaAZ0` (`Pending3_090`) | | `float` | 0x58 | `6RGkooTERsE` (`Pending3_059`) | `2mb8FYgER+E` (`Pending3_084`) | | `double` | 0x60 | `mAwXCpkWaYc` (`Pending3_057`) | `+hjXHfvy1Mg` (`Pending3_082`) | | `long double` | 0x68 | `wUCRGap1j0U` (`Pending3_058`) | `xLZr4GJRMLo` (`Pending3_083`) | | `void*` | 0x70 | `my9ujasm6-0` (`Pending3_055`) | `zomvAQ5RFdA` (`Pending3_080`) | Each NID matches `tools/nid_names.py` `compute_nid` of its mangled name, for example `_ZNKSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE3getES3_S3_RSt8ios_baseRNSt5_IosbIiE8_IostateERb` gives `OWO5cpNw3NA`. The others differ in the character type (`Ic`/`Iw`) and the last letters (`t`, `j`, `l`, `m`, `x`, `y`, `f`, `d`, `e`, `Pv`). All 22 were checked. What each `get` does: - [facet.num.get.members]: `get` returns `do_get(in, end, str, err, val)`. The first microsoft/STL commit does the same for all eleven overloads ([xlocnum L308-L361](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xlocnum#L308-L361)): `return do_get(_First, _Last, _Iosbase, _State, _Val);`. - The forwarder calls the slot for its value type in the vtable of the facet it is given, so a derived facet's override is reached. **The slot order is an inference.** The console's `libSceLibcInternal.sprx` was not read. The standard synopsis ([locale.num.get]) declares `do_get` for bool, long, long long, unsigned short, unsigned int, unsigned long, unsigned long long, float, double, long double and void*. This PR uses the microsoft/STL (Dinkumware) order instead, the order of the `do_get` declarations in [xlocnum L365-L636](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xlocnum#L365-L636): bool, unsigned short, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double, void*, starting after the four `FacetVtable` slots at 0x20. The evidence for that choice is indirect: - main's `GuestLocale::NumPutVtable`, which libc hands to guests as `g_numPutVtable` (`LocaleSupport.cpp`), already lays out `num_put` in the microsoft/STL order (`putLong`, `putUnsignedLong`, `putLongLong`), not the standard's (long, long long, unsigned long); - libc declares `_ZTVSt7num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE` and `_ZTVSt7num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE` with 17 entries: offset-to-top and RTTI, 4 facet slots and 11 `do_get` slots. That fixes the count, not the order. If the console's order differs, the forwarders call the wrong `do_get`. The debt entry says so, and the test pins every slot, so a later change to the order fails it. Changes: - `GuestLocale.hpp`: new `GuestLocale::InputIterator`, an opaque, trivially copyable 16-byte value for `istreambuf_iterator`, with `static_assert`s on its size and triviality. Nothing reads its fields. `istreambuf_iterator<char>` and `istreambuf_iterator<wchar_t>` are both 16 bytes (pointer, `bool`, element padded; the members are `_Strbuf`, `_Got` and `_Val` in [streambuf L519-L521](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/streambuf#L519-L521)) with no user-declared copy constructor or destructor, so both are passed and returned in two integer registers like this struct. - `GuestLocale.hpp`: new `GuestLocale::NumGetVtable` with all eleven slots, a `static_assert` on every slot offset (0x20 to 0x70) and on the size (0x78). The `ios_base::iostate&` argument is `_Iosb<int>::_Iostate&` in the mangled names and is passed as `std::int32_t*`. - New `NumGet.cpp` with the 22 forwarders, and the 22 placeholders removed from `Err.cpp`. - `docs/dev/debt/libSceLibcInternal.md`: the 22 per-NID "prototype and behavior are unverified" entries are removed and one entry records what is still open. The `InputIterator` block in `GuestLocale.hpp` (and its `<type_traits>` include) is byte-for-byte the block of the `time_get` and `money_get`/`money_put` PRs from the same batch, at the same place, so the three merge in any order. `git merge-tree --write-tree` of each pair, of all three, and of each against `main` is clean, and the merged header has one `InputIterator`. Still not done: - Neither libc nor libSceLibcInternal builds a `num_get` facet or implements `do_get`, so today these calls reach only a facet the title provides. The facet constructors, `_Init`, `_Getcat`, `_Getifld`, `_Getffld` and the `do_get` members still throw. - No title was seen calling these exports. ### 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. --> No title was run. I added the guest test `guest_libc_internal_num_get` (`core/libs/tests/GuestLibcInternalNumGet.cpp`). It loads `libSceLibcInternal`, calls each of the 22 exports with a facet whose vtable records every call, and checks: - each of the 22 exports calls the `do_get` slot of its own value type exactly once (every slot of the vtable records a different index, so a forwarder bound to a wrong slot, or a wrong slot order, fails); - the facet, both 16-byte iterators word for word, the stream, the state pointer and the value pointer arrive unchanged; - the export returns the iterator `do_get` returns and leaves the state `do_get` wrote; - with a second vtable standing in for a derived facet, every export reaches the derived slot, not a fixed one. The header `static_assert`s pin every slot offset (0x20 to 0x70) and the size. Results: - **Windows 11, WinLibs GCC 15.2.0 (MinGW), Release:** `ctest -R '^guest_libc_internal_num_get$'` passed 3 of 3 runs (1/1 each), and once more after the negative-control restore. `public_headers` passed. - **Linux, WSL Ubuntu 22.04, GCC 11.4.0, Release:** a fresh clone of `b11c7bf84f` with this commit applied (`git write-tree` equal to the commit's tree) passed `ctest -R '^(guest_libc_internal_num_get|public_headers)$'` 3 of 3 runs (2/2 each), and 1 of 1 after the restore. - **Negative control:** with main's `Err.cpp` put back and `NumGet.cpp` emptied, keeping the new test, the test fails on both hosts with `sceLibcInternalPending3_056_nid_no_patch not implemented` (Windows exit code 0xc0000409, Linux subprocess aborted). - **Conventions:** `python3 tools/check_conventions.py --base origin/main` with this title and body: "All conventions checks passed." - **Progress:** `tools/progress.py` `collect_libraries()` for libSceLibcInternal: done 92 to 114 (+22), todo 1045 to 1023. Overall done 9921 to 9943 of 37146; the total does not change, so no new todo. - **Overlap:** `python3 tools/pr_overlap.py --branch feat/r4-num-get-members` failed closed. It reported one PR with conflicting lines: our own #15712 (collate<wchar_t> members), whose `Pending3_049`-`054` removals in `Err.cpp` and debt lines sit right next to this PR's. It implements different functions; whichever lands second rebases. No PR has the same exports or new files. It could not compare 8 PRs that conflict with main: #5021, #13486, #13778, #13782, #14212, #14401, #14837 and #14936. I grepped the added and removed lines of every file patch of each one (from the REST files API; for #14212's `docs/dev/debt/libSceLibcInternal.md`, whose patch the API omits, `git diff` of the fetched PR head against its merge base) for the 44 NIDs of this batch, the `Pending3_055`-`065`, `Pending3_080`-`090` and `Pending4` stub names it removes, the `num_get`/`time_get`/`money_get`/`money_put` member mangled names, `InputIterator`, `NumGetVtable`, `TimeGetVtable`, `MoneyGetVtable`, `MoneyPutVtable` and the new file names. None has a match. #15712's lines have no match either. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull request closed

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!15788
No description provided.