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

use offset_of! to calculate dirent64 field offsets #114519

Merged
merged 1 commit into from
Aug 6, 2023

Conversation

the8472
Copy link
Member

@the8472 the8472 commented Aug 5, 2023

@the8472 the8472 added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Aug 5, 2023
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 5, 2023
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@dtolnay
Copy link
Member

dtolnay commented Aug 5, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Aug 5, 2023

📌 Commit 20c25d6 has been approved by dtolnay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 5, 2023
.offset_from(entry_ptr.cast::<u8>())
}
};
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::<_>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curiosity: I see above it talks about "in bounds of the same allocation, which is not necessarily the case here", but then it uses byte_offset, which also has the "inside the same allocation" problem.

Should it perhaps be wrapping_byte_offset here? Or am I misunderstanding the restrictions under which this is operating?

Copy link
Member

@dtolnay dtolnay Aug 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both the code and comment are correct as written. byte_offset(OFFSET) requires the start of $field to be in bounds, which it is. addr_of!((*ptr).$field) requires the start and end of $field (and every other field) to be in bounds which they are not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks! I hadn't considered the whole width of the field problem.

@bors
Copy link
Contributor

bors commented Aug 6, 2023

⌛ Testing commit 20c25d6 with merge c88b7fdfd99eda0e12376d12a4aa271d66e3033b...

@bors
Copy link
Contributor

bors commented Aug 6, 2023

☀️ Test successful - checks-actions
Approved by: dtolnay
Pushing c88b7fdfd99eda0e12376d12a4aa271d66e3033b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 6, 2023
@bors
Copy link
Contributor

bors commented Aug 6, 2023

👀 Test was successful, but fast-forwarding failed: 422 Update is not a fast forward

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c88b7fdfd99eda0e12376d12a4aa271d66e3033b): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.7% [3.0%, 4.3%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 652.053s -> 652.033s (-0.00%)

@the8472
Copy link
Member Author

the8472 commented Aug 6, 2023

weird

@bors retry

@the8472 the8472 closed this Aug 6, 2023
@the8472 the8472 reopened this Aug 6, 2023
@the8472
Copy link
Member Author

the8472 commented Aug 6, 2023

@bors r=dtolnay

@bors
Copy link
Contributor

bors commented Aug 6, 2023

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Aug 6, 2023

📌 Commit 20c25d6 has been approved by dtolnay

It is now in the queue for this repository.

@klensy
Copy link
Contributor

klensy commented Aug 6, 2023

and the same thing with #113648, suspiciously often.

// need to make our own non-libc allocation that conforms to the weird
// imaginary definition of dirent64, and use that for a field offset
// computation.
// Instead we must access fields individually through their offsets.
macro_rules! offset_ptr {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, if rust-lang/reference#1387 gets accepted then all this can be removed and a direct addr_of!((*entry_ptr).d_name) should work.

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#114466 (Add Allocation to SMIR)
 - rust-lang#114505 (Add documentation to has_deref)
 - rust-lang#114519 (use offset_of! to calculate dirent64 field offsets)
 - rust-lang#114537 (Migrate GUI colors test to original CSS color format)
 - rust-lang#114539 (linkchecker: Remove unneeded FIXME about intra-doc links)

Failed merges:

 - rust-lang#114485 (Add trait decls to SMIR)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3d1c36e into rust-lang:master Aug 6, 2023
22 checks passed
@rustbot rustbot added this to the 1.73.0 milestone Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants