feat(libc): format time_put<char>::do_put as the console's libc does #11044

Merged
verusferro merged 1 commit from upstream-pr/11044 into main 2026-10-26 22:00:15 +00:00
verusferro commented 2026-10-25 14:58:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by verusferro on 2026-10-25T14:58:44Z.


What

time_put<char>::do_put threw (TimePutMethodUnsupported), so a title that formats a std::tm through a stream (std::put_time, time_put::put) stopped there. It now does what the SDK libc.prx that PPSA06416 ships in sce_module/ (title SDK 7.00) does, read from its disassembly (REVERSE_ENGINEERING, source 2). The module exports it as +i81FtUCarA (0x9aa00):

  • It builds the format !% followed by the modifier and the conversion, or the conversion alone when the modifier is 0, and runs _Strftime on it, the same function strftime calls. It starts with a 16-byte buffer and doubles it until the result fits; the leading ! tells an empty result from one that did not fit, and is dropped.
  • It writes each remaining character through the output iterator the way the inline sputc does. When the stream buffer's put pointer (*(buffer + 0x40)) is set and (int)(*(buffer + 0x60) - next) > 0, it stores the character and advances the pointer. Otherwise it calls overflow, vtable slot 4, and marks the iterator failed when that returns eof. A null buffer marks the iterator failed. A failed iterator still offers the rest of the characters, and the stream and fill arguments are not read.

The facet gets a vtable with its single do_put slot instead of eight throwing slots. The formatting goes through this library's strftime, so its gaps carry over. GuestLocale.hpp describes the three guest types this touches: the stream buffer's put pointers, its overflow slot and the 16-byte iterator, which arrives in two registers and is returned in RAX:RDX.

The debt entry for these facets now says time_put formats through strftime. To keep it under 1000 characters, the std::clog, std::wclog and facet id sizes that shared it move to an entry of their own, unchanged.

Tested

Ubuntu 24.04 (WSL2) x86-64, GCC 13.3, Release, full build with BUILD_TESTING=ON:

  • The title's libc.prx, converted by the relinker and loaded in a host process, compared against this library's facet with the same fake stream buffer. That covers every conversion byte 0-255 with no modifier and with E, O, #, x, Y, 0x80 and %, each with room in the buffer, 2 bytes of room with overflow refusing every character or every other one, a null put pointer and a null buffer: 8,176 calls. Stored bytes, the order of overflow calls, the failed flag and the returned iterator match in all of them except the 12 %Z calls. There the module prints the empty zone name of a process without TZ and this library prints the host's, as the existing tzname debt entry records. A format that ends after E or O is left out: the console crashes there and strftime throws.
  • guest_locale gains CheckTimePut: a conversion that fits, one that runs into overflow part way (and needs a 32-byte buffer), E and O, a 0 conversion, an unknown conversion, overflow refusing (all 8 characters are still offered), a null put pointer and a null buffer. Emitting the ! as well fails it.
  • ctest -R '^(guest_locale|guest_strftime|patched_libraries|conventions_unknown_nids)$': 4/4 pass.
  • tools/progress.py: libc +1 implemented (TimePutDoPut), TimePutMethodUnsupported removed.
  • python3 tools/check_conventions.py --base origin/main: passed. python3 tools/pr_overlap.py: no conflicting lines or same exports; none of the 39 pull requests it could not compare touches time_put, the stream buffer types or this debt entry.

Windows: not run by me. guest_locale passed in @ycbuzi's run of 186fbf3b8f and in @wachi35676's run of this head 3338ffefff, as the parent of #11054.

