• 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 const SOME_DEFUN: u32 = 123;
9 extern "C" {
10     #[link_name = "\u{1}_Z12SomeFunctionv"]
SomeFunction()11     pub fn SomeFunction();
12 }
13 extern "C" {
14     pub static mut someVar: ::std::os::raw::c_int;
15 }
16 #[repr(C)]
17 #[derive(Debug, Default, Copy, Clone)]
18 pub struct someClass {
19     pub _address: u8,
20 }
21 #[test]
bindgen_test_layout_someClass()22 fn bindgen_test_layout_someClass() {
23     assert_eq!(
24         ::std::mem::size_of::<someClass>(),
25         1usize,
26         concat!("Size of: ", stringify!(someClass))
27     );
28     assert_eq!(
29         ::std::mem::align_of::<someClass>(),
30         1usize,
31         concat!("Alignment of ", stringify!(someClass))
32     );
33 }
34 extern "C" {
35     #[link_name = "\u{1}_ZN9someClass16somePublicMethodEi"]
someClass_somePublicMethod( this: *mut someClass, foo: ::std::os::raw::c_int, )36     pub fn someClass_somePublicMethod(
37         this: *mut someClass,
38         foo: ::std::os::raw::c_int,
39     );
40 }
41 impl someClass {
42     #[inline]
somePublicMethod(&mut self, foo: ::std::os::raw::c_int)43     pub unsafe fn somePublicMethod(&mut self, foo: ::std::os::raw::c_int) {
44         someClass_somePublicMethod(self, foo)
45     }
46 }
47 extern "C" {
ExternFunction()48     pub fn ExternFunction();
49 }
50 extern "C" {
51     #[link_name = "\u{1}_ZN3foo18NamespacedFunctionEv"]
foo_NamespacedFunction()52     pub fn foo_NamespacedFunction();
53 }
54 #[repr(C)]
55 #[derive(Debug, Copy, Clone)]
56 pub struct StructWithAllowlistedDefinition {
57     pub other: *mut StructWithAllowlistedFwdDecl,
58 }
59 #[test]
bindgen_test_layout_StructWithAllowlistedDefinition()60 fn bindgen_test_layout_StructWithAllowlistedDefinition() {
61     const UNINIT: ::std::mem::MaybeUninit<StructWithAllowlistedDefinition> =
62         ::std::mem::MaybeUninit::uninit();
63     let ptr = UNINIT.as_ptr();
64     assert_eq!(
65         ::std::mem::size_of::<StructWithAllowlistedDefinition>(),
66         8usize,
67         concat!("Size of: ", stringify!(StructWithAllowlistedDefinition))
68     );
69     assert_eq!(
70         ::std::mem::align_of::<StructWithAllowlistedDefinition>(),
71         8usize,
72         concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition))
73     );
74     assert_eq!(
75         unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize },
76         0usize,
77         concat!(
78             "Offset of field: ",
79             stringify!(StructWithAllowlistedDefinition),
80             "::",
81             stringify!(other)
82         )
83     );
84 }
85 impl Default for StructWithAllowlistedDefinition {
default() -> Self86     fn default() -> Self {
87         let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
88         unsafe {
89             ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
90             s.assume_init()
91         }
92     }
93 }
94 #[repr(C)]
95 #[derive(Debug, Default, Copy, Clone)]
96 pub struct StructWithAllowlistedFwdDecl {
97     pub b: ::std::os::raw::c_int,
98 }
99 #[test]
bindgen_test_layout_StructWithAllowlistedFwdDecl()100 fn bindgen_test_layout_StructWithAllowlistedFwdDecl() {
101     const UNINIT: ::std::mem::MaybeUninit<StructWithAllowlistedFwdDecl> =
102         ::std::mem::MaybeUninit::uninit();
103     let ptr = UNINIT.as_ptr();
104     assert_eq!(
105         ::std::mem::size_of::<StructWithAllowlistedFwdDecl>(),
106         4usize,
107         concat!("Size of: ", stringify!(StructWithAllowlistedFwdDecl))
108     );
109     assert_eq!(
110         ::std::mem::align_of::<StructWithAllowlistedFwdDecl>(),
111         4usize,
112         concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl))
113     );
114     assert_eq!(
115         unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize },
116         0usize,
117         concat!(
118             "Offset of field: ",
119             stringify!(StructWithAllowlistedFwdDecl),
120             "::",
121             stringify!(b)
122         )
123     );
124 }
125 #[repr(C)]
126 #[derive(Debug, Default, Copy, Clone)]
127 pub struct AllowlistMe {
128     pub foo: ::std::os::raw::c_int,
129 }
130 #[test]
bindgen_test_layout_AllowlistMe()131 fn bindgen_test_layout_AllowlistMe() {
132     const UNINIT: ::std::mem::MaybeUninit<AllowlistMe> =
133         ::std::mem::MaybeUninit::uninit();
134     let ptr = UNINIT.as_ptr();
135     assert_eq!(
136         ::std::mem::size_of::<AllowlistMe>(),
137         4usize,
138         concat!("Size of: ", stringify!(AllowlistMe))
139     );
140     assert_eq!(
141         ::std::mem::align_of::<AllowlistMe>(),
142         4usize,
143         concat!("Alignment of ", stringify!(AllowlistMe))
144     );
145     assert_eq!(
146         unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize },
147         0usize,
148         concat!(
149             "Offset of field: ",
150             stringify!(AllowlistMe),
151             "::",
152             stringify!(foo)
153         )
154     );
155 }
156