summary refs log tree commit diff
path: root/library/std/src/sys/windows/stdio.rs
AgeCommit message (Collapse)AuthorLines
2021-09-02Auto merge of #83342 - Count-Count:win-console-incomplete-utf8, r=m-ou-sebors-14/+90
Allow writing of incomplete UTF-8 sequences to the Windows console via stdout/stderr # Problem Writes of just an incomplete UTF-8 byte sequence (e.g. `b"\xC3"` or `b"\xF0\x9F"`) to stdout/stderr with a Windows console attached error with `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` even though further writes could complete the codepoint. This is currently a rare occurence since the [linewritershim](https://github.com/rust-lang/rust/blob/2c56ea38b045624dc8b42ec948fc169eaff1206a/library/std/src/io/buffered/linewritershim.rs) implementation flushes complete lines immediately and buffers up to 1024 bytes for incomplete lines. It can still happen as described in #83258. The problem will become more pronounced once the developer can switch stdout/stderr from line-buffered to block-buffered or immediate when the changes in the "Switchable buffering for Stdout" pull request (#78515) get merged. # Patch description If there is at least one valid UTF-8 codepoint all valid UTF-8 is passed through to the extracted `write_valid_utf8_to_console()` fn. The new code only comes into play if `write()` is being passed a short byte slice comprising an incomplete UTF-8 codepoint. In this case up to three bytes are buffered in the `IncompleteUtf8` struct associated with `Stdout` / `Stderr`. The bytes are accepted one at a time. As soon as an error can be detected `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` is returned. Once a complete UTF-8 codepoint is received it is passed to the `write_valid_utf8_to_console()` and the buffer length is set to zero. Calling `flush()` will neither error nor write anything if an incomplete codepoint is present in the buffer. # Tests Currently there are no Windows-specific tests for console writing code at all. Writing (regression) tests for this problem is a bit challenging since unit tests and UI tests don't run in a console and suddenly popping up another console window might be surprising to developers running the testsuite and it might not work at all in CI builds. To just test the new functionality in unit tests the code would need to be refactored. Some guidance on how to proceed would be appreciated. # Public API changes * `std::str::verifications::utf8_char_width()` would be exposed as `std::str::utf8_char_width()` behind the "str_internals" feature gate. # Related issues * Fixes #83258. * PR #78515 will exacerbate the problem. # Open questions * Add tests? * Squash into one commit with better commit message?
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-08-19I/O safety.Dan Gohman-8/+13
Introduce `OwnedFd` and `BorrowedFd`, and the `AsFd` trait, and implementations of `AsFd`, `From<OwnedFd>` and `From<T> for OwnedFd` for relevant types, along with Windows counterparts for handles and sockets. Tracking issue: - <https://github.com/rust-lang/rust/issues/87074> RFC: - <https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md>
2021-07-29Fix may not to appropriate might not or must notAli Malik-1/+1
2021-03-24comment posCount Count-1/+1
2021-03-24assert!() instead of panic!() for expected invariantCount Count-32/+30
2021-03-24rename fn write_valid_utf8() to write_valid_utf8_to_console()Count Count-4/+4
2021-03-24correct commentCount Count-1/+1
2021-03-24use io::Error::new_const() everywhereCount Count-6/+6
2021-03-24fixCount Count-1/+1
2021-03-24Reject byte if it cannot start a valid UTF-8 sequence.Count Count-1/+2
2021-03-24fix c&p errorCount Count-1/+1
2021-03-24Export utf8_char_width() publicly in core::std behind the "str_internals" ↵Count Count-12/+1
feature gate and use it in sys::windows::stdio instead of reimplementing it there.
2021-03-24fix fmtCount Count-2/+2
2021-03-24fix incomplete UTF-8 writes in Windows console stdioCount Count-14/+102
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-6/+6
2020-08-21Make raw standard stream constructors constTomasz Miąsko-3/+3
2020-08-21Remove result type from raw standard streams constructorsTomasz Miąsko-7/+7
Raw standard streams constructors are infallible. Remove unnecessary result type.
2020-07-27mv std libs to library/mark-0/+295