-
Notifications
You must be signed in to change notification settings - Fork 149
Fix clippy warnings #80
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,10 +165,10 @@ impl<'a> ObjectSkeletonConfigBuilder<'a> { | |
// Holds `CString`s alive so pointers to them stay valid | ||
let mut string_pool = Vec::new(); | ||
|
||
// NB: use default() to zero out struct | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danobi I also got rid of this, since it appears to be a comment about zeroing out the bytes, but it sounds like we'll fix it with the bind-gen bugfix |
||
let mut s = bpf_object_skeleton::default(); | ||
|
||
s.sz = size_of::<bpf_object_skeleton>() as u64; | ||
let mut s = libbpf_sys::bpf_object_skeleton { | ||
sz: size_of::<bpf_object_skeleton>() as u64, | ||
..Default::default() | ||
}; | ||
|
||
if let Some(ref n) = self.name { | ||
s.name = str_to_cstring_and_pool(&n, &mut string_pool)?; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does this ensure that all the bytes are zeroed out, even padding?
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 don't think so.
Example: https://godbolt.org/z/r75T13Pcd
Rust generates code to call
::default()
which is implemented by https://docs.rs/libbpf-sys/0.3.0-1/src/libbpf_sys/bindings.rs.html#2987-2991 and the implementation zeros out the struct using https://doc.rust-lang.org/stable/std/mem/fn.zeroed.html . From reading the docs there and looking at rust-lang/rust#70230 , I don't believe bindgen is generating the right code here. It should probably generate a memset.Also note that this PR doesn't change the old behavior. Functionally it should be the same as before.
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.
There's definitely padding: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b7342c8fe84d6bb1e01333e4e07f7a79 (48 vs 38). I think this should be a bindgen bug
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.
@danobi I think I'm following along, though I'm still p new to systems programming.
It sounds like the padding is bad because we want libbpf-rs to be as conservative as possible when it comes to memory, yeah? Also, It seems like rust-lang/rust#70230 is going to take some time to resolve, and when it does it'll be in the nightly release at first.
I can revert these changes around calling
default()
and add a comment so thatclippy
ignores em. That work?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.
Just pushed up the revert - let me know if that's not the right path, and I can undo em
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 your original changes were good. I think it's a bug with bindgen (a tool used to generate rust bindings to c/c++ libraries). I'm working on fixing the bindgen bug in rust-lang/rust-bindgen#2051
Even then, the non-zero padding is currently a theoretical issue. We haven't seen issues with it yet -- not to say it won't happen in the future (b/c bindgen is invoking undefined behavior)
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 the revert!