Skip to content

Conversation

@rytheo
Copy link
Contributor

@rytheo rytheo commented May 28, 2023

Creating unaligned references now causes a compile-time error, so this change uses std::ptr::addr_of! to compute struct field offsets instead.

ty: <#types as _h5::types::H5Type>::type_descriptor(),
offset: unsafe { &((*origin).#fields) as *const _ as _ },
offset: unsafe {
::std::ptr::addr_of!((*origin_ptr).#fields) as usize - origin_ptr as usize
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe offset_from with the pointers cast to u8 pointers?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer .cast::<u8>() over as

@rytheo rytheo force-pushed the avoid-unaligned-ref branch 2 times, most recently from aae9267 to cf5306f Compare May 30, 2023 11:08
@rytheo rytheo force-pushed the avoid-unaligned-ref branch from cf5306f to 90bd2ee Compare May 30, 2023 11:11
Copy link
Collaborator

@mulimoen mulimoen left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@mulimoen mulimoen merged commit 5e5bedb into aldanor:master May 30, 2023
@rytheo rytheo deleted the avoid-unaligned-ref branch May 31, 2023 01:29
aldanor added a commit that referenced this pull request Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants