diff --git a/hs-bindgen/examples/bitfields.h b/hs-bindgen/examples/bitfields.h index 9659b3a7..63c66a59 100644 --- a/hs-bindgen/examples/bitfields.h +++ b/hs-bindgen/examples/bitfields.h @@ -31,3 +31,14 @@ struct overflow64 { long x : 33; long y : 33; }; + +// alignment +struct alignA { + unsigned char x : 1; + int y : 10; +}; + +struct alignB { + unsigned char x : 7; + int y : 31; +}; diff --git a/hs-bindgen/fixtures/bitfields.rs b/hs-bindgen/fixtures/bitfields.rs index ed23063e..42d1f731 100644 --- a/hs-bindgen/fixtures/bitfields.rs +++ b/hs-bindgen/fixtures/bitfields.rs @@ -510,3 +510,128 @@ impl overflow64 { __bindgen_bitfield_unit } } +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Copy, Clone)] +pub struct alignA { + pub _bitfield_align_1: [u16; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, + pub __bindgen_padding_0: u16, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of alignA"][::std::mem::size_of::() - 4usize]; + ["Alignment of alignA"][::std::mem::align_of::() - 4usize]; +}; +impl alignA { + #[inline] + pub fn x(&self) -> ::std::os::raw::c_uchar { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } + } + #[inline] + pub fn set_x(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn y(&self) -> ::std::os::raw::c_int { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 10u8) as u32) } + } + #[inline] + pub fn set_y(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 10u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + x: ::std::os::raw::c_uchar, + y: ::std::os::raw::c_int, + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let x: u8 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 10u8, + { + let y: u32 = unsafe { ::std::mem::transmute(y) }; + y as u64 + }, + ); + __bindgen_bitfield_unit + } +} +#[repr(C)] +#[repr(align(8))] +#[derive(Debug, Copy, Clone)] +pub struct alignB { + pub _bitfield_align_1: [u32; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 5usize]>, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of alignB"][::std::mem::size_of::() - 8usize]; + ["Alignment of alignB"][::std::mem::align_of::() - 8usize]; +}; +impl alignB { + #[inline] + pub fn x(&self) -> ::std::os::raw::c_uchar { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u8) } + } + #[inline] + pub fn set_x(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 7u8, val as u64) + } + } + #[inline] + pub fn y(&self) -> ::std::os::raw::c_long { + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 31u8) as u64) } + } + #[inline] + pub fn set_y(&mut self, val: ::std::os::raw::c_long) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + self._bitfield_1.set(7usize, 31u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + x: ::std::os::raw::c_uchar, + y: ::std::os::raw::c_long, + ) -> __BindgenBitfieldUnit<[u8; 5usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 5usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 7u8, + { + let x: u8 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 31u8, + { + let y: u64 = unsafe { ::std::mem::transmute(y) }; + y as u64 + }, + ); + __bindgen_bitfield_unit + } +}