-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add read_buf
equivalents for positioned reads
#140459
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
74e016c
to
2ccb45f
Compare
Have these changes been discussed with libs-api at all? Usually changes to unstable API need to be proposed at https://github.com/rust-lang/libs-team/ with the ACP issue template. This needs some tests as well. |
For the above, |
Reminder, once the PR becomes ready for a review, use |
For consistency and clarity, could we include safety comments on each unsafe block? Even brief notes are helpful to understand the assumptions being made |
2ccb45f
to
09ac65a
Compare
This comment has been minimized.
This comment has been minimized.
09ac65a
to
a22d2b4
Compare
This comment has been minimized.
This comment has been minimized.
a22d2b4
to
59cb58e
Compare
This comment has been minimized.
This comment has been minimized.
59cb58e
to
85e1da1
Compare
Thank you both.
@rustbot ready |
library/std/src/sys/fd/unix.rs
Outdated
#[cfg(not(any( | ||
all(target_os = "linux", not(target_env = "musl")), | ||
target_os = "android", | ||
target_os = "hurd" | ||
)))] | ||
use libc::pread as pread64; | ||
#[cfg(any( | ||
all(target_os = "linux", not(target_env = "musl")), | ||
target_os = "android", | ||
target_os = "hurd" | ||
))] | ||
use libc::pread64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is getting moved anyway, mind simplifying this with cfg_select!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Did I pick the right place for #![feature(cfg_select)]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I would put it at the top with the off64_t
import, some of that config might be sharable.
@bors try |
Add `read_buf` equivalents for positioned reads Adds the following items under the ~~`read_buf` (#78485)~~ `read_buf_at` (#140771) feature: - `std::os::unix::fs::FileExt::read_buf_at` - `std::os::unix::fs::FileExt::read_buf_exact_at` - `std::os::windows::fs::FileExt::seek_read_buf` try-job: x86_64-msvc-1 try-job: x86_64-msvc-2
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
85e1da1
to
05dcef0
Compare
This comment has been minimized.
This comment has been minimized.
Adds the following items under the `read_buf_at` feature: - `std::os::unix::fs::FileExt::read_buf_at` - `std::os::unix::fs::FileExt::read_buf_exact_at` - `std::os::windows::fs::FileExt::seek_read_buf`
05dcef0
to
e8a35d4
Compare
Ready for the next round of review. The failed test on Windows was an assertion that I had (blindly) added about the seek position after @rustbot ready |
// SAFETY: `read` bytes were written to the initialized portion of the buffer | ||
unsafe { | ||
cursor.advance_unchecked(read); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the same handling for ErrorKind::BrokenPipe
as with read_buf
?
If so, these functions are pretty identical. Maybe we should only have read_buf_at(self, cursor, offset: Option<u64>)
, and instead of read_buf
call read_buf_at(..., None)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As always, cc @ChrisDenton for Windows changes
/// This equivalent to the [`read_at`](FileExt::read_at) method, | ||
/// except that it is passed a [`BorrowedCursor`] rather than `&mut [u8]` to allow | ||
/// use with uninitialized buffers. The new data will be appended to any | ||
/// existing contents of `buf`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small style nit, docs can wrap at 100 chars
@@ -490,6 +490,47 @@ fn file_test_io_read_write_at() { | |||
check!(fs::remove_file(&filename)); | |||
} | |||
|
|||
#[test] | |||
#[cfg(unix)] | |||
fn test_read_buf_at() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should get a couple of calls for read_buf_at
(not exact) that aren't just eof. Or maybe split test_read_buf_at
and read_buf_exact_at
?
Running another try, including a few other unix platforms @bors2 try |
Add `read_buf` equivalents for positioned reads Adds the following items under the ~~`read_buf` (#78485)~~ `read_buf_at` (#140771) feature: - `std::os::unix::fs::FileExt::read_buf_at` - `std::os::unix::fs::FileExt::read_buf_exact_at` - `std::os::windows::fs::FileExt::seek_read_buf` try-job: `x86_64-msvc*` try-job: `test-various*` try-job: `dist-various*`
crate::cfg_select! { | ||
any( | ||
all(target_os = "linux", not(target_env = "musl")), | ||
target_os = "android", | ||
target_os = "hurd", | ||
) => { | ||
use libc::pread64; | ||
} | ||
_ => { | ||
use libc::pread as pread64; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should move to the top with the other imports (mentioned this in another comment), but actually do we need this remapping? From what I can gather at https://pubs.opengroup.org/onlinepubs/7908799/xsh/read.html and https://linux.die.net/man/2/pread64, pread
is the POSIX name and Linux just changed its syscalls.
@rustbot author |
Adds the following items under the
read_buf
(#78485)read_buf_at
(#140771) feature:std::os::unix::fs::FileExt::read_buf_at
std::os::unix::fs::FileExt::read_buf_exact_at
std::os::windows::fs::FileExt::seek_read_buf
try-job:
x86_64-msvc*
try-job:
test-various*
try-job:
dist-various*