Skip to content

wasi: Update and Fix Travis failures #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ matrix:
- gunzip cargo-web.gz
- chmod +x cargo-web
# Get wasmtime
- export VERSION=v0.3.0 # Pin version for stability
- export VERSION=v0.8.0 # Pin version for stability
- wget -O wasmtime.tar.xz https://github.com/CraneStation/wasmtime/releases/download/$VERSION/wasmtime-$VERSION-x86_64-linux.tar.xz
- tar -xf wasmtime.tar.xz --strip-components=1
# Get wasm-bindgen-test-runner which matches our wasm-bindgen version
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ core = { version = "1.0", optional = true, package = "rustc-std-workspace-core"
libc = { version = "0.2.64", default-features = false }

[target.'cfg(target_os = "wasi")'.dependencies]
wasi = "0.7"
wasi = "0.9"

[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = { version = "0.2.29", optional = true }
Expand Down
17 changes: 8 additions & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Error {

cfg_if! {
if #[cfg(unix)] {
fn os_err_desc(errno: i32, buf: &mut [u8]) -> Option<&str> {
fn os_err(errno: i32, buf: &mut [u8]) -> Option<&str> {
let buf_ptr = buf.as_mut_ptr() as *mut libc::c_char;
if unsafe { libc::strerror_r(errno, buf_ptr, buf.len()) } != 0 {
return None;
Expand All @@ -74,12 +74,11 @@ cfg_if! {
core::str::from_utf8(&buf[..idx]).ok()
}
} else if #[cfg(target_os = "wasi")] {
fn os_err_desc(errno: i32, _buf: &mut [u8]) -> Option<&str> {
core::num::NonZeroU16::new(errno as u16)
.and_then(wasi::wasi_unstable::error_str)
fn os_err(errno: i32, _buf: &mut [u8]) -> Option<wasi::Error> {
wasi::Error::from_raw_error(errno as _)
}
} else {
fn os_err_desc(_errno: i32, _buf: &mut [u8]) -> Option<&str> {
fn os_err(_errno: i32, _buf: &mut [u8]) -> Option<&str> {
None
}
}
Expand All @@ -91,8 +90,8 @@ impl fmt::Debug for Error {
if let Some(errno) = self.raw_os_error() {
dbg.field("os_error", &errno);
let mut buf = [0u8; 128];
if let Some(desc) = os_err_desc(errno, &mut buf) {
dbg.field("description", &desc);
if let Some(err) = os_err(errno, &mut buf) {
dbg.field("description", &err);
}
} else if let Some(desc) = internal_desc(*self) {
dbg.field("internal_code", &self.0.get());
Expand All @@ -108,8 +107,8 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(errno) = self.raw_os_error() {
let mut buf = [0u8; 128];
match os_err_desc(errno, &mut buf) {
Some(desc) => f.write_str(desc),
match os_err(errno, &mut buf) {
Some(err) => err.fmt(f),
None => write!(f, "OS Error: {}", errno),
}
} else if let Some(desc) = internal_desc(*self) {
Expand Down
10 changes: 5 additions & 5 deletions src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

//! Implementation for WASI
use crate::Error;
use core::num;
use wasi::wasi_unstable::random_get;
use core::num::NonZeroU32;
use wasi::random_get;

pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
random_get(dest).map_err(|e: num::NonZeroU16| {
// convert wasi's NonZeroU16 error into getrandom's NonZeroU32 error
num::NonZeroU32::new(e.get() as u32).unwrap().into()
unsafe { random_get(dest.as_mut_ptr(), dest.len()) }.map_err(|e: wasi::Error| {
// convert wasi's Error into getrandom's NonZeroU32 error
NonZeroU32::new(e.raw_error() as u32).unwrap().into()
})
}