|
| 1 | +/* automatically generated by rust-bindgen */ |
| 2 | + |
| 3 | +#![allow( |
| 4 | + dead_code, |
| 5 | + non_snake_case, |
| 6 | + non_camel_case_types, |
| 7 | + non_upper_case_globals |
| 8 | +)] |
| 9 | + |
| 10 | +#[repr(C)] |
| 11 | +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] |
| 12 | +pub struct __BindgenBitfieldUnit<Storage, Align> { |
| 13 | + storage: Storage, |
| 14 | + align: [Align; 0], |
| 15 | +} |
| 16 | +impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> { |
| 17 | + #[inline] |
| 18 | + pub const fn new(storage: Storage) -> Self { |
| 19 | + Self { storage, align: [] } |
| 20 | + } |
| 21 | +} |
| 22 | +impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align> |
| 23 | +where |
| 24 | + Storage: AsRef<[u8]> + AsMut<[u8]>, |
| 25 | +{ |
| 26 | + #[inline] |
| 27 | + pub fn get_bit(&self, index: usize) -> bool { |
| 28 | + debug_assert!(index / 8 < self.storage.as_ref().len()); |
| 29 | + let byte_index = index / 8; |
| 30 | + let byte = self.storage.as_ref()[byte_index]; |
| 31 | + let bit_index = if cfg!(target_endian = "big") { |
| 32 | + 7 - (index % 8) |
| 33 | + } else { |
| 34 | + index % 8 |
| 35 | + }; |
| 36 | + let mask = 1 << bit_index; |
| 37 | + byte & mask == mask |
| 38 | + } |
| 39 | + #[inline] |
| 40 | + pub fn set_bit(&mut self, index: usize, val: bool) { |
| 41 | + debug_assert!(index / 8 < self.storage.as_ref().len()); |
| 42 | + let byte_index = index / 8; |
| 43 | + let byte = &mut self.storage.as_mut()[byte_index]; |
| 44 | + let bit_index = if cfg!(target_endian = "big") { |
| 45 | + 7 - (index % 8) |
| 46 | + } else { |
| 47 | + index % 8 |
| 48 | + }; |
| 49 | + let mask = 1 << bit_index; |
| 50 | + if val { |
| 51 | + *byte |= mask; |
| 52 | + } else { |
| 53 | + *byte &= !mask; |
| 54 | + } |
| 55 | + } |
| 56 | + #[inline] |
| 57 | + pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { |
| 58 | + debug_assert!(bit_width <= 64); |
| 59 | + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); |
| 60 | + debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); |
| 61 | + let mut val = 0; |
| 62 | + for i in 0..(bit_width as usize) { |
| 63 | + if self.get_bit(i + bit_offset) { |
| 64 | + let index = if cfg!(target_endian = "big") { |
| 65 | + bit_width as usize - 1 - i |
| 66 | + } else { |
| 67 | + i |
| 68 | + }; |
| 69 | + val |= 1 << index; |
| 70 | + } |
| 71 | + } |
| 72 | + val |
| 73 | + } |
| 74 | + #[inline] |
| 75 | + pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { |
| 76 | + debug_assert!(bit_width <= 64); |
| 77 | + debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); |
| 78 | + debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len()); |
| 79 | + for i in 0..(bit_width as usize) { |
| 80 | + let mask = 1 << i; |
| 81 | + let val_bit_is_set = val & mask == mask; |
| 82 | + let index = if cfg!(target_endian = "big") { |
| 83 | + bit_width as usize - 1 - i |
| 84 | + } else { |
| 85 | + i |
| 86 | + }; |
| 87 | + self.set_bit(index + bit_offset, val_bit_is_set); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | +#[repr(C)] |
| 92 | +#[derive(Default)] |
| 93 | +pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]); |
| 94 | +impl<T> __IncompleteArrayField<T> { |
| 95 | + #[inline] |
| 96 | + pub const fn new() -> Self { |
| 97 | + __IncompleteArrayField(::std::marker::PhantomData, []) |
| 98 | + } |
| 99 | + #[inline] |
| 100 | + pub unsafe fn as_ptr(&self) -> *const T { |
| 101 | + ::std::mem::transmute(self) |
| 102 | + } |
| 103 | + #[inline] |
| 104 | + pub unsafe fn as_mut_ptr(&mut self) -> *mut T { |
| 105 | + ::std::mem::transmute(self) |
| 106 | + } |
| 107 | + #[inline] |
| 108 | + pub unsafe fn as_slice(&self, len: usize) -> &[T] { |
| 109 | + ::std::slice::from_raw_parts(self.as_ptr(), len) |
| 110 | + } |
| 111 | + #[inline] |
| 112 | + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { |
| 113 | + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) |
| 114 | + } |
| 115 | +} |
| 116 | +impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> { |
| 117 | + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { |
| 118 | + fmt.write_str("__IncompleteArrayField") |
| 119 | + } |
| 120 | +} |
| 121 | +impl<T> ::std::clone::Clone for __IncompleteArrayField<T> { |
| 122 | + #[inline] |
| 123 | + fn clone(&self) -> Self { |
| 124 | + Self::new() |
| 125 | + } |
| 126 | +} |
| 127 | +#[repr(C)] |
| 128 | +#[derive(Debug)] |
| 129 | +pub struct foo { |
| 130 | + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, |
| 131 | + pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, |
| 132 | +} |
| 133 | +#[test] |
| 134 | +fn bindgen_test_layout_foo() { |
| 135 | + assert_eq!( |
| 136 | + ::std::mem::size_of::<foo>(), |
| 137 | + 8usize, |
| 138 | + concat!("Size of: ", stringify!(foo)) |
| 139 | + ); |
| 140 | + assert_eq!( |
| 141 | + ::std::mem::align_of::<foo>(), |
| 142 | + 8usize, |
| 143 | + concat!("Alignment of ", stringify!(foo)) |
| 144 | + ); |
| 145 | + assert_eq!( |
| 146 | + unsafe { &(*(::std::ptr::null::<foo>())).b as *const _ as usize }, |
| 147 | + 8usize, |
| 148 | + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) |
| 149 | + ); |
| 150 | +} |
| 151 | +impl Default for foo { |
| 152 | + fn default() -> Self { |
| 153 | + unsafe { ::std::mem::zeroed() } |
| 154 | + } |
| 155 | +} |
| 156 | +impl foo { |
| 157 | + #[inline] |
| 158 | + pub fn a(&self) -> ::std::os::raw::c_char { |
| 159 | + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } |
| 160 | + } |
| 161 | + #[inline] |
| 162 | + pub fn set_a(&mut self, val: ::std::os::raw::c_char) { |
| 163 | + unsafe { |
| 164 | + let val: u8 = ::std::mem::transmute(val); |
| 165 | + self._bitfield_1.set(0usize, 1u8, val as u64) |
| 166 | + } |
| 167 | + } |
| 168 | + #[inline] |
| 169 | + pub fn new_bitfield_1(a: ::std::os::raw::c_char) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { |
| 170 | + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize], u8> = |
| 171 | + Default::default(); |
| 172 | + __bindgen_bitfield_unit.set(0usize, 1u8, { |
| 173 | + let a: u8 = unsafe { ::std::mem::transmute(a) }; |
| 174 | + a as u64 |
| 175 | + }); |
| 176 | + __bindgen_bitfield_unit |
| 177 | + } |
| 178 | +} |
0 commit comments