• 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(Clone, Default)]
10 pub struct foo_struct {
11     pub inner: ::std::os::raw::c_int,
12 }
13 #[test]
bindgen_test_layout_foo_struct()14 fn bindgen_test_layout_foo_struct() {
15     const UNINIT: ::std::mem::MaybeUninit<foo_struct> =
16         ::std::mem::MaybeUninit::uninit();
17     let ptr = UNINIT.as_ptr();
18     assert_eq!(
19         ::std::mem::size_of::<foo_struct>(),
20         4usize,
21         concat!("Size of: ", stringify!(foo_struct))
22     );
23     assert_eq!(
24         ::std::mem::align_of::<foo_struct>(),
25         4usize,
26         concat!("Alignment of ", stringify!(foo_struct))
27     );
28     assert_eq!(
29         unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize },
30         0usize,
31         concat!(
32             "Offset of field: ",
33             stringify!(foo_struct),
34             "::",
35             stringify!(inner)
36         )
37     );
38 }
39 #[repr(u32)]
40 #[derive(Clone, Hash, PartialEq, Eq, Copy)]
41 pub enum foo_enum {
42     inner = 0,
43 }
44 #[repr(C)]
45 #[derive(Clone, Copy)]
46 pub union foo_union {
47     pub fst: ::std::mem::ManuallyDrop<::std::os::raw::c_int>,
48     pub snd: ::std::mem::ManuallyDrop<f32>,
49 }
50 #[test]
bindgen_test_layout_foo_union()51 fn bindgen_test_layout_foo_union() {
52     const UNINIT: ::std::mem::MaybeUninit<foo_union> =
53         ::std::mem::MaybeUninit::uninit();
54     let ptr = UNINIT.as_ptr();
55     assert_eq!(
56         ::std::mem::size_of::<foo_union>(),
57         4usize,
58         concat!("Size of: ", stringify!(foo_union))
59     );
60     assert_eq!(
61         ::std::mem::align_of::<foo_union>(),
62         4usize,
63         concat!("Alignment of ", stringify!(foo_union))
64     );
65     assert_eq!(
66         unsafe { ::std::ptr::addr_of!((*ptr).fst) as usize - ptr as usize },
67         0usize,
68         concat!(
69             "Offset of field: ",
70             stringify!(foo_union),
71             "::",
72             stringify!(fst)
73         )
74     );
75     assert_eq!(
76         unsafe { ::std::ptr::addr_of!((*ptr).snd) as usize - ptr as usize },
77         0usize,
78         concat!(
79             "Offset of field: ",
80             stringify!(foo_union),
81             "::",
82             stringify!(snd)
83         )
84     );
85 }
86 #[repr(C)]
87 pub struct non_matching {
88     pub inner: ::std::os::raw::c_int,
89 }
90 #[test]
bindgen_test_layout_non_matching()91 fn bindgen_test_layout_non_matching() {
92     const UNINIT: ::std::mem::MaybeUninit<non_matching> =
93         ::std::mem::MaybeUninit::uninit();
94     let ptr = UNINIT.as_ptr();
95     assert_eq!(
96         ::std::mem::size_of::<non_matching>(),
97         4usize,
98         concat!("Size of: ", stringify!(non_matching))
99     );
100     assert_eq!(
101         ::std::mem::align_of::<non_matching>(),
102         4usize,
103         concat!("Alignment of ", stringify!(non_matching))
104     );
105     assert_eq!(
106         unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize },
107         0usize,
108         concat!(
109             "Offset of field: ",
110             stringify!(non_matching),
111             "::",
112             stringify!(inner)
113         )
114     );
115 }
116