Not tested: macOS, a title that calls put_time.

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:5005832889 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11044). Originally posted by [verusferro](https://github.com/verusferro) on 2026-10-25T14:58:44Z. --- ### What `time_put<char>::do_put` threw (`TimePutMethodUnsupported`), so a title that formats a `std::tm` through a stream (`std::put_time`, `time_put::put`) stopped there. It now does what the SDK `libc.prx` that PPSA06416 ships in `sce_module/` (title SDK 7.00) does, read from its disassembly ([REVERSE_ENGINEERING](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/REVERSE_ENGINEERING.md), source 2). The module exports it as `+i81FtUCarA` (0x9aa00): - It builds the format `!%` followed by the modifier and the conversion, or the conversion alone when the modifier is 0, and runs `_Strftime` on it, the same function `strftime` calls. It starts with a 16-byte buffer and doubles it until the result fits; the leading `!` tells an empty result from one that did not fit, and is dropped. - It writes each remaining character through the output iterator the way the inline `sputc` does. When the stream buffer's put pointer (`*(buffer + 0x40)`) is set and `(int)(*(buffer + 0x60) - next) > 0`, it stores the character and advances the pointer. Otherwise it calls `overflow`, vtable slot 4, and marks the iterator failed when that returns `eof`. A null buffer marks the iterator failed. A failed iterator still offers the rest of the characters, and the stream and fill arguments are not read. The facet gets a vtable with its single `do_put` slot instead of eight throwing slots. The formatting goes through this library's `strftime`, so its gaps carry over. `GuestLocale.hpp` describes the three guest types this touches: the stream buffer's put pointers, its `overflow` slot and the 16-byte iterator, which arrives in two registers and is returned in RAX:RDX. The debt entry for these facets now says `time_put` formats through `strftime`. To keep it under 1000 characters, the `std::clog`, `std::wclog` and facet id sizes that shared it move to an entry of their own, unchanged. ### 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. --> Ubuntu 24.04 (WSL2) x86-64, GCC 13.3, Release, full build with `BUILD_TESTING=ON`: - The title's `libc.prx`, converted by the relinker and loaded in a host process, compared against this library's facet with the same fake stream buffer. That covers every conversion byte 0-255 with no modifier and with `E`, `O`, `#`, `x`, `Y`, 0x80 and `%`, each with room in the buffer, 2 bytes of room with `overflow` refusing every character or every other one, a null put pointer and a null buffer: 8,176 calls. Stored bytes, the order of `overflow` calls, the failed flag and the returned iterator match in all of them except the 12 `%Z` calls. There the module prints the empty zone name of a process without `TZ` and this library prints the host's, as the existing `tzname` debt entry records. A format that ends after `E` or `O` is left out: the console crashes there and `strftime` throws. - `guest_locale` gains `CheckTimePut`: a conversion that fits, one that runs into `overflow` part way (and needs a 32-byte buffer), `E` and `O`, a 0 conversion, an unknown conversion, `overflow` refusing (all 8 characters are still offered), a null put pointer and a null buffer. Emitting the `!` as well fails it. - `ctest -R '^(guest_locale|guest_strftime|patched_libraries|conventions_unknown_nids)$'`: 4/4 pass. - `tools/progress.py`: libc +1 implemented (`TimePutDoPut`), `TimePutMethodUnsupported` removed. - `python3 tools/check_conventions.py --base origin/main`: passed. `python3 tools/pr_overlap.py`: no conflicting lines or same exports; none of the 39 pull requests it could not compare touches `time_put`, the stream buffer types or this debt entry. Windows: not run by me. `guest_locale` passed in [@ycbuzi's run](https://github.com/boykopovar/AnyPS5/pull/11044#issuecomment-6399720304) of `186fbf3b8f` and in [@wachi35676's run](https://github.com/boykopovar/AnyPS5/pull/11044#issuecomment-6403822734) of this head `3338ffefff`, as the parent of #11054. Not tested: macOS, a title that calls `put_time`. ### 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
MarcZX10 commented 2026-10-25 15:16:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:16:45Z.

Review: APPROVED


Reviewed exact head 186fbf3b8f92f8c649bd869180af12887b4a8922. The guest streambuf offsets and vtable slot are statically asserted, the formatter follows the observed leading-sentinel and overflow behavior, and failed iterators still receive every output character. The focused test covers formatting, overflow rejection, null put-next, and null iterator buffer. The author also reports 8,176 comparisons against the title SDK implementation with only the documented timezone difference. Hosted conventions, intake, eligibility, relinker, sanitizer, and register-context checks pass; product jobs are skipped by path policy. I reviewed the implementation and test but did not run the full local build here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643826340 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11044#pullrequestreview-5643826340). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T15:16:45Z. **Review:** APPROVED --- Reviewed exact head 186fbf3b8f92f8c649bd869180af12887b4a8922. The guest streambuf offsets and vtable slot are statically asserted, the formatter follows the observed leading-sentinel and overflow behavior, and failed iterators still receive every output character. The focused test covers formatting, overflow rejection, null put-next, and null iterator buffer. The author also reports 8,176 comparisons against the title SDK implementation with only the documented timezone difference. Hosted conventions, intake, eligibility, relinker, sanitizer, and register-context checks pass; product jobs are skipped by path policy. I reviewed the implementation and test but did not run the full local build here.
MarcZX10 commented 2026-10-25 15:51:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:51:16Z.

Review: CHANGES_REQUESTED


I manually checked the exact heads of #9456 (159a6f44078e56a677b354da7e0d88688583a7f7) and #9468 (ef2f603255e817198618bd38a1fddd803b115ce5) against this PR (186fbf3b8f92f8c649bd869180af12887b4a8922). git merge-tree reports a content conflict only in core/libs/tests/GuestLocale.cpp; all three branches close CheckFacetGetcat and add a separate check at that insertion point. The implementation additions appear independent, and a combined result should retain one closing brace plus all three checks. Per CONTRIBUTING.md, please coordinate merge order with the other authors and declare the agreed dependency on the checklist (Depends on: #N) before this PR is considered ready. This is a merge-order issue, not a finding that the time_put implementation overlaps semantically with time_get or num_get.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643984376 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11044#pullrequestreview-5643984376). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T15:51:16Z. **Review:** CHANGES_REQUESTED --- I manually checked the exact heads of #9456 (`159a6f44078e56a677b354da7e0d88688583a7f7`) and #9468 (`ef2f603255e817198618bd38a1fddd803b115ce5`) against this PR (`186fbf3b8f92f8c649bd869180af12887b4a8922`). `git merge-tree` reports a content conflict only in `core/libs/tests/GuestLocale.cpp`; all three branches close `CheckFacetGetcat` and add a separate check at that insertion point. The implementation additions appear independent, and a combined result should retain one closing brace plus all three checks. Per `CONTRIBUTING.md`, please coordinate merge order with the other authors and declare the agreed dependency on the checklist (`Depends on: #N`) before this PR is considered ready. This is a merge-order issue, not a finding that the `time_put` implementation overlaps semantically with `time_get` or `num_get`.
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!11044
No description provided.