8000 Rollup of 13 pull requests by Manishearth · Pull Request #74208 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 13 pull requests #74208

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

Closed
wants to merge 30 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fb9fa5b
adjust ub-enum test to be endianess-independent
RalfJung Jul 3, 2020
bcef848
Explain effects of debugging options from config.toml
tmiasko Jul 5, 2020
6b59cac
Suppress debuginfo on naked function arguments
npmccallum Jul 6, 2020
5702e02
Only allow `repr(i128/u128)` on enum
nbdd0121 Jul 6, 2020
97867bb
Add UI test for issue 74082
nbdd0121 Jul 6, 2020
b82df31
:arrow_up: rust-analyzer
matklad Jul 7, 2020
b50c13c
Update books
ehuss Jul 7, 2020
32025fd
Update rust-installer to latest version
michaelforney May 25, 2020
653c091
Add `read_exact_at` and `write_all_at` to WASI's `FileExt`
sunfishcode Jul 3, 2020
58fc61b
Make WASI's FileExt's read_at/write_at consistent with other targets.
sunfishcode Jul 7, 2020
3c63fba
Correctly mark the ending span of a match arm
ayazhafiz Jul 7, 2020
59f979f
Fix cross-compilation of LLVM to aarch64 Windows targets
arlosi Jul 2, 2020
51b646e
ci: disabled: riscv: minimise docker overlays
tblah Jul 8, 2020
d9fec59
ci: fix context for disabled docker images
tblah Jul 8, 2020
7fb421b
linker: illumos ld does not support --eh-frame-hdr
jclulow Jul 8, 2020
6864546
Add a help to use `in_band_lifetimes` in nightly
JohnTitor Jul 8, 2020
a9b6476
Tweak wording
JohnTitor Jul 9, 2020
557f7b5
Rollup merge of #73989 - RalfJung:ub-enum-test, r=oli-obk
Manishearth Jul 10, 2020
34e4abf
Rollup merge of #74045 - tmiasko:config-debug, r=nikomatsakis
Manishearth Jul 10, 2020
fee1d6f
Rollup merge of #74076 - sunfishcode:wasi-fileext-newmethods, r=alexc…
Manishearth Jul 10, 2020
f9ae411
Rollup merge of #74105 - npmccallum:naked, r=matthewjasper
Manishearth Jul 10, 2020
b993139
Rollup merge of #74109 - nbdd0121:issue-74082, r=petrochenkov
Manishearth Jul 10, 2020
3ef344c
Rollup merge of #74116 - arlosi:aarch64build, r=pietroalbini
Manishearth Jul 10, 2020
b7f4912
Rollup merge of #74125 - ayazhafiz:i/74050, r=matthewjasper
Manishearth Jul 10, 2020
2b6b053
Rollup merge of #74129 - matklad:rust-analyzer-2020-07-07, r=Mark-Sim…
Manishearth Jul 10, 2020
dd65375
Rollup merge of #74135 - ehuss:update-books, r=ehuss
Manishearth Jul 10, 2020
b76b1ac
Rollup merge of #74145 - michaelforney:rust-installer, r=Mark-Simulacrum
Manishearth Jul 10, 2020
f728bb2
Rollup merge of #74161 - tblah:riscv64gc-dockerfile-improvment, r=Mar…
Manishearth Jul 10, 2020
6c73e61
Rollup merge of #74167 - jclulow:illumos-linker-eh-frame-hdr-fix, r=p…
Manishearth Jul 10, 2020
8ba2bfc
Rollup merge of #74168 - JohnTitor:help-for-in-band-lifetimes, r=petr…
Manishearth Jul 10, 2020
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
141 changes: 137 additions & 4 deletions src/libstd/sys/wasi/ext/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner};
///
/// [`File`]: ../../../../std/fs/struct.File.html
pub trait FileExt {
/// Reads a number of bytes starting from a given offset.
///
/// Returns the number of bytes read.
///
/// The offset is relative to the start of the file and thus independent
/// from the current cursor.
///
/// The current file cursor is not affected by this function.
///
/// Note that similar to [`File::read`], it is not an error to return with a
/// short read.
///
/// [`File::read`]: ../../../../std/fs/struct.File.html#method.read
fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
let bufs = &mut [IoSliceMut::new(buf)];
self.read_vectored_at(bufs, offset)
}

