Skip to content

Commit e71470c

Browse files
authored
Update FIELD_OFFSET macro (#16)
1 parent a09a60c commit e71470c

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/macros.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,8 @@ macro_rules! EXTERN {
2929
macro_rules! FIELD_OFFSET {
3030
($_type:ty, $field:ident$(.$cfields:ident)*) => {
3131
unsafe {
32-
union Transmuter<T: 'static> {
33-
p: *const T,
34-
r: &'static T,
35-
i: usize,
36-
}
37-
#[allow(unaligned_references)]
38-
Transmuter {
39-
r: &(&Transmuter {
40-
p: $crate::_core::ptr::null::<$_type>()
41-
}.r).$field$(.$cfields)*
42-
}.i
32+
let base = ::core::mem::MaybeUninit::<$_type>::uninit().as_ptr();
33+
::core::ptr::addr_of!((*base).$field$(.$cfields)*) as usize - base as usize
4334
}
4435
};
4536
}

0 commit comments

Comments
 (0)