Skip to content

Commit

Permalink
Flush to stdout from FileDescriptor::write for Stdout
Browse files Browse the repository at this point in the history
Also, remove unnecessary `-Zmiri-disable-isolation` in test
  • Loading branch information
samrat committed Aug 4, 2020
1 parent bea7113 commit bdef57e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/shims/posix/foreign_items.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::io::{self, Write};

use log::trace;

use rustc_middle::mir;
Expand Down Expand Up @@ -76,9 +74,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
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)?;
}
Expand Down
10 changes: 9 additions & 1 deletion src/shims/posix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ impl<'tcx> FileDescriptor<'tcx> for io::Stdout {
}

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>> {
Expand Down
1 change: 0 additions & 1 deletion tests/compile-fail/fs/write_to_stdin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// compile-flags: -Zmiri-disable-isolation
// ignore-windows: No libc on Windows

#![feature(rustc_private)]
Expand Down

0 comments on commit bdef57e

Please sign in to comment.