actually empty ready bytes of stdin
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2801,6 +2801,7 @@ dependencies = [
|
|||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"os_pipe",
|
"os_pipe",
|
||||||
"pretty_env_logger",
|
"pretty_env_logger",
|
||||||
|
"system-interface",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"wasi-cap-std-sync",
|
"wasi-cap-std-sync",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ os_pipe = "0.9"
|
|||||||
anyhow = "1.0.19"
|
anyhow = "1.0.19"
|
||||||
wat = "1.0.23"
|
wat = "1.0.23"
|
||||||
cap-std = "0.12"
|
cap-std = "0.12"
|
||||||
|
system-interface = "0.5.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
test_programs = []
|
test_programs = []
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use wasi_cap_std_sync::WasiCtxBuilder;
|
use wasi_cap_std_sync::WasiCtxBuilder;
|
||||||
use wasi_common::pipe::{ReadPipe, WritePipe};
|
use wasi_common::pipe::{ReadPipe, WritePipe};
|
||||||
@@ -90,7 +91,18 @@ pub fn instantiate_inherit_stdio(
|
|||||||
|
|
||||||
// Tests assume that stdin does not have any bytes available to read. Make sure this is the
|
// Tests assume that stdin does not have any bytes available to read. Make sure this is the
|
||||||
// case, regardless of the test environment:
|
// case, regardless of the test environment:
|
||||||
let _ = std::io::stdin().read_to_end().expect("read stdin to end");
|
use std::io::Read;
|
||||||
|
use system_interface::io::ReadReady;
|
||||||
|
let nbytes = std::io::stdin()
|
||||||
|
.num_ready_bytes()
|
||||||
|
.expect("get stdin's ready bytes");
|
||||||
|
if nbytes > 0 {
|
||||||
|
let mut stdin_contents = Vec::new();
|
||||||
|
stdin_contents.resize(nbytes.try_into().expect("ready bytes fits in memory"), 0);
|
||||||
|
std::io::stdin()
|
||||||
|
.read(stdin_contents.as_mut_slice())
|
||||||
|
.expect("read stdin to end");
|
||||||
|
}
|
||||||
|
|
||||||
// Create our wasi context.
|
// Create our wasi context.
|
||||||
// Additionally register any preopened directories if we have them.
|
// Additionally register any preopened directories if we have them.
|
||||||
|
|||||||
Reference in New Issue
Block a user