about summary refs log tree commit diff
path: root/library/std/src/sys/windows/stdio.rs
AgeCommit message (Collapse)AuthorLines
2024-01-11std: begin moving platform support modules into `pal`joboet-462/+0
2023-11-22manual_range_containsChris Denton-2/+2
2023-11-22needless_borrowChris Denton-1/+1
this expression creates a reference which is immediately dereferenced by the compiler
2023-11-22needless_returnChris Denton-1/+1
unneeded `return` statement
2023-10-16Create `windows/api.rs` for safer FFIChris Denton-1/+2
2023-05-31Fix bug in utf16_to_utf8 for zero length stringsShane Murphy-0/+7
This fixes the behavior of sending EOF by pressing Ctrl+Z => Enter in a windows console. Previously, that would trip the unpaired surrogate error, whereas now we correctly detect EOF.
2023-05-05Use new bindingsChris Denton-11/+11
2023-02-25[stdio][windows] Use MBTWC and WCTMBNicole Mazzuca-27/+47
2023-01-14Use associated items of `char` instead of freestanding items in `core::char`Lukas Markeffsky-2/+1
2022-08-30Avoid `MaybeUninit::uninit_array()`Thom Chiovoloni-4/+4
2022-08-30Avoid zeroing large stack buffers in stdio on WindowsThom Chiovoloni-14/+27
2022-02-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-8/+8
2022-01-04Rollup merge of #91754 - Patrick-Poitras:rm-4byte-minimum-stdio-windows, ↵Matthias Krüger-18/+54
r=Mark-Simulacrum Modifications to `std::io::Stdin` on Windows so that there is no longer a 4-byte buffer minimum in read(). This is an attempted fix of issue #91722, where a too-small buffer was passed to the read function of stdio on Windows. This caused an error to be returned when `read_to_end` or `read_to_string` were called. Both delegate to `std::io::default_read_to_end`, which creates a buffer that is of length >0, and forwards it to `std::io::Stdin::read()`. The latter method returns an error if the length of the buffer is less than 4, as there might not be enough space to allocate a UTF-16 character. This creates a problem when the buffer length is in `0 < N < 4`, causing the bug. The current modification creates an internal buffer, much like the one used for the write functions I'd also like to acknowledge the help of ``@agausmann`` and ``@hkratz`` in detecting and isolating the bug, and for suggestions that made the fix possible. Couple disclaimers: - Firstly, I didn't know where to put code to replicate the bug found in the issue. It would probably be wise to add that case to the testing suite, but I'm afraid that I don't know _where_ that test should be added. - Secondly, the code is fairly fundamental to IO operations, so my fears are that this may cause some undesired side effects ~or performance loss in benchmarks.~ The testing suite runs on my computer, and it does fix the issue noted in #91722. - Thirdly, I left the "surrogate" field in the Stdin struct, but from a cursory glance, it seems to be serving the same purpose for other functions. Perhaps merging the two would be appropriate. Finally, this is my first pull request to the rust language, and as such some things may be weird/unidiomatic/plain out bad. If there are any obvious improvements I could do to the code, or any other suggestions, I would appreciate them. Edit: Closes #91722
2021-12-15Modifications to buffer UTF-16 internally so that there is no longer a ↵PFPoitras-18/+54
4-byte buffer minimum. Include suggestions from @agausmann and @Mark-Simulacrum.
2021-12-14Fix a bunch of typosFrank Steffahn-1/+1
2021-10-01Fix ctrl-c causing reads of stdin to return empty on Windows.Arlo Siemsen-9/+19
Fixes #89177
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