diff options
| author | newpavlov <newpavlov@gmail.com> | 2019-08-21 17:57:22 +0300 |
|---|---|---|
| committer | newpavlov <newpavlov@gmail.com> | 2019-08-21 17:57:22 +0300 |
| commit | a47e3c077cd7f201dbbf12140c12663df0fcda6f (patch) | |
| tree | f3d8c8647fff9e00367df0eaf067e7270a8fa31a | |
| parent | 88fd9450aa2111fcbe981006a9c391d57775ec14 (diff) | |
| download | rust-a47e3c077cd7f201dbbf12140c12663df0fcda6f.tar.gz rust-a47e3c077cd7f201dbbf12140c12663df0fcda6f.zip | |
fixes
| -rw-r--r-- | src/libstd/sys/wasi/args.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/ext/fs.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/ext/io.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/fd.rs | 76 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/fs.rs | 16 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/io.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/mod.rs | 27 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/os.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/stdio.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/thread.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sys/wasi/time.rs | 3 |
11 files changed, 69 insertions, 74 deletions
diff --git a/src/libstd/sys/wasi/args.rs b/src/libstd/sys/wasi/args.rs index de9ca62469d..3280c4990dc 100644 --- a/src/libstd/sys/wasi/args.rs +++ b/src/libstd/sys/wasi/args.rs @@ -1,10 +1,10 @@ -use crate::ffi::CStr; -use crate::io; use crate::ffi::OsString; use crate::marker::PhantomData; use crate::os::wasi::ffi::OsStringExt; use crate::vec; +use ::wasi::wasi_unstable as wasi; + pub unsafe fn init(_argc: isize, _argv: *const *const u8) { } @@ -20,7 +20,7 @@ pub struct Args { pub fn args() -> Args { let buf = wasi::args_sizes_get().and_then(|args_sizes| { let mut buf = Vec::with_capacity(args_sizes.get_count()); - wasi::get_args(args_sizes, |arg| { + wasi::args_get(args_sizes, |arg| { let arg = OsString::from_vec(arg.to_vec()); buf.push(arg); })?; diff --git a/src/libstd/sys/wasi/ext/fs.rs b/src/libstd/sys/wasi/ext/fs.rs index ecd509f01da..9fa4abfd171 100644 --- a/src/libstd/sys/wasi/ext/fs.rs +++ b/src/libstd/sys/wasi/ext/fs.rs @@ -8,6 +8,8 @@ use crate::os::wasi::ffi::OsStrExt; use crate::path::{Path, PathBuf}; use crate::sys_common::{AsInner, AsInnerMut, FromInner}; +use ::wasi::wasi_unstable as wasi; + /// WASI-specific extensions to [`File`]. /// /// [`File`]: ../../../../std/fs/struct.File.html diff --git a/src/libstd/sys/wasi/ext/io.rs b/src/libstd/sys/wasi/ext/io.rs index c843144f0c4..f1839df3801 100644 --- a/src/libstd/sys/wasi/ext/io.rs +++ b/src/libstd/sys/wasi/ext/io.rs @@ -8,7 +8,7 @@ use crate::sys; use crate::net; use crate::sys_common::{AsInner, FromInner, IntoInner}; -use wasi::wasi_unstable as wasi; +use ::wasi::wasi_unstable as wasi; /// Raw file descriptors. pub type RawFd = u32; diff --git a/src/libstd/sys/wasi/fd.rs b/src/libstd/sys/wasi/fd.rs index 93fe8add326..275e1319be6 100644 --- a/src/libstd/sys/wasi/fd.rs +++ b/src/libstd/sys/wasi/fd.rs @@ -3,14 +3,15 @@ use crate::io::{self, IoSlice, IoSliceMut, SeekFrom}; use crate::mem; use crate::net::Shutdown; -use wasi::wasi_unstable as wasi; +use super::err2io; +use ::wasi::wasi_unstable as wasi; #[derive(Debug)] pub struct WasiFd { fd: wasi::Fd, } -fn iovec(a: &mut [IoSliceMut<'_>]) -> &[wasi::IoVec] { +fn iovec<'a>(a: &'a mut [IoSliceMut<'_>]) -> &'a [wasi::IoVec] { assert_eq!( mem::size_of::<IoSliceMut<'_>>(), mem::size_of::<wasi::IoVec>() @@ -23,7 +24,7 @@ fn iovec(a: &mut [IoSliceMut<'_>]) -> &[wasi::IoVec] { unsafe { mem::transmute(a) } } -fn ciovec(a: &[IoSlice<'_>]) -> &[wasi::CIoVec] { +fn ciovec<'a>(a: &'a [IoSlice<'_>]) -> &'a [wasi::CIoVec] { assert_eq!( mem::size_of::<IoSlice<'_>>(), mem::size_of::<wasi::CIoVec>() @@ -52,23 +53,23 @@ impl WasiFd { } pub fn datasync(&self) -> io::Result<()> { - wasi::fd_datasync(self.fd).map_err(From::from) + wasi::fd_datasync(self.fd).map_err(err2io) } pub fn pread(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> { - wasi::fd_pread(self.fd, iovec(bufs), offset).map_err(From::from) + wasi::fd_pread(self.fd, iovec(bufs), offset).map_err(err2io) } pub fn pwrite(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> { - wasi::fd_pwrite(self.fd, ciovec(bufs), offset).map_err(From::from) + wasi::fd_pwrite(self.fd, ciovec(bufs), offset).map_err(err2io) } pub fn read(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> { - wasi::fd_read(self.fd, iovec(bufs)).map_err(From::from) + wasi::fd_read(self.fd, iovec(bufs)).map_err(err2io) } pub fn write(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> { - wasi::fd_write(self.fd, ciovec(bufs)).map_err(From::from) + wasi::fd_write(self.fd, ciovec(bufs)).map_err(err2io) } pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> { @@ -77,37 +78,37 @@ impl WasiFd { SeekFrom::End(pos) => (wasi::WHENCE_END, pos), SeekFrom::Current(pos) => (wasi::WHENCE_CUR, pos), }; - wasi::fd_seek(self.fd, offset, whence).map_err(From::from) + wasi::fd_seek(self.fd, offset, whence).map_err(err2io) } pub fn tell(&self) -> io::Result<u64> { - wasi::fd_tell(self.fd).map_err(From::from) + wasi::fd_tell(self.fd).map_err(err2io) } // FIXME: __wasi_fd_fdstat_get pub fn set_flags(&self, flags: wasi::FdFlags) -> io::Result<()> { - wasi::fd_fdstat_set_flags(self.fd, flags).map_err(From::from) + wasi::fd_fdstat_set_flags(self.fd, flags).map_err(err2io) } pub fn set_rights(&self, base: wasi::Rights, inheriting: wasi::Rights) -> io::Result<()> { - wasi::fd_fdstat_set_rights(self.fd, base, inheriting).map_err(From::from) + wasi::fd_fdstat_set_rights(self.fd, base, inheriting).map_err(err2io) } pub fn sync(&self) -> io::Result<()> { - wasi::fd_sync(self.fd).map_err(From::from) + wasi::fd_sync(self.fd).map_err(err2io) } pub fn advise(&self, offset: u64, len: u64, advice: wasi::Advice) -> io::Result<()> { - wasi::fd_advise(self.fd, offset, len, advice).map_err(From::from) + wasi::fd_advise(self.fd, offset, len, advice).map_err(err2io) } pub fn allocate(&self, offset: u64, len: u64) -> io::Result<()> { - wasi::fd_allocate(self.fd, offset, len).map_err(From::from) + wasi::fd_allocate(self.fd, offset, len).map_err(err2io) } pub fn create_directory(&self, path: &[u8]) -> io::Result<()> { - wasi::path_create_directory(self.fd, path).map_err(From::from) + wasi::path_create_directory(self.fd, path).map_err(err2io) } pub fn link( @@ -118,7 +119,7 @@ impl WasiFd { new_path: &[u8], ) -> io::Result<()> { wasi::path_link(self.fd, old_flags, old_path, new_fd.fd, new_path) - .map_err(From::from) + .map_err(err2io) } pub fn open( @@ -130,7 +131,7 @@ impl WasiFd { fs_rights_inheriting: wasi::Rights, fs_flags: wasi::FdFlags, ) -> io::Result<WasiFd> { - let fd = wasi_path_open( + wasi::path_open( self.fd, dirflags, path, @@ -138,25 +139,24 @@ impl WasiFd { fs_rights_base, fs_rights_inheriting, fs_flags, - )?; - Ok(WasiFd::from_raw(fd)) + ).map(|fd| unsafe { WasiFd::from_raw(fd) }).map_err(err2io) } pub fn readdir(&self, buf: &mut [u8], cookie: wasi::DirCookie) -> io::Result<usize> { - wasi::fd_readdir(self.fd, buf, cookie).map_err(From::from) + wasi::fd_readdir(self.fd, buf, cookie).map_err(err2io) } pub fn readlink(&self, path: &[u8], buf: &mut [u8]) -> io::Result<usize> { - wasi::path_readlink(self.fd, path, buf).map_err(From::from) + wasi::path_readlink(self.fd, path, buf).map_err(err2io) } pub fn rename(&self, old_path: &[u8], new_fd: &WasiFd, new_path: &[u8]) -> io::Result<()> { wasi::path_rename(self.fd, old_path, new_fd.fd, new_path) - .map_err(From::from) + .map_err(err2io) } - pub fn filestat_get(&self) -> io::Result<wasi::Filestat> { - wasi::fd_filestat_get(self.fd, buf).map_err(From::from) + pub fn filestat_get(&self) -> io::Result<wasi::FileStat> { + wasi::fd_filestat_get(self.fd).map_err(err2io) } pub fn filestat_set_times( @@ -166,11 +166,11 @@ impl WasiFd { fstflags: wasi::FstFlags, ) -> io::Result<()> { wasi::fd_filestat_set_times(self.fd, atim, mtim, fstflags) - .map_err(From::from) + .map_err(err2io) } pub fn filestat_set_size(&self, size: u64) -> io::Result<()> { - wasi::fd_filestat_set_size(self.fd, size).map_err(From::from) + wasi::fd_filestat_set_size(self.fd, size).map_err(err2io) } pub fn path_filestat_get( @@ -178,7 +178,7 @@ impl WasiFd { flags: wasi::LookupFlags, path: &[u8], ) -> io::Result<wasi::FileStat> { - wasi::path_filestat_get(self.fd, flags, path).map_err(From::from) + wasi::path_filestat_get(self.fd, flags, path).map_err(err2io) } pub fn path_filestat_set_times( @@ -196,19 +196,19 @@ impl WasiFd { atim, mtim, fstflags, - ).map_err(From::from) + ).map_err(err2io) } pub fn symlink(&self, old_path: &[u8], new_path: &[u8]) -> io::Result<()> { - wasi::path_symlink(old_path, self.fd, new_path).map_err(From::from) + wasi::path_symlink(old_path, self.fd, new_path).map_err(err2io) } pub fn unlink_file(&self, path: &[u8]) -> io::Result<()> { - wasi::path_unlink_file(self.fd, path).map_err(From::from) + wasi::path_unlink_file(self.fd, path).map_err(err2io) } pub fn remove_directory(&self, path: &[u8]) -> io::Result<()> { - wasi::path_remove_directory(self.fd, path).map_err(From::from) + wasi::path_remove_directory(self.fd, path).map_err(err2io) } pub fn sock_recv( @@ -216,20 +216,20 @@ impl WasiFd { ri_data: &mut [IoSliceMut<'_>], ri_flags: wasi::RiFlags, ) -> io::Result<(usize, wasi::RoFlags)> { - wasi::sock_recv(self.fd, iovec(ri_data), ri_flags).map_err(From::from) + wasi::sock_recv(self.fd, iovec(ri_data), ri_flags).map_err(err2io) } pub fn sock_send(&self, si_data: &[IoSlice<'_>], si_flags: wasi::SiFlags) -> io::Result<usize> { - wasi::sock_send(self.fd, ciovec(si_data), si_flags).map_err(From::from) + wasi::sock_send(self.fd, ciovec(si_data), si_flags).map_err(err2io) } pub fn sock_shutdown(&self, how: Shutdown) -> io::Result<()> { let how = match how { - Shutdown::Read => WASI::SHUT_RD, - Shutdown::Write => WASI::SHUT_WR, - Shutdown::Both => WASI::SHUT_WR | WASI::SHUT_RD, + Shutdown::Read => wasi::SHUT_RD, + Shutdown::Write => wasi::SHUT_WR, + Shutdown::Both => wasi::SHUT_WR | wasi::SHUT_RD, }; - wasi::sock_shutdown(self.fd, how).map_err(From::from) + wasi::sock_shutdown(self.fd, how).map_err(err2io) } } diff --git a/src/libstd/sys/wasi/fs.rs b/src/libstd/sys/wasi/fs.rs index f23ecfc2bcd..4113f6a2e09 100644 --- a/src/libstd/sys/wasi/fs.rs +++ b/src/libstd/sys/wasi/fs.rs @@ -7,7 +7,7 @@ use crate::os::wasi::ffi::{OsStrExt, OsStringExt}; use crate::path::{Path, PathBuf}; use crate::ptr; use crate::sync::Arc; -use crate::sys::fd::{DirCookie, WasiFd}; +use crate::sys::fd::WasiFd; use crate::sys::time::SystemTime; use crate::sys::unsupported; use crate::sys_common::FromInner; @@ -15,7 +15,7 @@ use crate::sys_common::FromInner; pub use crate::sys_common::fs::copy; pub use crate::sys_common::fs::remove_dir_all; -use wasi::wasi_unstable as wasi; +use ::wasi::wasi_unstable as wasi; pub struct File { fd: WasiFd, @@ -28,7 +28,7 @@ pub struct FileAttr { pub struct ReadDir { inner: Arc<ReadDirInner>, - cookie: Option<DirCookie>, + cookie: Option<wasi::DirCookie>, buf: Vec<u8>, offset: usize, cap: usize, @@ -70,12 +70,6 @@ pub struct FileType { pub struct DirBuilder {} impl FileAttr { - fn zero() -> FileAttr { - FileAttr { - meta: unsafe { mem::zeroed() }, - } - } - pub fn size(&self) -> u64 { self.meta.st_size } @@ -390,7 +384,7 @@ impl File { } pub fn file_attr(&self) -> io::Result<FileAttr> { - self.fd.filestat_get().map_ok(|meta| FileAttr { meta }) + self.fd.filestat_get().map(|meta| FileAttr { meta }) } pub fn metadata_at( @@ -601,7 +595,7 @@ fn metadata_at( path: &Path, ) -> io::Result<FileAttr> { fd.path_filestat_get(flags, path.as_os_str().as_bytes()) - .map_ok(|meta| FileAttr { meta }) + .map(|meta| FileAttr { meta }) } pub fn canonicalize(_p: &Path) -> io::Result<PathBuf> { diff --git a/src/libstd/sys/wasi/io.rs b/src/libstd/sys/wasi/io.rs index ebea3a03e43..4be92faed30 100644 --- a/src/libstd/sys/wasi/io.rs +++ b/src/libstd/sys/wasi/io.rs @@ -1,7 +1,7 @@ use crate::marker::PhantomData; use crate::slice; -use wasi::wasi_unstable as wasi; +use ::wasi::wasi_unstable as wasi; use core::ffi::c_void; #[repr(transparent)] diff --git a/src/libstd/sys/wasi/mod.rs b/src/libstd/sys/wasi/mod.rs index 28b49996d14..89f7c887aaf 100644 --- a/src/libstd/sys/wasi/mod.rs +++ b/src/libstd/sys/wasi/mod.rs @@ -14,10 +14,10 @@ //! compiling for wasm. That way it's a compile time error for something that's //! guaranteed to be a runtime error! -use crate::io; +use crate::io as std_io; use crate::mem; use crate::os::raw::c_char; -use wasi::wasi_unstable as wasi; +use ::wasi::wasi_unstable as wasi; pub mod alloc; pub mod args; @@ -56,16 +56,19 @@ pub mod ext; pub fn init() { } -pub fn unsupported<T>() -> crate::io::Result<T> { +pub fn unsupported<T>() -> std_io::Result<T> { Err(unsupported_err()) } -pub fn unsupported_err() -> io::Error { - io::Error::new(io::ErrorKind::Other, "operation not supported on wasm yet") +pub fn unsupported_err() -> std_io::Error { + std_io::Error::new( + std_io::ErrorKind::Other, + "operation not supported on wasm yet", + ) } -pub fn decode_error_kind(_code: i32) -> io::ErrorKind { - io::ErrorKind::Other +pub fn decode_error_kind(_code: i32) -> std_io::ErrorKind { + std_io::ErrorKind::Other } // This enum is used as the storage for a bunch of types which can't actually @@ -114,16 +117,14 @@ macro_rules! impl_is_minus_one { impl_is_minus_one! { i8 i16 i32 i64 isize } -pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> { +pub fn cvt<T: IsMinusOne>(t: T) -> std_io::Result<T> { if t.is_minus_one() { - Err(io::Error::last_os_error()) + Err(std_io::Error::last_os_error()) } else { Ok(t) } } -impl From<wasi::Error> for io::Error { - fn from(err: wasi::Error) -> Self { - Self::from_raw_os_error(err as i32) - } +fn err2io(err: wasi::Error) -> std_io::Error { + std_io::Error::from_raw_os_error(err.get() as i32) } diff --git a/src/libstd/sys/wasi/os.rs b/src/libstd/sys/wasi/os.rs index dca58179e0c..7ee23c9a35e 100644 --- a/src/libstd/sys/wasi/os.rs +++ b/src/libstd/sys/wasi/os.rs @@ -12,8 +12,6 @@ use crate::sys::memchr; use crate::sys::{cvt, unsupported, Void}; use crate::vec; -use wasi::wasi_unstable as wasi; - #[cfg(not(target_feature = "atomics"))] pub unsafe fn env_lock() -> impl Any { // No need for a lock if we're single-threaded, but this function will need diff --git a/src/libstd/sys/wasi/stdio.rs b/src/libstd/sys/wasi/stdio.rs index dc6a6ef375a..1d57b9922e5 100644 --- a/src/libstd/sys/wasi/stdio.rs +++ b/src/libstd/sys/wasi/stdio.rs @@ -2,7 +2,7 @@ use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem::ManuallyDrop; use crate::sys::fd::WasiFd; -use wasi::wasi_unstable as wasi; +use ::wasi::wasi_unstable as wasi; pub struct Stdin; pub struct Stdout; @@ -74,7 +74,7 @@ impl io::Write for Stderr { pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; pub fn is_ebadf(err: &io::Error) -> bool { - err.raw_os_error() == Some(wasi::EBADF as i32) + err.raw_os_error() == Some(wasi::EBADF.get() as i32) } pub fn panic_output() -> Option<impl io::Write> { diff --git a/src/libstd/sys/wasi/thread.rs b/src/libstd/sys/wasi/thread.rs index a6c8f248701..dc5a72e82a3 100644 --- a/src/libstd/sys/wasi/thread.rs +++ b/src/libstd/sys/wasi/thread.rs @@ -1,10 +1,11 @@ -use crate::cmp; use crate::ffi::CStr; use crate::io; use crate::mem; use crate::sys::{unsupported, Void}; use crate::time::Duration; +use ::wasi::wasi_unstable as wasi; + pub struct Thread(Void); pub const DEFAULT_MIN_STACK_SIZE: usize = 4096; diff --git a/src/libstd/sys/wasi/time.rs b/src/libstd/sys/wasi/time.rs index 4c89a1781b9..4394a22f9c2 100644 --- a/src/libstd/sys/wasi/time.rs +++ b/src/libstd/sys/wasi/time.rs @@ -1,6 +1,5 @@ use crate::time::Duration; -use crate::mem; -use wasi::wasi_unstable as wasi; +use ::wasi::wasi_unstable as wasi; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct Instant(Duration); |
