fix(libc): convert a wide printf %c like btowc, as titles' libc.prx does #9964

Merged
JJenkx merged 4 commits from upstream-pr/9964 into main 2026-11-04 03:58:52 +00:00
JJenkx commented 2026-10-23 00:30:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-23T00:30:53Z.


What

The wide printf family wrote a narrow %c (no l, or with h/hh) as the argument's low byte taken as a code unit, so 0xE9 became U+00E9. The libc.prx that titles ship converts it the way its btowc does in the UTF-8 C locale (#8855 measures the same btowc):

  • a low byte below 0x80 is that character, so 0x141 gives A and 0x100 gives U+0000;
  • a low byte of 0x80 or above fails the whole call with -1, as #9953's invalid %s does, keeping the output written before the conversion;
  • errno becomes EILSEQ (86) only for 0x80–0xBF and 0xF0–0xFF. The valid lead bytes 0xC0–0xEF and EOF (-1) leave it alone.
Call Bundled libc.prx main
x%cy of 0x80 -1, EILSEQ, buffer x 3: x, U+0080, y
[%3c] of 0xE9 -1, errno unchanged, buffer [ 5
%lc|%c of U+20AC, 0xFF -1, EILSEQ, buffer €| 4
[%c] of -1 -1, errno unchanged 3, with U+00FF

This builds on the WideEncodingError and boolean AppendUtf16 decoder merged in #9953. The single error class retains main's message and partial output; its discriminator distinguishes %c failures that preserve errno. %lc and %C retain main's behavior.

Tested

Current head c22807ee5f65c395d0cca0d544a35d2bd669541f merges main 4f64f81ef7b4bca975b4b9f3dfd15dfff56f716f into the existing PR, as requested. No rebase or force-push.

Linux, Release, independent fresh source/dependency checkout and configuration; built guest_wide_formatting_tests, guest_formatting_tests and guest_stdio_variadic_tests with their full libc dependency. guest_wide_formatting, guest_formatting, guest_stdio_variadic and public_headers pass 4/4, zero skips.

Negative control on prior merge 2c8453337e (candidate formatting source and fixture, and main control source, unchanged in this refresh): the same frozen wide-formatting executable fails at %c of a continuation byte fails with EILSEQ with only FormattingWide.cpp replaced by current main's version. Restoring the candidate rebuilds libc byte-for-byte identically; the four checks pass again. Conventions, whitespace and clean-worktree checks pass.

Linux logs, JUnit, resolved diff and hashes, SHA-256 a6ec6ec866ade26fd53db504dcdd0c4d9514463ebc5ad6c17a3d881b80d2cce9.

Earlier reference measurements on Windows 11/WinLibs GCC15.2 at head 7868aaf64a against #9953 head 8bffaa164a: 44 %c cases match the bundled libc.prx (24 differences on the old main), and a 349,085-format sweep has no differences on PPSA07923/PPSA05916/PPSA13934 (2,843 old-main %c differences). These remain historical measurements of the byte-conversion rule, not a new Windows run of this merge. Console execution and streamed/secure %c error output remain unverified in debt.

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 (CPU-only libc change)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4976014076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9964). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-23T00:30:53Z. --- ### What The wide printf family wrote a narrow `%c` (no `l`, or with `h`/`hh`) as the argument's low byte taken as a code unit, so 0xE9 became U+00E9. The `libc.prx` that titles ship converts it the way its `btowc` does in the UTF-8 C locale (#8855 measures the same `btowc`): - a low byte below 0x80 is that character, so 0x141 gives `A` and 0x100 gives U+0000; - a low byte of 0x80 or above fails the whole call with -1, as #9953's invalid `%s` does, keeping the output written before the conversion; - `errno` becomes `EILSEQ` (86) only for 0x80–0xBF and 0xF0–0xFF. The valid lead bytes 0xC0–0xEF and `EOF` (-1) leave it alone. | Call | Bundled `libc.prx` | `main` | |---|---|---| | `x%cy` of 0x80 | -1, `EILSEQ`, buffer `x` | 3: `x`, U+0080, `y` | | `[%3c]` of 0xE9 | -1, `errno` unchanged, buffer `[` | 5 | | `%lc\|%c` of U+20AC, 0xFF | -1, `EILSEQ`, buffer `€\|` | 4 | | `[%c]` of -1 | -1, `errno` unchanged | 3, with U+00FF | This builds on the `WideEncodingError` and boolean `AppendUtf16` decoder merged in #9953. The single error class retains main's message and partial output; its discriminator distinguishes `%c` failures that preserve errno. `%lc` and `%C` retain main's behavior. ### 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. --> Current head `c22807ee5f65c395d0cca0d544a35d2bd669541f` merges main `4f64f81ef7b4bca975b4b9f3dfd15dfff56f716f` into the existing PR, as requested. No rebase or force-push. Linux, Release, independent fresh source/dependency checkout and configuration; built `guest_wide_formatting_tests`, `guest_formatting_tests` and `guest_stdio_variadic_tests` with their full libc dependency. `guest_wide_formatting`, `guest_formatting`, `guest_stdio_variadic` and `public_headers` pass **4/4, zero skips**. Negative control on prior merge `2c8453337e` (candidate formatting source and fixture, and main control source, unchanged in this refresh): the same frozen wide-formatting executable fails at `%c of a continuation byte fails with EILSEQ` with only `FormattingWide.cpp` replaced by current main's version. Restoring the candidate rebuilds libc byte-for-byte identically; the four checks pass again. Conventions, whitespace and clean-worktree checks pass. [Linux logs, JUnit, resolved diff and hashes](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr9964-main4f64-c22807ee5f-linux-20261102.tar.gz), SHA-256 `a6ec6ec866ade26fd53db504dcdd0c4d9514463ebc5ad6c17a3d881b80d2cce9`. Earlier reference measurements on Windows 11/WinLibs GCC15.2 at head `7868aaf64a` against #9953 head `8bffaa164a`: 44 `%c` cases match the bundled `libc.prx` (24 differences on the old main), and a 349,085-format sweep has no differences on PPSA07923/PPSA05916/PPSA13934 (2,843 old-main `%c` differences). These remain historical measurements of the byte-conversion rule, not a new Windows run of this merge. Console execution and streamed/secure `%c` error output remain unverified in debt. ### 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 (CPU-only libc change) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 00:34:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T00:34:11Z.

Review: APPROVED


Reviewed the exact PR head 7868aaf64a3e5e995a283a5c9d8f2ef7be8abbeb against its declared dependency, #9953 at 8bffaa164af60bb9be39d93b58b5c821bd4e1a01. The implementation and tests cover the measured title behavior for narrow %c, including low-byte conversion, partial swprintf output, and the observed EILSEQ cases; I found no blocking issue in the diff.

I also overlaid the exact PR versions of FormattingWide.cpp and GuestWideFormatting.cpp (plus the debt update) into the existing configured Linux build tree, rebuilt guest_wide_formatting_tests, and ran ctest -R '^guest_wide_formatting$': 1/1 passed. This reused the existing build configuration and prerequisites rather than a fresh PR checkout. git diff --check and the repository convention checker against #9953 passed. Hosted Linux and Windows product jobs are skipped; the author's Windows differential and repeated focused-suite results are recorded in the PR description.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5622578487 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9964#pullrequestreview-5622578487). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T00:34:11Z. **Review:** APPROVED --- Reviewed the exact PR head 7868aaf64a3e5e995a283a5c9d8f2ef7be8abbeb against its declared dependency, #9953 at 8bffaa164af60bb9be39d93b58b5c821bd4e1a01. The implementation and tests cover the measured title behavior for narrow `%c`, including low-byte conversion, partial `swprintf` output, and the observed `EILSEQ` cases; I found no blocking issue in the diff. I also overlaid the exact PR versions of `FormattingWide.cpp` and `GuestWideFormatting.cpp` (plus the debt update) into the existing configured Linux build tree, rebuilt `guest_wide_formatting_tests`, and ran `ctest -R '^guest_wide_formatting$'`: 1/1 passed. This reused the existing build configuration and prerequisites rather than a fresh PR checkout. `git diff --check` and the repository convention checker against #9953 passed. Hosted Linux and Windows product jobs are skipped; the author's Windows differential and repeated focused-suite results are recorded in the PR description.
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!9964
No description provided.