Skip to content

Commit 9e4d353

Browse files
authored
Rollup merge of rust-lang#72705 - Lucretiel:stdio-forwarding, r=Amanieu
Added io forwarding methods to the stdio structs Added methods to forward the `io::Read` and `io::Write` methods of the myriad wrapper structs in `stdio.rs` to their underlying readers / writers. This is especially important for the structs on the outside of a locking boundary, to ensure that the lock isn't being dropped and re-acquired in a loop.
2 parents 9bdd2db + 14d385b commit 9e4d353

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

src/libstd/io/stdio.rs

+77
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,20 @@ impl Read for StdinRaw {
9696
unsafe fn initializer(&self) -> Initializer {
9797
Initializer::nop()
9898
}
99+
100+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
101+
self.0.read_to_end(buf)
102+
}
103+
104+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
105+
self.0.read_to_string(buf)
106+
}
107+
108+
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
109+
self.0.read_exact(buf)
110+
}
99111
}
112+
100113
impl Write for StdoutRaw {
101114
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
102115
self.0.write(buf)
@@ -114,7 +127,20 @@ impl Write for StdoutRaw {
114127
fn flush(&mut self) -> io::Result<()> {
115128
self.0.flush()
116129
}
130+
131+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
132+
self.0.write_all(buf)
133+
}
134+
135+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
136+
self.0.write_all_vectored(bufs)
137+
}
138+
139+
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
140+
self.0.write_fmt(fmt)
141+
}
117142
}
143+
118144
impl Write for StderrRaw {
119145
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
120146
self.0.write(buf)
@@ -132,6 +158,18 @@ impl Write for StderrRaw {
132158
fn flush(&mut self) -> io::Result<()> {
133159
self.0.flush()
134160
}
161+
162+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
163+
self.0.write_all(buf)
164+
}
165+
166+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
167+
self.0.write_all_vectored(bufs)
168+
}
169+
170+
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
171+
self.0.write_fmt(fmt)
172+
}
135173
}
136174

137175
enum Maybe<T> {
@@ -420,16 +458,37 @@ impl Read for StdinLock<'_> {
420458
unsafe fn initializer(&self) -> Initializer {
421459
Initializer::nop()
422460
}
461+
462+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
463+
self.inner.read_to_end(buf)
464+
}
465+
466+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
467+
self.inner.read_to_string(buf)
468+
}
469+
470+
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
471+
self.inner.read_exact(buf)
472+
}
423473
}
424474

425475
#[stable(feature = "rust1", since = "1.0.0")]
426476
impl BufRead for StdinLock<'_> {
427477
fn fill_buf(&mut self) -> io::Result<&[u8]> {
428478
self.inner.fill_buf()
429479
}
480+
430481
fn consume(&mut self, n: usize) {
431482
self.inner.consume(n)
432483
}
484+
485+
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<usize> {
486+
self.inner.read_until(byte, buf)
487+
}
488+
489+
fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
490+
self.inner.read_line(buf)
491+
}
433492
}
434493

435494
#[stable(feature = "std_debug", since = "1.16.0")]
@@ -593,6 +652,9 @@ impl Write for Stdout {
593652
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
594653
self.lock().write_all(buf)
595654
}
655+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
656+
self.lock().write_all_vectored(bufs)
657+
}
596658
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
597659
self.lock().write_fmt(args)
598660
}
@@ -612,6 +674,12 @@ impl Write for StdoutLock<'_> {
612674
fn flush(&mut self) -> io::Result<()> {
613675
self.inner.borrow_mut().flush()
614676
}
677+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
678+
self.inner.borrow_mut().write_all(buf)
679+
}
680+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
681+
self.inner.borrow_mut().write_all_vectored(bufs)
682+
}
615683
}
616684

617685
#[stable(feature = "std_debug", since = "1.16.0")]
@@ -767,6 +835,9 @@ impl Write for Stderr {
767835
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
768836
self.lock().write_all(buf)
769837
}
838+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
839+
self.lock().write_all_vectored(bufs)
840+
}
770841
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
771842
self.lock().write_fmt(args)
772843
}
@@ -786,6 +857,12 @@ impl Write for StderrLock<'_> {
786857
fn flush(&mut self) -> io::Result<()> {
787858
self.inner.borrow_mut().flush()
788859
}
860+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
861+
self.inner.borrow_mut().write_all(buf)
862+
}
863+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
864+
self.inner.borrow_mut().write_all_vectored(bufs)
865+
}
789866
}
790867

791868
#[stable(feature = "std_debug", since = "1.16.0")]

0 commit comments

Comments
 (0)