-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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 |
@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
💔 Test failed - checks-actions |
85e1da1
to
05dcef0
Compare
This comment has been minimized.
This comment has been minimized.
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
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.
It makes sense to me to unify the implementations but pipes aren't seekable so this probably isn't a practical concern. It just avoids unnecessarily repeating ourselves.
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.
I think this error code is only produced on pipes, where read_at
and read_buf_at
do not make sense in any case.
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.
After weeks, we both respond in the same minute 😆
Will combine them then, after all.
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.
Reverted again. type AnonPipe = Handle
makes it a bit awkward to push usage of a deduplicated read_buf_at(..., offset: Option<u64>)
all the way down.
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*`
library/std/src/sys/fd/unix.rs
Outdated
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.
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.
Sorry, missed the auto-collapsed response earlier. Moved to the top.
Looks like they are identical up to off_t
vs. off64_t
.
unsafe fn pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t;
unsafe fn pread64(fd: c_int, buf: *mut c_void, count: size_t, offset: off64_t) -> ssize_t;
So it comes down to #[cfg(gnu_file_offset_bits64)]
, which justifies explicitly picking pread64
, I guess? Added a comment to that effect.
@rustbot author |
Hey @niklasf gentle ping: this only needs a few small changes if you're able to get it over the line |
☔ The latest upstream changes (presumably #145334) made this pull request unmergeable. Please resolve the merge conflicts. |
e8a35d4
to
f6dd203
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
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`
bf491a1
to
55ce5c1
Compare
Back after a while, rebased to resolve conflicts, and ready for the next round of review. @rustbot ready |
This comment has been minimized.
This comment has been minimized.
55ce5c1
to
bf491a1
Compare
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*