fix(libc): leave a stream that is reading untouched in fflush on macOS #8920
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8920"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by tkcm01 on 2026-10-21T06:13:54Z.
What
fflush_nid_postfixskips the hostfflushfor a stream that is not writing only on Linux (__fwriting, #4372). On macOS the hostfflushof a stream that is reading seeks the descriptor back and drops the read buffer together with a pushed-back character, so afterfgetc→'a',ungetc('Z')andfflushon"abcdef\n", the nextfreadreturned"\n"instead of"Zbcdef\n"(guest_standard_streams,CheckFlushWhileReading, for both"r"and"r+").FreeBSD's
__sflushreturns without touching a stream whose flags lack__SWR. macOS's stdio keeps the same flag inFILE::_flags(<_stdio.h>), so the macOS branch tests it there.The same two lines are part of the macOS port in #7201 (@marion909, credited as co-author); this splits them out as a small change, as for the rest of the macOS series on #1.
Tested
macOS 27.0.1, Apple M4, Apple clang 21, x86-64 build under Rosetta 2. The libraries do not link on macOS from
mainalone, so the run is on mugurc'sci/macos-series-2(53db0badb,main3fd1cc393) with #7524, the code commits of #7937 and the libSceSsl change from #7332, the setup described on #1. No Vulkan loader, so the AGC/GPU tests are skipped.guest_standard_streamsfails withfflush of a "r" stream that is reading changed the data read next: "\n" (1 bytes), expected "Zbcdef\n" (7 bytes).guest_standard_streamspasses.ctest -j4: 1648 tests, 14 failed, all of which also fail without this change (15 without it, the 15th beingguest_standard_streams); no new failure.#elif defined(__APPLE__)).python3 tools/check_conventions.py --base upstream/main: passed.tools/pr_overlap.pylists #7081 and #7201 forFileAndHeap.cpp; #7081 does not touchfflush_nid_postfix, #7201 contains this same change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T06:17:04Z.
Review: APPROVED
The Apple-only
_SWRguard is narrowly scoped and matches the read-stream behavior this test exercises. The described macOS before/after result is directly relevant, and current PR checks pass for conventions and the focused register-context jobs. I did not rerun the macOS test locally. One coordination point: #7201 currently contains the same guard; if this focused PR lands first, that hunk should be removed from #7201 during its rebase.Imported from boykopovar/AnyPS5. Originally posted by tkcm01 on 2026-10-21T08:12:51Z.
Thanks for the review. Same note for #8658 (@iamthehimansh): it carries the same
__SWRguard infflush_nid_postfix, so if this one lands first that hunk can be dropped from #8658 on rebase, as for #7201.