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