Skip to content
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

Rollup of 7 pull requests #135525

Merged
merged 18 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e7bd340
Switch missing_abi lint to warn-by-default.
m-ou-se Oct 31, 2024
585c976
Update tests.
m-ou-se Oct 31, 2024
2f5a3d4
Convert `struct FromBytesWithNulError` into enum
nyurik Dec 10, 2024
86b86fa
Rename `pos` to `position`
nyurik Jan 11, 2025
9cbd177
Detect unstable lint docs that dont enable their feature
compiler-errors Jan 12, 2025
3d54764
ci: Enable opt-dist for dist-aarch64-linux builds
mrkajetanp Dec 3, 2024
3d9dcf4
Un-spaghettify the control flow of generate_lint_output
compiler-errors Jan 12, 2025
a911da1
Use a C-safe return type for `__rust_[ui]128_*` overflowing intrinsics
tgross35 Dec 15, 2024
f6a2db8
Update compiler-builtins to 0.1.143
tgross35 Jan 15, 2025
c89ee08
Make sure we actually use the right trivial lifetime substs when eage…
compiler-errors Jan 15, 2025
58d6301
Update ReadDir::next in std::sys::pal::unix::fs to use `&raw const (*…
zachs18 Dec 23, 2024
285df03
Rollup merge of #132397 - m-ou-se:warn-missing-abi, r=Nadrieril
jhpratt Jan 15, 2025
f9d8b65
Rollup merge of #133807 - mrkajetanp:ci-aarch64-opt-dist, r=Kobzol
jhpratt Jan 15, 2025
229c91b
Rollup merge of #134143 - nyurik:err-nul, r=dtolnay
jhpratt Jan 15, 2025
bf4aeeb
Rollup merge of #134338 - tgross35:overflowing-c-safe-ret, r=bjorn3,a…
jhpratt Jan 15, 2025
56eb7bd
Rollup merge of #134678 - zachs18:offset-ptr-update, r=tgross35
jhpratt Jan 15, 2025
f35ff74
Rollup merge of #135424 - compiler-errors:unstable-lint, r=ehuss
jhpratt Jan 15, 2025
8e91327
Rollup merge of #135520 - compiler-errors:mono-impossible-drop-with-l…
jhpratt Jan 15, 2025
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
Prev Previous commit
Next Next commit
Update ReadDir::next in std::sys::pal::unix::fs to use `&raw const (*…
…ptr).field` instead of `ptr.offset(...).cast()`.

Also, the macro is only called three times, and all with the same local variable entry_ptr, so just use the local variable directly,
and rename the macro to entry_field_ptr.
zachs18 committed Jan 15, 2025
commit 58d6301cad7ac20407e708cd9d1ec499d1804015
36 changes: 13 additions & 23 deletions library/std/src/sys/pal/unix/fs.rs
Original file line number Diff line number Diff line change
@@ -709,7 +709,7 @@ impl Iterator for ReadDir {
// thread safety for readdir() as long an individual DIR* is not accessed
// concurrently, which is sufficient for Rust.
super::os::set_errno(0);
let entry_ptr = readdir64(self.inner.dirp.0);
let entry_ptr: *const dirent64 = readdir64(self.inner.dirp.0);
if entry_ptr.is_null() {
// We either encountered an error, or reached the end. Either way,
// the next call to next() should return None.
@@ -735,44 +735,34 @@ impl Iterator for ReadDir {
// contents were "simply" partially initialized data.
//
// Like for uninitialized contents, converting entry_ptr to `&dirent64`
// would not be legal. However, unique to dirent64 is that we don't even
// get to use `&raw const (*entry_ptr).d_name` because that operation
// requires the full extent of *entry_ptr to be in bounds of the same
// allocation, which is not necessarily the case here.
//
// Instead we must access fields individually through their offsets.
macro_rules! offset_ptr {
($entry_ptr:expr, $field:ident) => {{
const OFFSET: isize = mem::offset_of!(dirent64, $field) as isize;
if true {
// Cast to the same type determined by the else branch.
$entry_ptr.byte_offset(OFFSET).cast::<_>()
} else {
#[allow(deref_nullptr)]
{
&raw const (*ptr::null::<dirent64>()).$field
}
}
}};
// would not be legal. However, we can use `&raw const (*entry_ptr).d_name`
// to refer the fields individually, because that operation is equivalent
// to `byte_offset` and thus does not require the full extent of `*entry_ptr`
// to be in bounds of the same allocation, only the offset of the field
// being referenced.
macro_rules! entry_field_ptr {
($field:ident) => {
&raw const (*entry_ptr).$field
};
}

// d_name is guaranteed to be null-terminated.
let name = CStr::from_ptr(offset_ptr!(entry_ptr, d_name).cast());
let name = CStr::from_ptr(entry_field_ptr!(d_name).cast());
let name_bytes = name.to_bytes();
if name_bytes == b"." || name_bytes == b".." {
continue;
}

#[cfg(not(target_os = "vita"))]
let entry = dirent64_min {
d_ino: *offset_ptr!(entry_ptr, d_ino) as u64,
d_ino: *entry_field_ptr!(d_ino) as u64,
#[cfg(not(any(
target_os = "solaris",
target_os = "illumos",
target_os = "aix",
target_os = "nto",
)))]
d_type: *offset_ptr!(entry_ptr, d_type) as u8,
d_type: *entry_field_ptr!(d_type) as u8,
};

#[cfg(target_os = "vita")]