• 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(Default)]
10 pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
11 impl<T> __IncompleteArrayField<T> {
12     #[inline]
new() -> Self13     pub const fn new() -> Self {
14         __IncompleteArrayField(::std::marker::PhantomData, [])
15     }
16     #[inline]
as_ptr(&self) -> *const T17     pub fn as_ptr(&self) -> *const T {
18         self as *const _ as *const T
19     }
20     #[inline]
as_mut_ptr(&mut self) -> *mut T21     pub fn as_mut_ptr(&mut self) -> *mut T {
22         self as *mut _ as *mut T
23     }
24     #[inline]
as_slice(&self, len: usize) -> &[T]25     pub unsafe fn as_slice(&self, len: usize) -> &[T] {
26         ::std::slice::from_raw_parts(self.as_ptr(), len)
27     }
28     #[inline]
as_mut_slice(&mut self, len: usize) -> &mut [T]29     pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
30         ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
31     }
32 }
33 impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result34     fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
35         fmt.write_str("__IncompleteArrayField")
36     }
37 }
38 #[repr(C)]
39 #[derive(Debug, Default)]
40 pub struct test {
41     pub a: ::std::os::raw::c_int,
42     pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>,
43 }
44 #[test]
bindgen_test_layout_test()45 fn bindgen_test_layout_test() {
46     const UNINIT: ::std::mem::MaybeUninit<test> =
47         ::std::mem::MaybeUninit::uninit();
48     let ptr = UNINIT.as_ptr();
49     assert_eq!(
50         ::std::mem::size_of::<test>(),
51         4usize,
52         concat!("Size of: ", stringify!(test))
53     );
54     assert_eq!(
55         ::std::mem::align_of::<test>(),
56         4usize,
57         concat!("Alignment of ", stringify!(test))
58     );
59     assert_eq!(
60         unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize },
61         0usize,
62         concat!("Offset of field: ", stringify!(test), "::", stringify!(a))
63     );
64     assert_eq!(
65         unsafe {
66             ::std::ptr::addr_of!((*ptr).zero_length_array) as usize -
67                 ptr as usize
68         },
69         4usize,
70         concat!(
71             "Offset of field: ",
72             stringify!(test),
73             "::",
74             stringify!(zero_length_array)
75         )
76     );
77 }
78 #[repr(C)]
79 #[derive(Debug, Default)]
80 pub struct test2 {
81     pub a: ::std::os::raw::c_int,
82     pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>,
83 }
84 #[test]
bindgen_test_layout_test2()85 fn bindgen_test_layout_test2() {
86     assert_eq!(
87         ::std::mem::size_of::<test2>(),
88         4usize,
89         concat!("Size of: ", stringify!(test2))
90     );
91     assert_eq!(
92         ::std::mem::align_of::<test2>(),
93         4usize,
94         concat!("Alignment of ", stringify!(test2))
95     );
96 }
97 #[repr(C)]
98 #[derive(Debug, Default)]
99 pub struct test3 {
100     pub a: ::std::os::raw::c_int,
101     pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>,
102     pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>,
103 }
104 #[test]
bindgen_test_layout_test3()105 fn bindgen_test_layout_test3() {
106     assert_eq!(
107         ::std::mem::size_of::<test3>(),
108         4usize,
109         concat!("Size of: ", stringify!(test3))
110     );
111     assert_eq!(
112         ::std::mem::align_of::<test3>(),
113         4usize,
114         concat!("Alignment of ", stringify!(test3))
115     );
116 }
117