Repository navigation
fix(libc): return flush failures from fflush instead of throwing - #4904
Conversation
fflush threw when the host flush failed, which ends the title on an ordinary write error such as a full disk. FreeBSD's __sflush sets the stream's error flag and returns EOF, as C17 7.21.5.2 asks. fflush now returns the host result and keeps the guest stream's error flag in sync, as fwrite, fputs and fclose already do since boykopovar#4380 and boykopovar#3926.
|
Windows test: head AI-assisted (Claude Code). |
|
Title evidence from Windows (Windows 11, RTX 3080, WinLibs GCC 15.2, Release): XPSemu (PPSA97358), on |
What
fflush(libc/src/FileAndHeap.cpp) throws when the host flush fails, so an ordinary write error such as a full disk ends the title:On a write error, C17 7.21.5.2 asks
fflushto set the stream's error indicator and returnEOF. FreeBSD's__sflushdoes exactly that (fflush.cL126-L137).fflushwas the one stream call left:fwrite,freadandfputsreturn their errors instead of throwing.fclose.fflushto fix(libc): leave a stream that is reading untouched in fflush on Linux #4372, which has since merged without changing the throw.fflushnow returns the host's result and syncs the guest stream's error flag, as those functions do. A stream that was already closed still throws, as the existing test expects. No title is claimed.Tested
Windows 11 (10.0.26300), WinLibs MinGW-w64 GCC 15.2.0 r7 (UCRT), Release,
-DBUILD_TESTING=ON, onmainat c13dc7e:file_streamsnow writes a line into a buffered stream, then replaces the stream's descriptor with a read-only one, so the flush fails withEBADFon both hosts.fflushmust returnEOF, andferrormust report the error.main'sFileAndHeap.cppthe test ends with theterminateabove. With the change it passes 20 runs in a row.core/libs/prx/libc/CMakeLists.txtandcore/libs/prx/libkernel/CMakeLists.txtthat build on Windows.tools/check_conventions.py --base origin/mainpasses.main'sFileAndHeap.cppthe test aborts the same way. With the change it passes 20 runs in a row.main18c438b with feat(libkernel): add getdtablesize #5061 and feat(libkernel): report RLIMIT_NOFILE through getrlimit #5187 merged, stops withfflush: flush failed(0xC0000409) when its Mesa shader-cache write fails under the Windows file lock (fix(libc): make flock advisory on Windows so other descriptors can read and write #4958); with this changefflushreturns the failure and the title reaches xemu's GPU probe, as babyhuey reported in fix(libc): return flush failures from fflush instead of throwing #4904 (comment).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)