feat(libSceLibcInternal): implement num_put<char>::put and time_put<char>::put #15715

Merged
B-Howell merged 11 commits from upstream-pr/15715 into main 2026-11-09 09:59:54 +00:00
B-Howell commented 2026-11-04 09:07:48 +00:00 (Migrated from github.com)

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


What

Implements ten libSceLibcInternal exports that threw through NotImplemented_nid_no_patch on main: the public put members of std::num_put<char> and std::time_put<char> (the ostreambuf_iterator<char> instantiations), which operator<< on numbers and std::put_time reach through the stream's facets.

Export NID Stub on main Now
num_put<char>::put(..., bool) (...3putES3_RSt8ios_basecb) nftirmo6hBg sceLibcInternalPending3_106 (Err.cpp) returns the facet's do_put(bool)
num_put<char>::put(..., long) (...basecl) ffnhh0HcxJ4 sceLibcInternalPending3_109 returns do_put(long)
num_put<char>::put(..., unsigned long) (...basecm) uODuM76vS4U sceLibcInternalPending3_110 returns do_put(unsigned long)
num_put<char>::put(..., long long) (...basecx) NJtKruu9qOs sceLibcInternalPending3_111 returns do_put(long long)
num_put<char>::put(..., unsigned long long) (...basecy) dep6W2Ix35s sceLibcInternalPending3_112 returns do_put(unsigned long long)
num_put<char>::put(..., double) (...basecd) w9NzCYAjEpQ sceLibcInternalPending3_107 returns do_put(double)
num_put<char>::put(..., long double) (...basece) VPcTGA-LwSo sceLibcInternalPending3_108 returns do_put(long double)
num_put<char>::put(..., const void*) (...basecPKv) 8NVUcufbklM sceLibcInternalPending3_105 returns do_put(const void*)
time_put<char>::put(..., const tm*, char, char) (...basecPK2tmcc) qkuA-unH7PU sceLibcInternalPending4_069 (Export.cpp) returns the facet's do_put(spec, mod)
time_put<char>::put(..., const tm*, const char*, const char*) (...basecPK2tmPKcSB_) j9LU8GsuEGw sceLibcInternalPending4_068 walks the pattern, see below

Where the behaviour comes from:

  • The C++ standard ([facet.num.put.members]) defines each num_put::put as Returns: do_put(out, str, fill, val)., and [locale.time.put.members] the (spec, mod) overload as Returns: do_put(s, str, fill, t, format, modifier). The Dinkumware code in the first microsoft/STL commit 219514876ea8 writes them the same way: return do_put(_Dest, _Iosbase, _Fill, _Val); (stl/inc/xlocnum L1189-L1227) and return do_put(_Dest, _Iosbase, _Fill, _Pt, _Specifier, _Modifier); (stl/inc/xloctime L680-L683). do_put is virtual, so each export calls the slot of the facet's own vtable (GuestLocale::NumPutVtable putBool 0x20 to putPointer 0x58, TimePutVtable::put 0x20, all already static_asserted). A guest facet that overrides do_put is honoured; libc's own num_put/time_put facets run libc's existing NumPut* and TimePutDoPut.
  • The pattern overload follows the same commit's loop (stl/inc/xloctime L646-L678): it takes use_facet<ctype<char>>(_Iosbase.getloc()), and for each character if (_Ctype_fac.narrow(*_Fmtfirst) != '%') copies it; a trailing % is copied; E, O, Q and # after % are modifiers, and a modifier at the end is copied with its %; every other specifier goes to do_put(_Dest, _Iosbase, _Fill, _Pt, _Specifier, _Modifier), whose returned iterator is used for the rest of the pattern. It is LibcTimePutPattern_nid_no_patch in libc's LocaleSupport.cpp, next to TimePutDoPut, because it uses libc's existing FindFacet (the stream's locale::id lookup that Widen already uses for ctype<char>) and PutCharacter (the ostreambuf_iterator write: a full or null buffer sets failed, and later characters are still offered, as Dinkumware's operator= does: if (!_Strbuf || traits_type::eq_int_type(_Traits::eof(), _Strbuf->sputc(_Right))) { _Failed = true; }, stl/inc/streambuf L555-L561). The export in libSceLibcInternal calls it.
  • Later microsoft/STL commits added _Is_valid_strftime_specifier checks that write ? for some specifiers. That is a later MSVC change, not Dinkumware's, so it is left out: every specifier goes to do_put, as in 219514876ea8 and the standard ("For each valid format sequence identified, calls do_put").
  • Narrowing calls the ctype<char> vtable's do_narrow slot with a null default, as ctype<char>::narrow(c, '\0') does. GuestLocale::CtypeVtable gets narrow (0x50) and narrowRange (0x58) after widenRange with static_asserts, in the declaration order of ctype<char>'s virtuals. These lines are character-for-character the ones the feat/r2-ctype-char-widen branch adds, so the two merge cleanly in either order (checked with git merge-tree).
  • When the stream's locale has no ctype<char> facet, the pattern is narrowed by identity. Dinkumware's use_facet would then create the classic ctype<char> through _Getcat, whose do_narrow returns the character; libc has no ctype<char>::_Getcat, and libc's Widen already treats a missing ctype<char> the same way.

The ten stubs are removed from Err.cpp and Export.cpp; the new exports are in core/libs/prx/libSceLibcInternal/FacetPut.cpp. The debt file drops their ten "prototype and behavior are unverified" lines and gets one entry for what stays unverified: the console's libSceLibcInternal.sprx was not read and no title was seen calling them.

tools/progress.py collect_libraries() on origin/main 5b1d381d5a and on this branch: libSceLibcInternal done 92 -> 102 (+10), todo 1045 -> 1035 (-10); libc unchanged at 1628 done, 19 todo. The repository total goes from 9913 to 9923 done of 37146, so +10 done and no new todo. The branch merges cleanly into the current origin/main b11c7bf84f.

Tested

  • New guest test guest_libc_internal_facet_put (core/libs/tests/GuestLibcInternalFacetPut.cpp). It resolves the ten exports by their NID export names (<NID>_nid_no_patch_cut) from the built libSceLibcInternal.prx, so the same test runs against main's stubs:
    • Each num_put::put calls the do_put slot of its own value type on a recording vtable, passes the facet, stream, fill, iterator and value (INT64_MIN, UINT64_MAX, 0x8000000000000001, -2.5, 1.0L / 3.0L, a pointer), and returns what do_put returned.
    • Through libc's own num_put<char> facet from _Getcat: put(long) gives ***-42 and 0X****FF (hex, showbase, uppercase, internal), put(double) and put(bool) give 0.125 and 1.
    • time_put::put(spec, mod) calls do_put once with its arguments and returns its iterator.
    • The pattern walk with a recording do_put: empty and plain patterns, a%Yb%Ec%Od%%e (four calls, in order, %% going to do_put), Q and # modifiers, unknown and null specifiers, trailing % and %E, %EE, and a failed iterator returned by do_put carried through the rest of the pattern.
    • A locale holding a custom ctype<char>: the pattern is narrowed through it (! to %, q to E, z to d), once per examined character with a null default, literal characters keep their unnarrowed value, and a trailing !q is copied as !E.
    • Through libc's own time_put<char> facet: %Y-%m-%d %H:%M:%S %% %Ey %Oy % gives 2026-10-02 13:05:09 % 26 26 %, put('a') gives Fri, and a streambuf that takes 3 characters marks the iterator failed while all 10 characters of %Y-%m-%d are still offered.
  • Windows 11, WinLibs GCC 15.2.0, Release, commit 87228bb9f8: guest_libc_internal_facet_put, guest_locale (the libc locale code changed here), debt_split and 39 conventions_* tests (the last 40 are checker self-tests of tools/check_conventions.py and the debt-file splitter, not tests of this change) were run 3 times with ctest -j2; 42/42 passed each time (126/126). The other two checker self-tests, conventions_wrapped_declarations and conventions_wrapped_declarations_AbiAliasTests, hit ctest's 30 s timeout on this loaded machine; run directly with python tools/tests/test_check_conventions_wrapped_declarations.py <class> 3 times each, they passed every time (6/6, 19-26 s each).
  • Linux, WSL Ubuntu 22.04, GCC 11.4.0, Release, same commit: the same 44 tests (the 42 above plus both conventions_wrapped_declarations self-tests) were run 3 times with ctest -j2; 44/44 passed each time (132/132).
  • Negative control on Windows and on Linux (commit f7d95ac7bc, whose test file is identical to the final one): main's Err.cpp, Export.cpp, LocaleSupport.cpp and GuestLocale.hpp, with FacetPut.cpp removed and this PR's test, build and the test fails: terminate called after throwing an instance of 'std::runtime_error', what(): sceLibcInternalPending3_106_nid_no_patch not implemented (the first export it calls, put(bool)).
  • python3 tools/check_conventions.py --base origin/main --title ... --body ... with this title and body printed "All conventions checks passed."
  • python3 tools/pr_overlap.py --branch feat/r2-numput-char-put on the final commit probed 1804 open PRs against main b11c7bf84f and failed closed. Its table lists only neighbouring lines, no same exports and no same new files: #14158 and #15692 (libSceLibcInternal/CMakeLists.txt L79, where this PR adds FacetPut.cpp and its test after Filesystem.cpp), and #14373, #14834, #15695 and #15697 (debt file L534, the entry this PR's entry follows). It could not compare #5021, #7081, #9526, #10158, #10165, #10200, #12510, #12511, #12518, #12704, #13486, #13778, #13782, #13881, #14212, #14401, #14837 and #14936. I took the diff of all 24 (gh pr diff; for #5021, which is too large for that, the libSceLibcInternal, LocaleSupport and GuestLocale file patches from the pull request files API), together with #14085 and #15696 from an earlier run, and searched every added and removed line for the ten NIDs, the 3putES3_RSt8ios_base mangled names, the ten stub names, LibcTimePutPattern, CtypeVtable and FacetPut. None has a hit, so none implements these functions or edits the stub lines this PR removes. Whichever of the neighbouring PRs merges second needs a rebase.
  • The branch is on 5b1d381d5a; none of the 87 commits from there to b11c7bf84f touches a file this PR changes, and git merge-tree merges it into b11c7bf84f without conflicts.
  • No title was 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 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:5151800353 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15715). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-11-04T09:07:48Z. --- ### What Implements ten `libSceLibcInternal` exports that threw through `NotImplemented_nid_no_patch` on `main`: the public `put` members of `std::num_put<char>` and `std::time_put<char>` (the `ostreambuf_iterator<char>` instantiations), which `operator<<` on numbers and `std::put_time` reach through the stream's facets. | Export | NID | Stub on `main` | Now | |---|---|---|---| | `num_put<char>::put(..., bool)` (`...3putES3_RSt8ios_basecb`) | `nftirmo6hBg` | `sceLibcInternalPending3_106` (`Err.cpp`) | returns the facet's `do_put(bool)` | | `num_put<char>::put(..., long)` (`...basecl`) | `ffnhh0HcxJ4` | `sceLibcInternalPending3_109` | returns `do_put(long)` | | `num_put<char>::put(..., unsigned long)` (`...basecm`) | `uODuM76vS4U` | `sceLibcInternalPending3_110` | returns `do_put(unsigned long)` | | `num_put<char>::put(..., long long)` (`...basecx`) | `NJtKruu9qOs` | `sceLibcInternalPending3_111` | returns `do_put(long long)` | | `num_put<char>::put(..., unsigned long long)` (`...basecy`) | `dep6W2Ix35s` | `sceLibcInternalPending3_112` | returns `do_put(unsigned long long)` | | `num_put<char>::put(..., double)` (`...basecd`) | `w9NzCYAjEpQ` | `sceLibcInternalPending3_107` | returns `do_put(double)` | | `num_put<char>::put(..., long double)` (`...basece`) | `VPcTGA-LwSo` | `sceLibcInternalPending3_108` | returns `do_put(long double)` | | `num_put<char>::put(..., const void*)` (`...basecPKv`) | `8NVUcufbklM` | `sceLibcInternalPending3_105` | returns `do_put(const void*)` | | `time_put<char>::put(..., const tm*, char, char)` (`...basecPK2tmcc`) | `qkuA-unH7PU` | `sceLibcInternalPending4_069` (`Export.cpp`) | returns the facet's `do_put(spec, mod)` | | `time_put<char>::put(..., const tm*, const char*, const char*)` (`...basecPK2tmPKcSB_`) | `j9LU8GsuEGw` | `sceLibcInternalPending4_068` | walks the pattern, see below | Where the behaviour comes from: - The C++ standard ([facet.num.put.members]) defines each `num_put::put` as `Returns: do_put(out, str, fill, val).`, and [locale.time.put.members] the `(spec, mod)` overload as `Returns: do_put(s, str, fill, t, format, modifier).` The Dinkumware code in the first microsoft/STL commit `219514876ea8` writes them the same way: `return do_put(_Dest, _Iosbase, _Fill, _Val);` ([`stl/inc/xlocnum` L1189-L1227](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xlocnum#L1189-L1227)) and `return do_put(_Dest, _Iosbase, _Fill, _Pt, _Specifier, _Modifier);` ([`stl/inc/xloctime` L680-L683](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xloctime#L680-L683)). `do_put` is virtual, so each export calls the slot of the facet's own vtable (`GuestLocale::NumPutVtable` `putBool` 0x20 to `putPointer` 0x58, `TimePutVtable::put` 0x20, all already static_asserted). A guest facet that overrides `do_put` is honoured; libc's own `num_put`/`time_put` facets run libc's existing `NumPut*` and `TimePutDoPut`. - The pattern overload follows the same commit's loop ([`stl/inc/xloctime` L646-L678](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/xloctime#L646-L678)): it takes `use_facet<ctype<char>>(_Iosbase.getloc())`, and for each character `if (_Ctype_fac.narrow(*_Fmtfirst) != '%')` copies it; a trailing `%` is copied; `E`, `O`, `Q` and `#` after `%` are modifiers, and a modifier at the end is copied with its `%`; every other specifier goes to `do_put(_Dest, _Iosbase, _Fill, _Pt, _Specifier, _Modifier)`, whose returned iterator is used for the rest of the pattern. It is `LibcTimePutPattern_nid_no_patch` in `libc`'s `LocaleSupport.cpp`, next to `TimePutDoPut`, because it uses `libc`'s existing `FindFacet` (the stream's `locale::id` lookup that `Widen` already uses for `ctype<char>`) and `PutCharacter` (the `ostreambuf_iterator` write: a full or null buffer sets `failed`, and later characters are still offered, as Dinkumware's `operator=` does: `if (!_Strbuf || traits_type::eq_int_type(_Traits::eof(), _Strbuf->sputc(_Right))) { _Failed = true; }`, [`stl/inc/streambuf` L555-L561](https://github.com/microsoft/STL/blob/219514876ea86491de191ceaa88632616bbc0f19/stl/inc/streambuf#L555-L561)). The export in `libSceLibcInternal` calls it. - Later microsoft/STL commits added `_Is_valid_strftime_specifier` checks that write `?` for some specifiers. That is a later MSVC change, not Dinkumware's, so it is left out: every specifier goes to `do_put`, as in `219514876ea8` and the standard ("For each valid format sequence identified, calls `do_put`"). - Narrowing calls the `ctype<char>` vtable's `do_narrow` slot with a null default, as `ctype<char>::narrow(c, '\0')` does. `GuestLocale::CtypeVtable` gets `narrow` (0x50) and `narrowRange` (0x58) after `widenRange` with static_asserts, in the declaration order of `ctype<char>`'s virtuals. These lines are character-for-character the ones the `feat/r2-ctype-char-widen` branch adds, so the two merge cleanly in either order (checked with `git merge-tree`). - When the stream's locale has no `ctype<char>` facet, the pattern is narrowed by identity. Dinkumware's `use_facet` would then create the classic `ctype<char>` through `_Getcat`, whose `do_narrow` returns the character; `libc` has no `ctype<char>::_Getcat`, and `libc`'s `Widen` already treats a missing `ctype<char>` the same way. The ten stubs are removed from `Err.cpp` and `Export.cpp`; the new exports are in `core/libs/prx/libSceLibcInternal/FacetPut.cpp`. The debt file drops their ten "prototype and behavior are unverified" lines and gets one entry for what stays unverified: the console's `libSceLibcInternal.sprx` was not read and no title was seen calling them. `tools/progress.py` `collect_libraries()` on `origin/main` `5b1d381d5a` and on this branch: `libSceLibcInternal` done 92 -> 102 (+10), todo 1045 -> 1035 (-10); `libc` unchanged at 1628 done, 19 todo. The repository total goes from 9913 to 9923 done of 37146, so +10 done and no new todo. The branch merges cleanly into the current `origin/main` `b11c7bf84f`. ### 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. --> - New guest test `guest_libc_internal_facet_put` (`core/libs/tests/GuestLibcInternalFacetPut.cpp`). It resolves the ten exports by their NID export names (`<NID>_nid_no_patch_cut`) from the built `libSceLibcInternal.prx`, so the same test runs against `main`'s stubs: - Each `num_put::put` calls the `do_put` slot of its own value type on a recording vtable, passes the facet, stream, fill, iterator and value (`INT64_MIN`, `UINT64_MAX`, `0x8000000000000001`, `-2.5`, `1.0L / 3.0L`, a pointer), and returns what `do_put` returned. - Through `libc`'s own `num_put<char>` facet from `_Getcat`: `put(long)` gives `***-42` and `0X****FF` (hex, showbase, uppercase, internal), `put(double)` and `put(bool)` give `0.125` and `1`. - `time_put::put(spec, mod)` calls `do_put` once with its arguments and returns its iterator. - The pattern walk with a recording `do_put`: empty and plain patterns, `a%Yb%Ec%Od%%e` (four calls, in order, `%%` going to `do_put`), `Q` and `#` modifiers, unknown and null specifiers, trailing `%` and `%E`, `%EE`, and a failed iterator returned by `do_put` carried through the rest of the pattern. - A locale holding a custom `ctype<char>`: the pattern is narrowed through it (`!` to `%`, `q` to `E`, `z` to `d`), once per examined character with a null default, literal characters keep their unnarrowed value, and a trailing `!q` is copied as `!E`. - Through `libc`'s own `time_put<char>` facet: `%Y-%m-%d %H:%M:%S %% %Ey %Oy %` gives `2026-10-02 13:05:09 % 26 26 %`, `put('a')` gives `Fri`, and a streambuf that takes 3 characters marks the iterator failed while all 10 characters of `%Y-%m-%d` are still offered. - Windows 11, WinLibs GCC 15.2.0, Release, commit `87228bb9f8`: `guest_libc_internal_facet_put`, `guest_locale` (the `libc` locale code changed here), `debt_split` and 39 `conventions_*` tests (the last 40 are checker self-tests of `tools/check_conventions.py` and the debt-file splitter, not tests of this change) were run 3 times with `ctest -j2`; 42/42 passed each time (126/126). The other two checker self-tests, `conventions_wrapped_declarations` and `conventions_wrapped_declarations_AbiAliasTests`, hit ctest's 30 s timeout on this loaded machine; run directly with `python tools/tests/test_check_conventions_wrapped_declarations.py <class>` 3 times each, they passed every time (6/6, 19-26 s each). - Linux, WSL Ubuntu 22.04, GCC 11.4.0, Release, same commit: the same 44 tests (the 42 above plus both `conventions_wrapped_declarations` self-tests) were run 3 times with `ctest -j2`; 44/44 passed each time (132/132). - Negative control on Windows and on Linux (commit `f7d95ac7bc`, whose test file is identical to the final one): `main`'s `Err.cpp`, `Export.cpp`, `LocaleSupport.cpp` and `GuestLocale.hpp`, with `FacetPut.cpp` removed and this PR's test, build and the test fails: `terminate called after throwing an instance of 'std::runtime_error'`, `what(): sceLibcInternalPending3_106_nid_no_patch not implemented` (the first export it calls, `put(bool)`). - `python3 tools/check_conventions.py --base origin/main --title ... --body ...` with this title and body printed "All conventions checks passed." - `python3 tools/pr_overlap.py --branch feat/r2-numput-char-put` on the final commit probed 1804 open PRs against `main` `b11c7bf84f` and failed closed. Its table lists only neighbouring lines, no same exports and no same new files: #14158 and #15692 (`libSceLibcInternal/CMakeLists.txt` L79, where this PR adds `FacetPut.cpp` and its test after `Filesystem.cpp`), and #14373, #14834, #15695 and #15697 (debt file L534, the entry this PR's entry follows). It could not compare #5021, #7081, #9526, #10158, #10165, #10200, #12510, #12511, #12518, #12704, #13486, #13778, #13782, #13881, #14212, #14401, #14837 and #14936. I took the diff of all 24 (`gh pr diff`; for #5021, which is too large for that, the `libSceLibcInternal`, `LocaleSupport` and `GuestLocale` file patches from the pull request files API), together with #14085 and #15696 from an earlier run, and searched every added and removed line for the ten NIDs, the `3putES3_RSt8ios_base` mangled names, the ten stub names, `LibcTimePutPattern`, `CtypeVtable` and `FacetPut`. None has a hit, so none implements these functions or edits the stub lines this PR removes. Whichever of the neighbouring PRs merges second needs a rebase. - The branch is on `5b1d381d5a`; none of the 87 commits from there to `b11c7bf84f` touches a file this PR changes, and `git merge-tree` merges it into `b11c7bf84f` without conflicts. - No title was run. ### 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!15715
No description provided.