-
Notifications
You must be signed in to change notification settings - Fork 141
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
Fix up some mutability warts on datasec skeleton accessors #611
Conversation
It's not particularly user friendly to only have exclusive shared datasec accessor variants available, as that can lead to unnecessary borrow conflicts. With this change we revamp the generation logic to generate shared and exclusive accessors when possible. Refs: #606 Signed-off-by: Daniel Müller <[email protected]>
When we create a skeleton with a getter for an immutable map, we should be able to use a non-exclusive receiver (&self) instead of an exclusive one (&mut self). Using the latter unconditionally can be the cause of unnecessary borrow conflicts. Refs: #606 Signed-off-by: Daniel Müller <[email protected]>
There is not too much of a point in passing in the desired mutability to gen_skel_prog_getter() when all call sites invoke it with both true and false. Move the logic for dealing with mutability into the function itself to shield callers from the need to care. Signed-off-by: Daniel Müller <[email protected]>
There is not too much of a point in passing in the desired mutability to gen_skel_map_getters() when all call sites invoke it with both true and false. Move the logic for dealing with mutability into the function itself to shield callers from the need to care. Signed-off-by: Daniel Müller <[email protected]>
There is not too much of a point in passing in the desired mutability to gen_skel_map_defs() when all call sites invoke it with both true and false. Move the logic for dealing with mutability into the function itself to shield callers from the need to care. Signed-off-by: Daniel Müller <[email protected]>
libbpf-cargo/src/gen/mod.rs
Outdated
unsafe {{ | ||
std::mem::transmute::<*mut std::ffi::c_void, &'_ {mutability} {struct_name}>( | ||
std::mem::transmute::<*mut std::ffi::c_void, &{mutability} {struct_name}>( |
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.
is it intentional that we transmute to *mut c_void for both mutabilities?
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.
Not sure which commit you looked at/commented on, but in the end mutability
would be just the empty string for the "shared" accessor. So yeah, it's intentional.
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.
ah, I commented on commit #2 ("Use non-exclusive receiver for immutable datasec getters"), and it will later be replaced with {ptr_suffix}, never mind.
Uhm...I can't rebase and resolve the conflict for , so I am going to recreate the pull request with updated changes and then merge. Thanks for the review. |
Please see individual commits for descriptions