Repository navigation
fix(libc): leave write mode when an unbuffered update stream switches to reading on Windows - #12036
Conversation
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head 9f16485c4188efc23cae31f13be4f6012fd4ce59. The Windows-specific flag update is narrowly placed after a successful flush, and the regression matrix exercises seven write APIs crossed with four read paths. The author reports a main control failing before the change and passing after it, plus repeated stream tests; hosted Windows and the Linux/macOS relinker and supporting checks pass. I did not independently reproduce the Windows runtime test.
One repository overlap item remains: the exact pairwise merge preview with open #8150 reports a content conflict in core/libs/tests/FileStreams.cpp. Both PRs add calls in that test executable's main, so this is an integration-order issue even though the test behaviors are distinct. CONTRIBUTING.md requires agreement with the overlapping PR author and a Depends on entry for this case. Please agree with #8150's author which test change lands first and record the order in this checklist; it currently says Depends on: none. The other shared-path hunks I checked (#5021, #7386, #7447 and #10324) do not conflict in the changed SwitchToReadingUnlocked behavior.
I am requesting changes for that coordination requirement, not for a defect in the stream fix.
|
Independent Windows (AMD) and Linux results. Head Windows: Windows 11 Pro 26300, AMD Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7, Ninja Release,
Linux: Ubuntu 22.04 under WSL2, GCC 11.4.0, Release. Not tested: the wider stream and stdio set from the description, a tree with both #12036 and #12057 (both edit AI-assisted (Claude Code). |
adriadam10
left a comment
There was a problem hiding this comment.
The fix and the test look right: clearing UcrtWriting after a successful flush in SwitchToReadingUnlocked (FileStream.hpp:285) matches FreeBSD's __srefill, and the 7 writes x 4 reads matrix pins the position and file contents.
One thing left, the one @MarcZX10 requested: #8150 also adds a call in main of core/libs/tests/FileStreams.cpp and conflicts with this PR there (it already conflicts with main). Please agree with its author which goes first and record it under Depends on (this PR looks like the natural first one, Depends on: none stays if so and #8150 lists #12036). Once that is in the description this can go to the merge queue.
|
@MarcZX10 @adriadam10 Thanks. @Dellz36, #8150 and this PR conflict in Proposed order: this PR first, since it merges cleanly into AI-assisted: yes (Claude Code) |
Re-checked — changes still requestedI agree that #12036 should land before #8150 because it merges cleanly to current What I checked
Results
FindingsBlockingThe suggested #12036-first sequence is reasonable, but it is still a proposal. Please get #8150's author's confirmation and have #8150 record Sources
Not verifiedI did not rerun the test matrix; this reply addresses only the requested integration order, and no code head changed. To get this to a good stateConfirm the order with #8150's author and record it in both PR descriptions before either is merged. |
|
@Ragbie reviewed at 9f16485: PASS. On Windows, @adriadam10 exact-head CI is green (run 40570192797); we'll merge this in the next train unless you'd rather merge it yourself. |
|
The implementation/test PASS is useful, but the overlap blocker I raised remains: #8150 is still open and its author has not confirmed the proposed #12036-first order or recorded |
|
@MarcZX10 Agreed, the order should be recorded on both sides before this merges. We'll keep this PR out of the merge train until #8150's author confirms #12036 first and records |
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
Met: the PR body now records the ordering with #8150 (line 29) and keeps Depends on: none.
What
On Windows a read that follows a write on an unbuffered update stream fails. With
0123456789openedr+bandsetvbuf(_IONBF),fputc('A')andfputc('B')thenfgetcreturnEOFand set the error indicator, where FreeBSD returns'2'.fread,getc_unlocked,ungetcfollowed byfgetc, and anfflushbefore the read fail the same way. Writes that reach the UCRT throughfputc,putc_unlockedorfputwcleave the stream in write mode;fwriteandfputsof more than one byte bypass it and already work.FreeBSD 11.4's
__srefillflushes a stream that is writing, clears__SWRand sets__SRDbefore it reads, and__ungetcdoes the same.FileStream::SwitchToReadingUnlocked(from #8226) flushes and adds_IOREAD, but leaves clearing_IOWRITEto the UCRT's_fflush_nolock. That only happens when the flush writes buffered bytes: a stream without a buffer returns 0 at once with_IOWRITEstill set, and_filbufthen refuses to read.The change clears
_IOWRITEafter a successful flush, before setting_IOREAD. A failed flush leaves the flags as they were, as before. On a buffered stream that the flush wrote, the UCRT has already cleared the flag, so nothing changes there. Linux and macOS are not touched. The libc debt entry already says reads directly after writes follow__srefill, which is now also true for unbuffered streams.Tested
Windows 11 Pro, Intel Core i5-14600KF, WinLibs GCC 15.2.0, full Release build:
file_streamsgetsCheckUnbufferedStreamReadsAfterWrites. On an unbufferedr+bstream over0123456789, each offwrite,fputs,fputc,putc_unlocked,fprintf,fputwcandfputcwithfflushwritesAB. Thenfgetc,getc_unlocked, a one-bytefread, orungetc('Z')with twofgetcmust read'2'without the error indicator,ftellmust give 3, and the file must holdAB23456789.main's sources):file_streamsfails withfgetc after a write on an unbuffered r+ stream. Thefwriteandfputsrounds before it pass.file_streamsand theguest_standard_streamstests pass with--repeat until-fail:5.stream|stdio|printf|wide|format|fopen|freopen|fclose|fwrite|fread|putw|getw|ungetc|gets|scanf|puts|libc|random|fwide|setvbufpass with--repeat until-fail:3, exceptguest_wide_formatting. That test fails onmainhere too:%Zgives the host's non-ASCII zone name, which fix(libc): convert Windows time zone names to UTF-8 #10987 addresses.ctestonmainc547deaac:99% tests passed, 3 tests failed out of 2669.guest_wide_formatting, as above.agc_driver_image_plane_address_on_linealso fails onmainon this machine.agc_driver_mesh_barycentric_emulationfails every time on this machine's NVIDIA GPU withthe pixel shader did not emulate barycentrics. feat(recompiler): read I/J from barycentric built-ins on MoltenVK #9193 changed that test today. It does not use libc streams.check_skips.pyreports one skip,guest_fopen_errors. It skips itself on this machine because creating symbolic links needs Developer Mode.Linux (Ubuntu 24.04 container, GCC 13.3.0), where the change does nothing: the 70 tests matching the same pattern pass with
--repeat until-fail:3, including the new cases.macOS: not tested.
Overlaps:
mainofcore/libs/tests/FileStreams.cpp, so the two conflict there; the tested behaviours are separate. fix(libc): support character reads from random device streams #8150 already conflicts withmaininStandardStreams.cpp,FileStreams.cppanddocs/dev/debt/libc.md. Proposed order, asked of fix(libc): support character reads from random device streams #8150's author in this PR's conversation: this PR first; fix(libc): support character reads from random device streams #8150 then keeps both calls when it rebases and lists fix(libc): leave write mode when an unbuffered update stream switches to reading on Windows #12036 underDepends on. If fix(libc): support character reads from random device streams #8150 goes first instead, this PR rebases after it andDepends onbecomes fix(libc): support character reads from random device streams #8150.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)