Skip to content

Commit

Permalink
move cvt
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Aug 21, 2019
1 parent a47e3c0 commit 926f364
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/libstd/Cargo.toml
Expand Up @@ -24,6 +24,7 @@ compiler_builtins = { version = "0.1.16" }
profiler_builtins = { path = "../libprofiler_builtins", optional = true }
unwind = { path = "../libunwind" }
hashbrown = { version = "0.5.0", features = ['rustc-dep-of-std'] }
wasi = { git = "https://github.com/newpavlov/rust-wasi", branch = "safe_rework", features = ['rustc-dep-of-std', 'alloc'] }

[dependencies.backtrace]
version = "0.3.35"
Expand Down
23 changes: 0 additions & 23 deletions src/libstd/sys/wasi/mod.rs
Expand Up @@ -102,29 +102,6 @@ pub fn hashmap_random_keys() -> (u64, u64) {
return ret
}

#[doc(hidden)]
pub trait IsMinusOne {
fn is_minus_one(&self) -> bool;
}

macro_rules! impl_is_minus_one {
($($t:ident)*) => ($(impl IsMinusOne for $t {
fn is_minus_one(&self) -> bool {
*self == -1
}
})*)
}

impl_is_minus_one! { i8 i16 i32 i64 isize }

pub fn cvt<T: IsMinusOne>(t: T) -> std_io::Result<T> {
if t.is_minus_one() {
Err(std_io::Error::last_os_error())
} else {
Ok(t)
}
}

fn err2io(err: wasi::Error) -> std_io::Error {
std_io::Error::from_raw_os_error(err.get() as i32)
}
25 changes: 24 additions & 1 deletion src/libstd/sys/wasi/os.rs
Expand Up @@ -9,7 +9,7 @@ use crate::path::{self, PathBuf};
use crate::ptr;
use crate::str;
use crate::sys::memchr;
use crate::sys::{cvt, unsupported, Void};
use crate::sys::{unsupported, Void};
use crate::vec;

#[cfg(not(target_feature = "atomics"))]
Expand Down Expand Up @@ -176,3 +176,26 @@ pub fn exit(code: i32) -> ! {
pub fn getpid() -> u32 {
panic!("unsupported");
}

#[doc(hidden)]
pub trait IsMinusOne {
fn is_minus_one(&self) -> bool;
}

macro_rules! impl_is_minus_one {
($($t:ident)*) => ($(impl IsMinusOne for $t {
fn is_minus_one(&self) -> bool {
*self == -1
}
})*)
}

impl_is_minus_one! { i8 i16 i32 i64 isize }

fn cvt<T: IsMinusOne>(t: T) -> io::Result<T> {
if t.is_minus_one() {
Err(io::Error::last_os_error())
} else {
Ok(t)
}
}

0 comments on commit 926f364

Please sign in to comment.