

Modifications to `std::io::Stdin` on Windows so that there is no longer a 4-byte...
source link: https://github.com/rust-lang/rust/pull/91754
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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
Recommend
-
50
In this post I want to discuss faking (or redirecting ) standard input and output ( os.Stdin and os.Stdout ) in Go programs. This is often done in tests, but may also be useful in other scenarios. ...
-
21
2019-02-10IntroductionWhen I wrote my last two tools multicode and epoch, I wanted them to work with...
-
28
Read a file (stdin) line by line yourbasic.org/golang Read from file Use a
-
29
Introduction Among the popular operating systems, they have all standardized on using standard input, standard output, and standard error with file desciptors 0, 1, and 2 respectively. This allows you to pipe the inputs and outputs...
-
27
Introduction Operating systems recognize a couple special file descriptor IDs: STDIN - 0 - Input usally coming in from keyboard. STDOUT - 1 - Output from the...
-
19
让ssh从stdin读取密码 执行像ssh,scp这类secure command时,必须手工输入密码,而且它们是直接从/dev/tty而不是stdin中读取密码的,这也意味着无法通过重定向IO的方式传送密码給这些程序. 查了一下网上一般的解决方案是借助 paramiko
-
11
How can I read a single line from stdin? Join Stack Overflow to learn, share knowledge, and build your career.
-
6
STDIN for Node JS in Windows. STDIN for Node JS in Windows. I recently started using Node...
-
15
X servers no longer allow byte-swapped clients In the beginning, there was the egg. Then fictional people started eating that from different ends, and...
-
5
Hutterer: X servers no longer allow byte-swapped clients [Posted January 6, 2023 by corbet] Peter Hutterer
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK