fix(libc): share multibyte state in fgetwc #10405

Merged
MarcZX10 merged 4 commits from upstream-pr/10405 into main 2026-11-12 06:15:27 +00:00
MarcZX10 commented 2026-10-23 21:51:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T21:51:26Z.


What

Implements fgetwc through the existing guest mbrtowc converter, preserving conversion state in the guest FILE area at offset 0x60. This follows the bundled libc.prx call pattern described in issue #8897: one 16-bit result unit per call, with state stored on the stream. A successful seek and freopen reset the conversion state. Reads hold the host stream lock across the full character conversion; random-device streams use the existing host entropy provider.

This addresses the fgetwc portion of #8897. The remaining fgetws cases are tracked separately, so this PR does not close the issue. Console stream refill behavior and title-specific dynamic locale tables remain unverified and are recorded in the libc debt entry.

Tested

Debian 12, Linux 6.1.0-53-amd64, GCC 12.2.0, Release, CMake configured with BUILD_TESTING=ON.

  • Built guest_standard_stream_tests and libc.prx.
  • ctest --test-dir build-fgetwc-full --output-on-failure -R '^guest_standard_streams$': passed (1/1).
  • The regression cases cover incomplete input at EOF, malformed input followed by clear/seek, rejection of a four-byte sequence by the guest C-locale converter, and reading from a marked random-device stream.
  • python3 tools/check_conventions.py --base upstream/main passed; git diff --check is clean.
  • Not tested on Windows, macOS or a title. No full project build was run.

Checklist

  • Based on current main; no other open PR implements the same function
  • 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: #10324
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4989705969 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10405). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T21:51:26Z. --- ### What Implements `fgetwc` through the existing guest `mbrtowc` converter, preserving conversion state in the guest `FILE` area at offset `0x60`. This follows the bundled `libc.prx` call pattern described in [issue #8897](https://github.com/boykopovar/AnyPS5/issues/8897): one 16-bit result unit per call, with state stored on the stream. A successful seek and `freopen` reset the conversion state. Reads hold the host stream lock across the full character conversion; random-device streams use the existing host entropy provider. This addresses the `fgetwc` portion of #8897. The remaining `fgetws` cases are tracked separately, so this PR does not close the issue. Console stream refill behavior and title-specific dynamic locale tables remain unverified and are recorded in the libc debt entry. ### Tested Debian 12, Linux 6.1.0-53-amd64, GCC 12.2.0, Release, CMake configured with `BUILD_TESTING=ON`. - Built `guest_standard_stream_tests` and `libc.prx`. - `ctest --test-dir build-fgetwc-full --output-on-failure -R '^guest_standard_streams$'`: passed (1/1). - The regression cases cover incomplete input at EOF, malformed input followed by clear/seek, rejection of a four-byte sequence by the guest C-locale converter, and reading from a marked random-device stream. - `python3 tools/check_conventions.py --base upstream/main` passed; `git diff --check` is clean. - Not tested on Windows, macOS or a title. No full project build 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 function - [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: #10324 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-02 04:57:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:57:20Z.

Review: COMMENTED


Reviewed — reconcile request still open, reply answered

The head predates main's fgetwc surrogate fix and is CONFLICTING/DIRTY, so the reviewer's question has a checkable answer: this branch does not yet carry that behavior.

What I ran

  • Live head 7d100f768e4f52970f417d0db32b11942a56ae2c (matches batch).
  • gh pr view 10405 (headRefOid, state, mergeable, statusCheckRollup); gh api GET of issue comments, review comments and reviews, kept newer than 2026-10-27T02:23:07Z.
  • git show of StandardStreams.cpp, Multibyte.cpp and FileStream.hpp at the head; git show 84aec8b0ac for main's fix.
  • Nothing was built or run.

Results

Check Result Note
eligibility, conventions, labels, report SUCCESS hosted
relinker (3 OS), relinker-asan, register-context, write-watch SUCCESS hosted
windows SUCCESS hosted
linux SKIPPED hosted
merge state CONFLICTING / DIRTY matches reviewer's report

Findings

  • oneandonlydean (2026-11-01T11:27:52Z) asks to reconcile with main 84aec8b0ac5, which adds pending low-surrogate handling to fgetwc.
    • Head fgetwc (StandardStreams.cpp:100-156) decodes through mbrtowc_nid_postfix (line 148) and keeps no surrogate state. FileStream.hpp at the head has no lowSurrogate field (grep).
    • Four-byte leads are rejected by Multibyte.cpp:73 (pending == 0 && byte >= 0xf0). Read, not run.
    • Reconciliation and the requested standard-stream regression rerun are not done at this head.
  • Verified: the reviewer's description of both sides. Not verified: whether the composed behavior is correct.

Sources

Not verified

  • Standard-stream regressions and any build: not run.
  • Main's current state beyond the cited commit.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732248541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10405#pullrequestreview-5732248541). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T04:57:20Z. **Review:** COMMENTED --- # Reviewed — reconcile request still open, reply answered The head predates main's fgetwc surrogate fix and is CONFLICTING/DIRTY, so the reviewer's question has a checkable answer: this branch does not yet carry that behavior. ## What I ran - Live head 7d100f768e4f52970f417d0db32b11942a56ae2c (matches batch). - gh pr view 10405 (headRefOid, state, mergeable, statusCheckRollup); gh api GET of issue comments, review comments and reviews, kept newer than 2026-10-27T02:23:07Z. - git show of StandardStreams.cpp, Multibyte.cpp and FileStream.hpp at the head; git show 84aec8b0ac5 for main's fix. - Nothing was built or run. ## Results | Check | Result | Note | |---|---|---| | eligibility, conventions, labels, report | SUCCESS | hosted | | relinker (3 OS), relinker-asan, register-context, write-watch | SUCCESS | hosted | | windows | SUCCESS | hosted | | linux | SKIPPED | hosted | | merge state | CONFLICTING / DIRTY | matches reviewer's report | ## Findings - oneandonlydean (2026-11-01T11:27:52Z) asks to reconcile with main `84aec8b0ac5`, which adds pending low-surrogate handling to fgetwc. - Head fgetwc (StandardStreams.cpp:100-156) decodes through mbrtowc_nid_postfix (line 148) and keeps no surrogate state. FileStream.hpp at the head has no lowSurrogate field (grep). - Four-byte leads are rejected by Multibyte.cpp:73 (`pending == 0 && byte >= 0xf0`). Read, not run. - Reconciliation and the requested standard-stream regression rerun are not done at this head. - Verified: the reviewer's description of both sides. Not verified: whether the composed behavior is correct. ## Sources - https://github.com/boykopovar/AnyPS5/blob/7d100f768e4f52970f417d0db32b11942a56ae2c/core/libs/prx/libc/src/StandardStreams.cpp#L100-L156 - https://github.com/boykopovar/AnyPS5/blob/7d100f768e4f52970f417d0db32b11942a56ae2c/core/libs/prx/libc/src/Multibyte.cpp#L73 - https://github.com/boykopovar/AnyPS5/commit/84aec8b0ac5 ## Not verified - Standard-stream regressions and any build: not run. - Main's current state beyond the cited commit.
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!10405
No description provided.