/// Reads a number of bytes starting from a given offset.
///
/// Returns the number of bytes read.
Expand All @@ -25,7 +43,80 @@ pub trait FileExt {
/// return with a short read.
///
/// [`File::read`]: ../../../../std/fs/struct.File.html#method.read_vectored
fn read_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize>;
fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize>;

/// Reads the exact number of byte required to fill `buf` from the given offset.
///
/// The offset is relative to the start of the file and thus independent
/// from the current cursor.
///
/// The current file cursor is not affected by this function.
///
/// Similar to [`Read::read_exact`] but uses [`read_at`] instead of `read`.
///
/// [`Read::read_exact`]: ../../../../std/io/trait.Read.html#method.read_exact
/// [`read_at`]: #tymethod.read_at
///
/// # Errors
///
/// If this function encounters an error of the kind
/// [`ErrorKind::Interrupted`] then the error is ignored and the operation
/// will continue.
///
/// If this function encounters an "end of file" before completely filling
/// the buffer, it returns an error of the kind [`ErrorKind::UnexpectedEof`].
/// The contents of `buf` are unspecified in this case.
///
/// If any other read error is encountered then this function immediately
/// returns. The contents of `buf` are unspecified in this case.
///
/// If this function returns an error, it is unspecified how many bytes it
/// has read, but it will never read more than would be necessary to
/// completely fill the buffer.
///
/// [`ErrorKind::Interrupted`]: ../../../../std/io/enum.ErrorKind.html#variant.Interrupted
/// [`ErrorKind::UnexpectedEof`]: ../../../../std/io/enum.ErrorKind.html#variant.UnexpectedEof
#[stable(feature = "rw_exact_all_at", since = "1.33.0")]
fn read_exact_at(&self, mut buf: &mut [u8], mut offset: u64) -> io::Result<()> {
while !buf.is_empty() {
match self.read_at(buf, offset) {
Ok(0) => break,
Ok(n) => {
let tmp = buf;
buf = &mut tmp[n..];
offset += n as u64;
}
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
Err(e) => return Err(e),
}
}
if !buf.is_empty() {
Err(io::Error::new(io::ErrorKind::UnexpectedEof, "failed to fill whole buffer"))
} else {
Ok(())
}
}

/// Writes a number of bytes starting from a given offset.
///
/// Returns the number of bytes written.
///
/// The offset is relative to the start of the file and thus independent
/// from the current cursor.
///
/// The current file cursor is not affected by this function.
///
/// When writing beyond the end of the file, the file is appropriately
/// extended and the intermediate bytes are initialized with the value 0.
///
/// Note that similar to [`File::write`], it is not an error to return a
/// short write.
///
/// [`File::write`]: ../../../../std/fs/struct.File.html#write.v
fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
let bufs = &[IoSlice::new(buf)];
self.write_vectored_at(bufs, offset)
}

/// Writes a number of bytes starting from a given offset.
///
Expand All @@ -43,7 +134,49 @@ pub trait FileExt {
/// short write.
///
/// [`File::write`]: ../../../../std/fs/struct.File.html#method.write_vectored
fn write_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize>;
fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize>;

/// Attempts to write an entire buffer starting from a given offset.
///
/// The offset is relative to the start of the file and thus independent
/// from the current cursor.
///
/// The current file cursor is not affected by this function.
///
/// This method will continuously call [`write_at`] until there is no more data
/// to be written or an error of non-[`ErrorKind::Interrupted`] kind is
/// returned. This method will not return until the entire buffer has been
/// successfully written or such an error occurs. The first error that is
/// not of [`ErrorKind::Interrupted`] kind generated from this method will be
/// returned.
///
/// # Errors
///
/// This function will return the first error of
/// non-[`ErrorKind::Interrupted`] kind that [`write_at`] returns.
///
/// [`ErrorKind::Interrupted`]: ../../../../std/io/enum.ErrorKind.html#variant.Interrupted
/// [`write_at`]: #tymethod.write_at
#[stable(feature = "rw_exact_all_at", since = "1.33.0")]
fn write_all_at(&self, mut buf: &[u8], mut offset: u64) -> io::Result<()> {
while !buf.is_empty() {
match self.write_at(buf, offset) {
Ok(0) => {
return Err(io::Error::new(
io::ErrorKind::WriteZero,
"failed to write whole buffer",
));
}
Ok(n) => {
buf = &buf[n..];
offset += n as u64
}
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
Err(e) => return Err(e),
}
}
Ok(())
}

/// Returns the current position within the file.
///
Expand Down Expand Up @@ -105,11 +238,11 @@ pub trait FileExt {
// FIXME: bind random_get maybe? - on crates.io for unix

impl FileExt for fs::File {
fn read_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
self.as_inner().fd().pread(bufs, offset)
}

fn write_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
self.as_inner().fd().pwrite(bufs, offset)
}

Expand Down
0