Skip to content

Commit bdef57e

Browse files
committed
Flush to stdout from FileDescriptor::write for Stdout
Also, remove unnecessary `-Zmiri-disable-isolation` in test
1 parent bea7113 commit bdef57e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/shims/posix/foreign_items.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::io::{self, Write};
2-
31
use log::trace;
42

53
use rustc_middle::mir;
@@ -76,9 +74,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7674
let count = this.read_scalar(n)?.to_machine_usize(this)?;
7775
trace!("Called write({:?}, {:?}, {:?})", fd, buf, count);
7876
let result = this.write(fd, buf, count)?;
79-
if fd == 1 {
80-
io::stdout().flush().unwrap();
81-
}
8277
// Now, `result` is the value we return back to the program.
8378
this.write_scalar(Scalar::from_machine_isize(result, this), dest)?;
8479
}

src/shims/posix/fs.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,15 @@ impl<'tcx> FileDescriptor<'tcx> for io::Stdout {
7676
}
7777

7878
fn write(&mut self, bytes: &[u8]) -> InterpResult<'tcx, io::Result<usize>> {
79-
Ok(Write::write(self, bytes))
79+
let result = Write::write(self, bytes);
80+
// Stdout is buffered, flush to make sure it appears on the
81+
// screen. This is the write() syscall of the interpreted
82+
// program, we want it to correspond to a write() syscall on
83+
// the host -- there is no good in adding extra buffering
84+
// here.
85+
io::stdout().flush().unwrap();
86+
87+
Ok(result)
8088
}
8189

8290
fn seek(&mut self, _offset: SeekFrom) -> InterpResult<'tcx, io::Result<u64>> {

tests/compile-fail/fs/write_to_stdin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// compile-flags: -Zmiri-disable-isolation
21
// ignore-windows: No libc on Windows
32

43
#![feature(rustc_private)]

0 commit comments

Comments
 (0)