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

Add support for nested map_field operations #50

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/volatile_ptr/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
/// ```
#[macro_export]
macro_rules! map_field {
($volatile:ident.$place:ident) => {{
($volatile:ident.$($place:ident).+) => {{
// Simulate creating a reference to the field. This is done to make
// sure that the field is not potentially unaligned. The body of the
// if statement will never be executed, so it can never cause any UB.
if false {
let _ref_to_field = &(unsafe { &*$volatile.as_raw_ptr().as_ptr() }).$place;
let _ref_to_field = &(unsafe { &*$volatile.as_raw_ptr().as_ptr() }).$($place).+;
}

unsafe {
$volatile.map(|ptr| {
core::ptr::NonNull::new(core::ptr::addr_of_mut!((*ptr.as_ptr()).$place)).unwrap()
core::ptr::NonNull::new(core::ptr::addr_of_mut!((*ptr.as_ptr()).$($place).+)).unwrap()
})
}
}};
Expand Down
Loading