• 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 pub type AnotherInt = ::std::os::raw::c_int;
9 #[repr(C)]
10 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
11 pub struct C {
12     pub c: C_MyInt,
13     pub ptr: *mut C_MyInt,
14     pub arr: [C_MyInt; 10usize],
15     pub d: AnotherInt,
16     pub other_ptr: *mut AnotherInt,
17 }
18 pub type C_MyInt = ::std::os::raw::c_int;
19 pub type C_Lookup = *const ::std::os::raw::c_char;
20 #[test]
bindgen_test_layout_C()21 fn bindgen_test_layout_C() {
22     const UNINIT: ::std::mem::MaybeUninit<C> =
23         ::std::mem::MaybeUninit::uninit();
24     let ptr = UNINIT.as_ptr();
25     assert_eq!(
26         ::std::mem::size_of::<C>(),
27         72usize,
28         concat!("Size of: ", stringify!(C))
29     );
30     assert_eq!(
31         ::std::mem::align_of::<C>(),
32         8usize,
33         concat!("Alignment of ", stringify!(C))
34     );
35     assert_eq!(
36         unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize },
37         0usize,
38         concat!("Offset of field: ", stringify!(C), "::", stringify!(c))
39     );
40     assert_eq!(
41         unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize },
42         8usize,
43         concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr))
44     );
45     assert_eq!(
46         unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize },
47         16usize,
48         concat!("Offset of field: ", stringify!(C), "::", stringify!(arr))
49     );
50     assert_eq!(
51         unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize },
52         56usize,
53         concat!("Offset of field: ", stringify!(C), "::", stringify!(d))
54     );
55     assert_eq!(
56         unsafe {
57             ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize
58         },
59         64usize,
60         concat!(
61             "Offset of field: ",
62             stringify!(C),
63             "::",
64             stringify!(other_ptr)
65         )
66     );
67 }
68 extern "C" {
69     #[link_name = "\u{1}_ZN1C6methodEi"]
C_method(this: *mut C, c: C_MyInt)70     pub fn C_method(this: *mut C, c: C_MyInt);
71 }
72 extern "C" {
73     #[link_name = "\u{1}_ZN1C9methodRefERi"]
C_methodRef(this: *mut C, c: *mut C_MyInt)74     pub fn C_methodRef(this: *mut C, c: *mut C_MyInt);
75 }
76 extern "C" {
77     #[link_name = "\u{1}_ZN1C16complexMethodRefERPKc"]
C_complexMethodRef(this: *mut C, c: *mut C_Lookup)78     pub fn C_complexMethodRef(this: *mut C, c: *mut C_Lookup);
79 }
80 extern "C" {
81     #[link_name = "\u{1}_ZN1C13anotherMethodEi"]
C_anotherMethod(this: *mut C, c: AnotherInt)82     pub fn C_anotherMethod(this: *mut C, c: AnotherInt);
83 }
84 impl Default for C {
default() -> Self85     fn default() -> Self {
86         let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
87         unsafe {
88             ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
89             s.assume_init()
90         }
91     }
92 }
93 impl C {
94     #[inline]
method(&mut self, c: C_MyInt)95     pub unsafe fn method(&mut self, c: C_MyInt) {
96         C_method(self, c)
97     }
98     #[inline]
methodRef(&mut self, c: *mut C_MyInt)99     pub unsafe fn methodRef(&mut self, c: *mut C_MyInt) {
100         C_methodRef(self, c)
101     }
102     #[inline]
complexMethodRef(&mut self, c: *mut C_Lookup)103     pub unsafe fn complexMethodRef(&mut self, c: *mut C_Lookup) {
104         C_complexMethodRef(self, c)
105     }
106     #[inline]
anotherMethod(&mut self, c: AnotherInt)107     pub unsafe fn anotherMethod(&mut self, c: AnotherInt) {
108         C_anotherMethod(self, c)
109     }
110 }
111 #[repr(C)]
112 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
113 pub struct D {
114     pub _base: C,
115     pub ptr: *mut C_MyInt,
116 }
117 #[test]
bindgen_test_layout_D()118 fn bindgen_test_layout_D() {
119     const UNINIT: ::std::mem::MaybeUninit<D> =
120         ::std::mem::MaybeUninit::uninit();
121     let ptr = UNINIT.as_ptr();
122     assert_eq!(
123         ::std::mem::size_of::<D>(),
124         80usize,
125         concat!("Size of: ", stringify!(D))
126     );
127     assert_eq!(
128         ::std::mem::align_of::<D>(),
129         8usize,
130         concat!("Alignment of ", stringify!(D))
131     );
132     assert_eq!(
133         unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize },
134         72usize,
135         concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr))
136     );
137 }
138 impl Default for D {
default() -> Self139     fn default() -> Self {
140         let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
141         unsafe {
142             ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
143             s.assume_init()
144         }
145     }
146 }
147