diff --git a/.github/workflows/rust-target.yml b/.github/workflows/rust-target.yml new file mode 100644 index 0000000000..9107f9f7b1 --- /dev/null +++ b/.github/workflows/rust-target.yml @@ -0,0 +1,43 @@ +name: rust-target + +on: + push: + branches: + - main + pull_request: + branches: + - main + merge_group: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + rust-version: ["1.33", "1.36", "1.40", "1.43", "1.47", "1.59", "1.64", "1.68", "1.71", "1.73", "1.77", "nightly"] + steps: + - uses: actions/checkout@v4 + + - name: Install rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{matrix.rust-version}} + + - name: Install packages + run: | + sudo apt-get update + sudo apt-get install libtinfo5 ripgrep + + - name: Check headers + run: | + HEADERS=$(rg -l '\-\-rust-target[\s=]${{matrix.rust-version}}' bindgen-tests/tests/headers/ | cut -d '/' -f 4 | cut -d '.' -f 1) + + for HEADER in $HEADERS; do + FILE="bindgen-tests/tests/expectations/tests/$HEADER.rs" + echo "Checking $FILE" + rustup run ${{matrix.rust-version}} rustc --edition=2018 --crate-type=rlib --emit=metadata $FILE + done + diff --git a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs index 88b9ceaa24..c8f19bc5af 100644 --- a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -32,14 +32,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -57,14 +49,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -85,26 +69,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -122,24 +86,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } /** Because this struct have array larger than 32 items and --with-derive-partialeq --impl-partialeq --impl-debug is provided, @@ -219,35 +165,6 @@ impl Foo { } } #[inline] - pub unsafe fn type__bindgen_bitfield_raw( - this: *const Self, - ) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 3u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_type__bindgen_bitfield_raw( - this: *mut Self, - val: ::std::os::raw::c_char, - ) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 3u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( type__bindgen_bitfield: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs index e88d1d6d38..edcb4e2a02 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -33,14 +33,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -58,14 +50,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -86,26 +70,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -123,24 +87,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] #[derive(Copy, Clone)] @@ -188,31 +134,6 @@ impl C { } } #[inline] - pub unsafe fn a_raw(this: *const Self) -> bool { - unsafe { - ::core::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::core::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) - as u8, - ) - } - } - #[inline] - pub unsafe fn set_a_raw(this: *mut Self, val: bool) { - unsafe { - let val: u8 = ::core::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::core::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn b(&self) -> bool { unsafe { ::core::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } @@ -224,31 +145,6 @@ impl C { } } #[inline] - pub unsafe fn b_raw(this: *const Self) -> bool { - unsafe { - ::core::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::core::ptr::addr_of!((*this)._bitfield_1), 1usize, 7u8) - as u8, - ) - } - } - #[inline] - pub unsafe fn set_b_raw(this: *mut Self, val: bool) { - unsafe { - let val: u8 = ::core::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::core::ptr::addr_of_mut!((*this)._bitfield_1), - 1usize, - 7u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs index 09ca288b07..20c7cf0c88 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -32,14 +32,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -57,14 +49,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -85,26 +69,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -122,24 +86,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] #[derive(Copy, Clone)] @@ -198,30 +144,6 @@ impl C { } } #[inline] - pub unsafe fn a_raw(this: *const Self) -> bool { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_a_raw(this: *mut Self, val: bool) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn b(&self) -> bool { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } @@ -233,30 +155,6 @@ impl C { } } #[inline] - pub unsafe fn b_raw(this: *const Self) -> bool { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 7u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_b_raw(this: *mut Self, val: bool) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 1usize, - 7u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs index b27a9bb32d..eaf3f45e5f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -32,14 +32,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -57,14 +49,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -85,26 +69,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -122,24 +86,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] #[derive(Copy, Clone)] @@ -188,30 +134,6 @@ impl C { } } #[inline] - pub unsafe fn a_raw(this: *const Self) -> bool { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_a_raw(this: *mut Self, val: bool) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn b(&self) -> bool { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } @@ -223,30 +145,6 @@ impl C { } } #[inline] - pub unsafe fn b_raw(this: *const Self) -> bool { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 7u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_b_raw(this: *mut Self, val: bool) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 1usize, - 7u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1(a: bool, b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 5da0e7995f..422782d66d 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -32,14 +32,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -57,14 +49,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -85,26 +69,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -122,24 +86,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -328,31 +274,6 @@ impl jsval_layout__bindgen_ty_1 { } } #[inline] - pub unsafe fn payload47_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 8usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 47u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_payload47_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 8usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 47u8, - val as u64, - ) - } - } - #[inline] pub fn tag(&self) -> JSValueTag { unsafe { ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) } } @@ -364,31 +285,6 @@ impl jsval_layout__bindgen_ty_1 { } } #[inline] - pub unsafe fn tag_raw(this: *const Self) -> JSValueTag { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 8usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 47usize, 17u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_tag_raw(this: *mut Self, val: JSValueTag) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 8usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 47usize, - 17u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( payload47: u64, tag: JSValueTag, diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index d9d30e1d88..4a62ddbea3 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -32,14 +32,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -57,14 +49,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -85,26 +69,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -122,24 +86,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } pub const ETH_MQ_RX_RSS_FLAG: u32 = 1; pub const ETH_MQ_RX_DCB_FLAG: u32 = 2; @@ -260,31 +206,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn header_split_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_header_split_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_ip_checksum(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } @@ -296,31 +217,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_ip_checksum_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_ip_checksum_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 1usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_filter(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } @@ -332,31 +228,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_vlan_filter_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_filter_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 2usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_strip(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) } } @@ -368,31 +239,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_vlan_strip_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 3usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_strip_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 3usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_extend(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) } } @@ -404,31 +250,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_vlan_extend_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_extend_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 4usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn jumbo_frame(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) } } @@ -440,31 +261,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn jumbo_frame_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 5usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_jumbo_frame_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 5usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_strip_crc(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) } } @@ -476,31 +272,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_strip_crc_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 6usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_strip_crc_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 6usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn enable_scatter(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) } } @@ -512,31 +283,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn enable_scatter_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_enable_scatter_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 7usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn enable_lro(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) } } @@ -548,31 +294,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn enable_lro_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_enable_lro_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 8usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( header_split: u16, hw_ip_checksum: u16, @@ -755,30 +476,6 @@ impl rte_eth_txmode { } } #[inline] - pub unsafe fn hw_vlan_reject_tagged_raw(this: *const Self) -> u8 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_reject_tagged_raw(this: *mut Self, val: u8) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_reject_untagged(&self) -> u8 { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } @@ -790,30 +487,6 @@ impl rte_eth_txmode { } } #[inline] - pub unsafe fn hw_vlan_reject_untagged_raw(this: *const Self) -> u8 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_reject_untagged_raw(this: *mut Self, val: u8) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 1usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_insert_pvid(&self) -> u8 { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } @@ -825,30 +498,6 @@ impl rte_eth_txmode { } } #[inline] - pub unsafe fn hw_vlan_insert_pvid_raw(this: *const Self) -> u8 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_insert_pvid_raw(this: *mut Self, val: u8) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 2usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( hw_vlan_reject_tagged: u8, hw_vlan_reject_untagged: u8, diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index c5ccdd0959..6cbeb042aa 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -32,14 +32,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -57,14 +49,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -85,26 +69,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -122,24 +86,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -308,31 +254,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn header_split_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_header_split_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_ip_checksum(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } @@ -344,31 +265,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_ip_checksum_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_ip_checksum_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 1usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_filter(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } @@ -380,31 +276,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_vlan_filter_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_filter_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 2usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_strip(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) } } @@ -416,31 +287,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_vlan_strip_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 3usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_strip_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 3usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_extend(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) } } @@ -452,31 +298,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_vlan_extend_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_extend_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 4usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn jumbo_frame(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) } } @@ -488,31 +309,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn jumbo_frame_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 5usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_jumbo_frame_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 5usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_strip_crc(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) } } @@ -524,31 +320,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn hw_strip_crc_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 6usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_hw_strip_crc_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 6usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn enable_scatter(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) } } @@ -560,31 +331,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn enable_scatter_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_enable_scatter_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 7usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn enable_lro(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) } } @@ -596,31 +342,6 @@ impl rte_eth_rxmode { } } #[inline] - pub unsafe fn enable_lro_raw(this: *const Self) -> u16 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 1u8) - as u16, - ) - } - } - #[inline] - pub unsafe fn set_enable_lro_raw(this: *mut Self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 2usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 8usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( header_split: u16, hw_ip_checksum: u16, @@ -808,30 +529,6 @@ impl rte_eth_txmode { } } #[inline] - pub unsafe fn hw_vlan_reject_tagged_raw(this: *const Self) -> u8 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_reject_tagged_raw(this: *mut Self, val: u8) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_reject_untagged(&self) -> u8 { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } @@ -843,30 +540,6 @@ impl rte_eth_txmode { } } #[inline] - pub unsafe fn hw_vlan_reject_untagged_raw(this: *const Self) -> u8 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_reject_untagged_raw(this: *mut Self, val: u8) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 1usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn hw_vlan_insert_pvid(&self) -> u8 { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } @@ -878,30 +551,6 @@ impl rte_eth_txmode { } } #[inline] - pub unsafe fn hw_vlan_insert_pvid_raw(this: *const Self) -> u8 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) as u8, - ) - } - } - #[inline] - pub unsafe fn set_hw_vlan_insert_pvid_raw(this: *mut Self, val: u8) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 2usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( hw_vlan_reject_tagged: u8, hw_vlan_reject_untagged: u8, diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index db4f078aad..38e221f3ca 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -32,14 +32,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -57,14 +49,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -85,26 +69,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -122,24 +86,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -360,31 +306,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn l2_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_l2_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn l3_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } @@ -396,31 +317,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn l3_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_l3_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 4usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn l4_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } } @@ -432,31 +328,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn l4_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_l4_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 8usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn tun_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) } } @@ -468,31 +339,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn tun_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 12usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_tun_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 12usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn inner_l2_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) } } @@ -504,31 +350,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn inner_l2_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_inner_l2_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 16usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn inner_l3_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) } } @@ -540,31 +361,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn inner_l3_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 20usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_inner_l3_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 20usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn inner_l4_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) } } @@ -576,31 +372,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn inner_l4_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_inner_l4_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 24usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( l2_type: u32, l3_type: u32, @@ -991,31 +762,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn l2_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 7u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_l2_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 7u8, - val as u64, - ) - } - } - #[inline] pub fn l3_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) } } @@ -1027,31 +773,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn l3_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 9u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_l3_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 7usize, - 9u8, - val as u64, - ) - } - } - #[inline] pub fn l4_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) } } @@ -1063,31 +784,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn l4_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 8u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_l4_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 16usize, - 8u8, - val as u64, - ) - } - } - #[inline] pub fn tso_segsz(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) } } @@ -1099,31 +795,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn tso_segsz_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 16u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_tso_segsz_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 24usize, - 16u8, - val as u64, - ) - } - } - #[inline] pub fn outer_l3_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) } } @@ -1135,31 +806,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn outer_l3_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 40usize, 9u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_outer_l3_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 40usize, - 9u8, - val as u64, - ) - } - } - #[inline] pub fn outer_l2_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) } } @@ -1171,31 +817,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn outer_l2_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 49usize, 7u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_outer_l2_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 49usize, - 7u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( l2_len: u64, l3_len: u64, diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index 9cf2bf8e47..bd4a772cb7 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -32,14 +32,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -57,14 +49,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -85,26 +69,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -122,24 +86,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -216,34 +162,6 @@ impl U4 { } } #[inline] - pub unsafe fn derp_raw(this: *const Self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get( - (*::std::ptr::addr_of!((*this)._bitfield_1)).as_ref() as *const _, - 0usize, - 1u8, - ) as u32, - ) - } - } - #[inline] - pub unsafe fn set_derp_raw(this: *mut Self, val: ::std::os::raw::c_uint) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - (*::std::ptr::addr_of_mut!((*this)._bitfield_1)).as_mut() as *mut _, - 0usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( derp: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { @@ -292,34 +210,6 @@ impl B { } } #[inline] - pub unsafe fn foo_raw(this: *const Self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get( - (*::std::ptr::addr_of!((*this)._bitfield_1)).as_ref() as *const _, - 0usize, - 31u8, - ) as u32, - ) - } - } - #[inline] - pub unsafe fn set_foo_raw(this: *mut Self, val: ::std::os::raw::c_uint) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - (*::std::ptr::addr_of_mut!((*this)._bitfield_1)).as_mut() as *mut _, - 0usize, - 31u8, - val as u64, - ) - } - } - #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.as_ref().get(31usize, 1u8) as u8) @@ -333,34 +223,6 @@ impl B { } } #[inline] - pub unsafe fn bar_raw(this: *const Self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get( - (*::std::ptr::addr_of!((*this)._bitfield_1)).as_ref() as *const _, - 31usize, - 1u8, - ) as u8, - ) - } - } - #[inline] - pub unsafe fn set_bar_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - (*::std::ptr::addr_of_mut!((*this)._bitfield_1)).as_mut() as *mut _, - 31usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 287bfebfba..ff19f398ad 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -32,14 +32,6 @@ where Self::extract_bit(byte, index) } #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) @@ -57,14 +49,6 @@ where *byte = Self::change_bit(*byte, index, val); } #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -85,26 +69,6 @@ where val } #[inline] - pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - let mut val = 0; - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); @@ -122,24 +86,6 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - #[inline] - pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::(), - ); - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -228,31 +174,6 @@ impl foo__bindgen_ty_1 { } } #[inline] - pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 7u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_int) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 7u8, - val as u64, - ) - } - } - #[inline] pub fn c(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) } } @@ -264,31 +185,6 @@ impl foo__bindgen_ty_1 { } } #[inline] - pub unsafe fn c_raw(this: *const Self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 25u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_c_raw(this: *mut Self, val: ::std::os::raw::c_int) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 7usize, - 25u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, diff --git a/bindgen/codegen/bitfield_unit.rs b/bindgen/codegen/bitfield_unit.rs index 3411c22eac..59c66f8cb7 100644 --- a/bindgen/codegen/bitfield_unit.rs +++ b/bindgen/codegen/bitfield_unit.rs @@ -38,17 +38,6 @@ where Self::extract_bit(byte, index) } - #[inline] - pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { - debug_assert!(index / 8 < core::mem::size_of::()); - - let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); - - Self::extract_bit(byte, index) - } - #[inline] fn change_bit(byte: u8, index: usize, val: bool) -> u8 { let bit_index = if cfg!(target_endian = "big") { @@ -75,17 +64,6 @@ where *byte = Self::change_bit(*byte, index, val); } - #[inline] - pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { - debug_assert!(index / 8 < core::mem::size_of::()); - - let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); @@ -111,35 +89,6 @@ where val } - #[inline] - pub unsafe fn raw_get( - this: *const Self, - bit_offset: usize, - bit_width: u8, - ) -> u64 { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - core::mem::size_of::() - ); - - let mut val = 0; - - for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - val |= 1 << index; - } - } - - val - } - #[inline] pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { debug_assert!(bit_width <= 64); @@ -160,30 +109,4 @@ where self.set_bit(index + bit_offset, val_bit_is_set); } } - - #[inline] - pub unsafe fn raw_set( - this: *mut Self, - bit_offset: usize, - bit_width: u8, - val: u64, - ) { - debug_assert!(bit_width <= 64); - debug_assert!(bit_offset / 8 < core::mem::size_of::()); - debug_assert!( - (bit_offset + (bit_width as usize)) / 8 <= - core::mem::size_of::() - ); - - for i in 0..(bit_width as usize) { - let mask = 1 << i; - let val_bit_is_set = val & mask == mask; - let index = if cfg!(target_endian = "big") { - bit_width as usize - 1 - i - } else { - i - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } diff --git a/bindgen/codegen/bitfield_unit_raw_ref_macros.rs b/bindgen/codegen/bitfield_unit_raw_ref_macros.rs new file mode 100644 index 0000000000..3411c22eac --- /dev/null +++ b/bindgen/codegen/bitfield_unit_raw_ref_macros.rs @@ -0,0 +1,189 @@ +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit { + storage: Storage, +} + +impl __BindgenBitfieldUnit { + #[inline] + pub const fn new(storage: Storage) -> Self { + Self { storage } + } +} + +impl __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + #[inline] + fn extract_bit(byte: u8, index: usize) -> bool { + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + + let mask = 1 << bit_index; + + byte & mask == mask + } + + #[inline] + pub fn get_bit(&self, index: usize) -> bool { + debug_assert!(index / 8 < self.storage.as_ref().len()); + + let byte_index = index / 8; + let byte = self.storage.as_ref()[byte_index]; + + Self::extract_bit(byte, index) + } + + #[inline] + pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool { + debug_assert!(index / 8 < core::mem::size_of::()); + + let byte_index = index / 8; + let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize); + + Self::extract_bit(byte, index) + } + + #[inline] + fn change_bit(byte: u8, index: usize, val: bool) -> u8 { + let bit_index = if cfg!(target_endian = "big") { + 7 - (index % 8) + } else { + index % 8 + }; + + let mask = 1 << bit_index; + if val { + byte | mask + } else { + byte & !mask + } + } + + #[inline] + pub fn set_bit(&mut self, index: usize, val: bool) { + debug_assert!(index / 8 < self.storage.as_ref().len()); + + let byte_index = index / 8; + let byte = &mut self.storage.as_mut()[byte_index]; + + *byte = Self::change_bit(*byte, index, val); + } + + #[inline] + pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) { + debug_assert!(index / 8 < core::mem::size_of::()); + + let byte_index = index / 8; + let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + + *byte = Self::change_bit(*byte, index, val); + } + + #[inline] + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= + self.storage.as_ref().len() + ); + + let mut val = 0; + + for i in 0..(bit_width as usize) { + if self.get_bit(i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + + val + } + + #[inline] + pub unsafe fn raw_get( + this: *const Self, + bit_offset: usize, + bit_width: u8, + ) -> u64 { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= + core::mem::size_of::() + ); + + let mut val = 0; + + for i in 0..(bit_width as usize) { + if Self::raw_get_bit(this, i + bit_offset) { + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + val |= 1 << index; + } + } + + val + } + + #[inline] + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= + self.storage.as_ref().len() + ); + + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + self.set_bit(index + bit_offset, val_bit_is_set); + } + } + + #[inline] + pub unsafe fn raw_set( + this: *mut Self, + bit_offset: usize, + bit_width: u8, + val: u64, + ) { + debug_assert!(bit_width <= 64); + debug_assert!(bit_offset / 8 < core::mem::size_of::()); + debug_assert!( + (bit_offset + (bit_width as usize)) / 8 <= + core::mem::size_of::() + ); + + for i in 0..(bit_width as usize) { + let mask = 1 << i; + let val_bit_is_set = val & mask == mask; + let index = if cfg!(target_endian = "big") { + bit_width as usize - 1 - i + } else { + i + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } +} diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 4cab877362..253c18f3c1 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2008,31 +2008,35 @@ impl<'a> FieldCodegen<'a> for Bitfield { ) } } + })); - #[inline] - #access_spec unsafe fn #raw_getter_name(this: *const Self) -> #bitfield_ty { - unsafe { - ::#prefix::mem::transmute(<#unit_field_ty>::raw_get( - (*::#prefix::ptr::addr_of!((*this).#unit_field_ident)).as_ref() as *const _, - #offset, - #width, - ) as #bitfield_int_ty) + if ctx.options().rust_features.raw_ref_macros { + methods.extend(Some(quote! { + #[inline] + #access_spec unsafe fn #raw_getter_name(this: *const Self) -> #bitfield_ty { + unsafe { + ::#prefix::mem::transmute(<#unit_field_ty>::raw_get( + (*::#prefix::ptr::addr_of!((*this).#unit_field_ident)).as_ref() as *const _, + #offset, + #width, + ) as #bitfield_int_ty) + } } - } - #[inline] - #access_spec unsafe fn #raw_setter_name(this: *mut Self, val: #bitfield_ty) { - unsafe { - let val: #bitfield_int_ty = ::#prefix::mem::transmute(val); - <#unit_field_ty>::raw_set( - (*::#prefix::ptr::addr_of_mut!((*this).#unit_field_ident)).as_mut() as *mut _, - #offset, - #width, - val as u64, - ) + #[inline] + #access_spec unsafe fn #raw_setter_name(this: *mut Self, val: #bitfield_ty) { + unsafe { + let val: #bitfield_int_ty = ::#prefix::mem::transmute(val); + <#unit_field_ty>::raw_set( + (*::#prefix::ptr::addr_of_mut!((*this).#unit_field_ident)).as_mut() as *mut _, + #offset, + #width, + val as u64, + ) + } } - } - })); + })); + } } else { methods.extend(Some(quote! { #[inline] @@ -2056,7 +2060,10 @@ impl<'a> FieldCodegen<'a> for Bitfield { ) } } + })); + if ctx.options().rust_features.raw_ref_macros { + methods.extend(Some(quote! { #[inline] #access_spec unsafe fn #raw_getter_name(this: *const Self) -> #bitfield_ty { unsafe { @@ -2081,6 +2088,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { } } })); + } } } } @@ -5302,7 +5310,11 @@ pub(crate) mod utils { return; } - let bitfield_unit_src = include_str!("./bitfield_unit.rs"); + let bitfield_unit_src = if ctx.options().rust_features().raw_ref_macros { + include_str!("./bitfield_unit_raw_ref_macros.rs") + } else { + include_str!("./bitfield_unit.rs") + }; let bitfield_unit_src = if ctx.options().rust_features().min_const_fn { Cow::Borrowed(bitfield_unit_src) } else { diff --git a/bindgen/features.rs b/bindgen/features.rs index 990e4513cb..e67b00f0d3 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -104,6 +104,7 @@ define_rust_targets! { Stable_1_71(71) => { c_unwind_abi: #106075 }, Stable_1_68(68) => { abi_efiapi: #105795 }, Stable_1_64(64) => { core_ffi_c: #94503 }, + Stable_1_51(51) => { raw_ref_macros: #80886 }, Stable_1_59(59) => { const_cstr: #54745 }, Stable_1_47(47) => { larger_arrays: #74060 }, Stable_1_43(43) => { associated_constants: #68952 },