feat(libc): implement buffered stream purge #10139
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10139"
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 dotaku22 on 2026-10-23T10:37:34Z.
What
Add the missing
fpurgeexport to libc. It discards buffered input,ungetcpushback and pending output without writing or repositioning the descriptor, preserves EOF/error indicators, and returns -1 with EBADF for a closed stream. It holds the existing stream lock and republishes guest stream status.The contract follows FreeBSD 11.4 fpurge.c. Linux uses
__fpurge, macOS uses nativefpurge, and Windows clears the buffer through the UCRT stream representation already used byFileStream. The implementation is original host integration code; no third-party source is copied. Console behavior and host-dependent buffering remain documented in libc technical debt.Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release, based on upstream
513ca7e558(head ad9dc21d9f). No game or console-hardware validation; Linux/macOS are not tested locally.ctest --test-dir build -R '^(guest_stream_purge|guest_binary_word|file_streams|guest_standard_streams.*)$' -V: 6/6 passed, aggregate 1.12 seconds.tools/check_conventions.py --base origin/mainpasses;tools/check_test_registration.pyfinds no newly unregistered executable;git diff --checkpasses.tools/pr_overlap.py --branch feat/libc-fpurgereports no directly conflicting PR. It flags 21 already-conflicting branches that share build/debt files; scoped inspection found nofpurgeimplementation or new test file in those branches. They concern other functions/platforms, so no dependency is required. The branch was subsequently rebased onto the same upstream base used by the overlap scan.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T10:43:54Z.
Review: APPROVED
I reviewed the wrapper and the new cases for output discard, input read-ahead/pushback, unbuffered input, non-seekable pipes, repeated empty purges, status preservation, and closed/null streams. The Linux path uses
__fpurge; the Windows path resets the UCRT buffer pointers/count without seeking, and the macOS path usesfpurge. The existing stream lock surrounds the purge and status synchronization. Locally, GCC 12.2 syntax-checkedStreamPurge.cppandGuestStreamPurge.cpp; a small executable linked to the actual wrapper passed buffered-output discard/no-write/no-seek and EOF-preservation checks. The full repository test target could not be built in this workspace because the configured project lacks SDL2/XRandR dependencies. The author reports Windows 11/MinGW, with the new test and five related CTest entries passing (6/6). Current-main convention, diff-check, and sync checks pass (1 ahead/4 behind; merge clean). Hosted checks currently show conventions, labels, and report success; no product build result is present, so I am not claiming one.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T11:11:28Z.
Review: APPROVED
Reviewed the exact head
171419e9588a301cede51f9a9578f335383401e4. The implementation locks the stream, purges host input/output buffering without seeking, resets the guest buffer cursor, and republishes EOF/error status; platform selection is limited to UCRT, glibc and macOS paths. The regression covers pending output, read-ahead plus pushback, non-seekable pipes, unbuffered input, repeated empty purges, status preservation and closed/null streams. Exact-head conventions and diff checks pass; hosted register-context, relinker platform and ASan checks pass, while full Linux/Windows product jobs were skipped. The PR reports its Windows libc tests passing; I did not independently run those tests. No blocking issue found.