Repository navigation
fix(libc): leave a stream that is reading untouched in fflush on macOS - #8920
Conversation
The Linux guard from boykopovar#4372 skips the host fflush for a stream that is not writing. On macOS the host fflush of a stream that is reading seeks the descriptor back and drops the read buffer together with a pushed-back character, so guest_standard_streams read "\n" instead of "Zbcdef\n" after fgetc, ungetc and fflush. FreeBSD's __sflush returns without touching a stream whose flags lack __SWR; macOS keeps the same flag in FILE::_flags, so the guard tests it there. The same guard is part of boykopovar#7201. Co-Authored-By: marion909 <103169397+marion909@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
The Apple-only _SWR guard 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.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Thanks for the review. Same note for #8658 (@iamthehimansh): it carries the same |
Independent test: Apple M1 Pro, macOS 27.0.1Apple M1 Pro, macOS 27.0.1, Apple clang 21, x86-64 Release build under Rosetta 2,
AI-assisted: yes (Claude Code ran the build and the tests). |
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(53db0ba,main3fd1cc3) 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 fix(libs): share Sony CRT handler and lconv state between libc and libSceAmpr #7081 and Macos port #7201 forFileAndHeap.cpp; fix(libs): share Sony CRT handler and lconv state between libc and libSceAmpr #7081 does not touchfflush_nid_postfix, Macos port #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