]> git.lizzy.rs Git - rust.git/commitdiff
Flush to stdout from FileDescriptor::write for `Stdout`
authorSamrat Man Singh <samratmansingh@gmail.com>
Tue, 4 Aug 2020 15:10:48 +0000 (20:40 +0530)
committerSamrat Man Singh <samratmansingh@gmail.com>
Tue, 4 Aug 2020 15:10:48 +0000 (20:40 +0530)
Also, remove unnecessary `-Zmiri-disable-isolation` in test

src/shims/posix/foreign_items.rs
src/shims/posix/fs.rs
tests/compile-fail/fs/write_to_stdin.rs

index 594f58d26461f9cddb9c51004b2787cc9727e5ee..151ab95f1e3c4d278d89a0972ce9ec0b2cda9350 100644 (file)
@@ -1,5 +1,3 @@
-use std::io::{self, Write};
-
 use log::trace;
 
 use rustc_middle::mir;
@@ -76,9 +74,6 @@ fn emulate_foreign_item_by_name(
                 let count = this.read_scalar(n)?.to_machine_usize(this)?;
                 trace!("Called write({:?}, {:?}, {:?})", fd, buf, count);
                 let result = this.write(fd, buf, count)?;
-                if fd == 1 {
-                    io::stdout().flush().unwrap();
-                }
                 // Now, `result` is the value we return back to the program.
                 this.write_scalar(Scalar::from_machine_isize(result, this), dest)?;
             }
index 65d50aa504d3d6b0f3d5c444c496e93144998194..3e1ba3976f776a783fce15a674c6f8facbf03b69 100644 (file)
@@ -76,7 +76,15 @@ fn read(&mut self, _bytes: &mut [u8]) -> InterpResult<'tcx, io::Result<usize>> {
     }
 
     fn write(&mut self, bytes: &[u8]) -> InterpResult<'tcx, io::Result<usize>> {
-        Ok(Write::write(self, bytes))
+        let result = Write::write(self, bytes);
+        // Stdout is buffered, flush to make sure it appears on the
+        // screen.  This is the write() syscall of the interpreted
+        // program, we want it to correspond to a write() syscall on
+        // the host -- there is no good in adding extra buffering
+        // here.
+        io::stdout().flush().unwrap();
+
+        Ok(result)
     }
 
     fn seek(&mut self, _offset: SeekFrom) -> InterpResult<'tcx, io::Result<u64>> {
index 30d24b5dc4443e60e1f258c5a9f521d18911328b..c2754636c860c9d74bf0c7e7c7f8f198bf2715cb 100644 (file)
@@ -1,4 +1,3 @@
-// compile-flags: -Zmiri-disable-isolation
 // ignore-windows: No libc on Windows
 
 #![feature(rustc_private)]