fix(libc): flush line-buffered output on Windows #5394

Closed
MarcZX10 wants to merge 3 commits from upstream-pr/5394 into main
MarcZX10 commented 2026-10-13 18:42:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T18:42:05Z.


What

Carries Hussein Kadhim's Windows line-buffering fix from #5391, preserving his commit authorship. Windows' CRT treats _IOLBF as fully buffered, so guest stream writes now flush through the last newline while leaving the remaining tail buffered. The host stream remains buffered; the implementation covers the guest byte, string, formatted, wide and standard-output write paths and holds the stream lock for each line-buffered write. The flag resets when freopen or close replaces the stream and when a later setvbuf changes the mode. The test checks the Windows emulation flag on Windows and native _IOLBF behavior on Linux.

Tested

  • Linux (Ubuntu 24.04, GCC 12.2.0, Ninja, Release): built guest_standard_stream_tests and file_streams_tests; guest_standard_streams and file_streams passed (2/2).
  • Windows: the issue author reports the new line-buffering tests and both CTest cases pass on the proposed fix branch. I did not run a Windows build.
  • tools/check_conventions.py --base upstream/main and git diff --check pass.

Checklist

  • Based on current main; no open PR implements line buffering
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical-debt comments
  • Unimplemented paths throw; no stubs added
  • No notes, investigation files or images added to the repository
  • No third-party code added
  • Generic behavior, not title-specific
  • Depends on: #4627 (overlapping putc_unlocked portability edit) and #4804 (overlapping puts return-value edit); resolve/rebase after those land
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4847833701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5394). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T18:42:05Z. --- ### What Carries Hussein Kadhim's Windows line-buffering fix from [#5391](https://github.com/boykopovar/AnyPS5/issues/5391), preserving his commit authorship. Windows' CRT treats `_IOLBF` as fully buffered, so guest stream writes now flush through the last newline while leaving the remaining tail buffered. The host stream remains buffered; the implementation covers the guest byte, string, formatted, wide and standard-output write paths and holds the stream lock for each line-buffered write. The flag resets when `freopen` or close replaces the stream and when a later `setvbuf` changes the mode. The test checks the Windows emulation flag on Windows and native `_IOLBF` behavior on Linux. ### Tested - Linux (Ubuntu 24.04, GCC 12.2.0, Ninja, Release): built `guest_standard_stream_tests` and `file_streams_tests`; `guest_standard_streams` and `file_streams` passed (2/2). - Windows: the issue author reports the new line-buffering tests and both CTest cases pass on the proposed fix branch. I did not run a Windows build. - `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. ### Checklist - [x] Based on current `main`; no open PR implements line buffering - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical-debt comments - [x] Unimplemented paths throw; no stubs added - [x] No notes, investigation files or images added to the repository - [x] No third-party code added - [x] Generic behavior, not title-specific - [x] Depends on: #4627 (overlapping `putc_unlocked` portability edit) and #4804 (overlapping `puts` return-value edit); resolve/rebase after those land - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
likecrank-dotcom commented 2026-10-13 18:49:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by likecrank-dotcom on 2026-10-13T18:49:10Z.


Independent Windows validation by OpenAI Codex (AI-assisted). No code changes were made to this PR.

Validated PR head 647e18497f087e942b9f89c01d6b5a0d4c15eee6 on Windows 11 Pro (build 26100) with WinLibs MinGW GCC 15.2.0 and CMake 4.4.4. Built guest_standard_stream_tests and file_streams_tests; CTest guest_standard_streams and file_streams each passed five consecutive runs (10/10 executions). tools/check_conventions.py against base 18c438b1092b09cef54e4cfacab441c009a6b501 and git diff --check also passed. This was a focused Windows build/test, not a full build or game run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152756774 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5394#issuecomment-6152756774). Originally posted by [likecrank-dotcom](https://github.com/likecrank-dotcom) on 2026-10-13T18:49:10Z. --- Independent Windows validation by OpenAI Codex (AI-assisted). No code changes were made to this PR. Validated PR head `647e18497f087e942b9f89c01d6b5a0d4c15eee6` on Windows 11 Pro (build 26100) with WinLibs MinGW GCC 15.2.0 and CMake 4.4.4. Built `guest_standard_stream_tests` and `file_streams_tests`; CTest `guest_standard_streams` and `file_streams` each passed five consecutive runs (10/10 executions). `tools/check_conventions.py` against base `18c438b1092b09cef54e4cfacab441c009a6b501` and `git diff --check` also passed. This was a focused Windows build/test, not a full build or game run.
github-actions[bot] commented 2026-10-13 19:10:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T19:10:26Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4804 core/libs/prx/libc/src/Formatting.cpp L544
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153140533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5394#issuecomment-6153140533). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T19:10:26Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4804 | `core/libs/prx/libc/src/Formatting.cpp` [L544](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L544) | | |
xXPBSXx commented 2026-10-14 01:09:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T01:09:08Z.


Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, -j4: head 647e18497 of this PR merged onto main 19785b50e (clean merge, 8 files).

  • guest_standard_streams (0.79 s) and guest_formatting (0.16 s) pass (2 of 2, ctest).
  • A run without the change cannot show the behaviour: with the six product files taken back to main (and the two new headers removed) the new test does not compile (GuestStandardStreams.cpp:247 and :262: class FileStream has no member named IsLineBuffered), so the new test checks an interface that main lacks and fails to build there; a behavioural red run was not possible with this test.
  • Not run: Linux, a console, a title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158603517 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5394#issuecomment-6158603517). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T01:09:08Z. --- Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, `-j4`: head `647e18497` of this PR merged onto `main` `19785b50e` (clean merge, 8 files). - `guest_standard_streams` (0.79 s) and `guest_formatting` (0.16 s) pass (2 of 2, ctest). - A run without the change cannot show the behaviour: with the six product files taken back to `main` (and the two new headers removed) the new test does not compile (`GuestStandardStreams.cpp:247` and `:262`: `class FileStream` has no member named `IsLineBuffered`), so the new test checks an interface that `main` lacks and fails to build there; a behavioural red run was not possible with this test. - Not run: Linux, a console, a title. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-14 02:27:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:27:41Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159526954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5394#issuecomment-6159526954). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:27:41Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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