Skip to content

fix(libc): leave a stream that is reading untouched in fflush on macOS - #8920

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
tkcm01:fix/libc-fflush-read-stream-macos
Oct 24, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
tkcm01:fix/libc-fflush-read-stream-macos

Conversation

@tkcm01

@tkcm01 tkcm01 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

What

fflush_nid_postfix skips the host fflush for a stream that is not writing only on Linux (__fwriting, #4372). 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 after fgetc → 'a', ungetc('Z') and fflush on "abcdef\n", the next fread returned "\n" instead of "Zbcdef\n" (guest_standard_streams, CheckFlushWhileReading, for both "r" and "r+").

FreeBSD's __sflush returns without touching a stream whose flags lack __SWR. macOS's stdio keeps the same flag in FILE::_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 main alone, so the run is on mugurc's ci/macos-series-2 (53db0ba, main 3fd1cc3) 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.

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
  • AI-assisted: yes

🤖 Generated with Claude Code

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>
@tkcm01 tkcm01 mentioned this pull request Oct 21, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 7201 core/libs/prx/libc/src/FileAndHeap.cpp
PR 9526 core/libs/prx/libc/src/FileAndHeap.cpp
PR 9527 core/libs/prx/libc/src/FileAndHeap.cpp

@github-actions github-actions Bot added the libc label Oct 21, 2026
@tkcm01

tkcm01 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Same note for #8658 (@iamthehimansh): it carries the same __SWR guard in fflush_nid_postfix, so if this one lands first that hunk can be dropped from #8658 on rebase, as for #7201.

@maximilianfv

Copy link
Copy Markdown
Contributor

Independent test: Apple M1 Pro, macOS 27.0.1

Apple M1 Pro, macOS 27.0.1, Apple clang 21, x86-64 Release build under Rosetta 2, BUILD_TESTING=ON, no Vulkan loader. Base: mugurc's ci/macos-series-2 at 27e968974, with this pull request's commit cherry-picked (together with #9971 and #9972, which touch other files).

  • guest_standard_streams: fails on the series alone (fflush of a "r" stream that is reading changed the data read next), and passes with this pull request in 2 of 2 runs.
  • Full ctest -j 6 (mic tests excluded): 15 failures with this change against 20 without, and no test that passed before fails now. The other differences are precise_wait and guest_refused_connect, which are flaky here either way.

AI-assisted: yes (Claude Code ran the build and the tests).

@oneandonlydean oneandonlydean self-assigned this Oct 23, 2026
@oneandonlydean
oneandonlydean merged commit 1d624de into boykopovar:main Oct 24, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants