-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
897: Remove special casing of stdin, stdout, and stderr in WASI FS r=MarkMcCaskey a=MarkMcCaskey # Description Properly fixes closing stdin, stdout, stderr. Cleans up this part of the code while it's at it. This PR introduces breaking changes to the pubic WASI API # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Mark McCaskey <mark@wasmer.io>
- Loading branch information
Showing
9 changed files
with
334 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// !!! THIS IS A GENERATED FILE !!! | ||
// ANY MANUAL EDITS MAY BE OVERWRITTEN AT ANY TIME | ||
// Files autogenerated with cargo build (build/wasitests.rs). | ||
|
||
#[test] | ||
fn test_fd_close() { | ||
assert_wasi_output!( | ||
"../../wasitests/fd_close.wasm", | ||
"fd_close", | ||
vec![], | ||
vec![( | ||
".".to_string(), | ||
::std::path::PathBuf::from("wasitests/test_fs/hamlet") | ||
),], | ||
vec![], | ||
"../../wasitests/fd_close.out" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Successfully closed file! | ||
Successfully closed stderr! | ||
Successfully closed stdin! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Args: | ||
// mapdir: .:wasitests/test_fs/hamlet | ||
|
||
use std::fs; | ||
#[cfg(target_os = "wasi")] | ||
use std::os::wasi::prelude::AsRawFd; | ||
use std::path::PathBuf; | ||
|
||
#[cfg(target_os = "wasi")] | ||
#[link(wasm_import_module = "wasi_unstable")] | ||
extern "C" { | ||
fn fd_close(fd: u32) -> u16; | ||
} | ||
|
||
fn main() { | ||
#[cfg(not(target_os = "wasi"))] | ||
let mut base = PathBuf::from("wasitests/test_fs/hamlet"); | ||
#[cfg(target_os = "wasi")] | ||
let mut base = PathBuf::from("."); | ||
|
||
base.push("act3/scene3.txt"); | ||
let file = fs::File::open(&base).expect("could not open file"); | ||
|
||
#[cfg(target_os = "wasi")] | ||
{ | ||
let file_fd = file.as_raw_fd(); | ||
let stdout_fd = std::io::stdout().as_raw_fd(); | ||
let stderr_fd = std::io::stderr().as_raw_fd(); | ||
let stdin_fd = std::io::stdin().as_raw_fd(); | ||
|
||
let result = unsafe { fd_close(file_fd) }; | ||
if result == 0 { | ||
println!("Successfully closed file!") | ||
} else { | ||
println!("Could not close file"); | ||
} | ||
|
||
let result = unsafe { fd_close(stderr_fd) }; | ||
if result == 0 { | ||
println!("Successfully closed stderr!") | ||
} else { | ||
println!("Could not close stderr"); | ||
} | ||
let result = unsafe { fd_close(stdin_fd) }; | ||
if result == 0 { | ||
println!("Successfully closed stdin!") | ||
} else { | ||
println!("Could not close stdin"); | ||
} | ||
let result = unsafe { fd_close(stdout_fd) }; | ||
if result == 0 { | ||
println!("Successfully closed stdout!") | ||
} else { | ||
println!("Could not close stdout"); | ||
} | ||
} | ||
#[cfg(not(target_os = "wasi"))] | ||
{ | ||
println!("Successfully closed file!"); | ||
println!("Successfully closed stderr!"); | ||
println!("Successfully closed stdin!"); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.