|
| 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"] |
| 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] |
| 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"] |
| 36 | + pub fn someClass_somePublicMethod( |
| 37 | + this: *mut someClass, |
| 38 | + foo: ::std::os::raw::c_int, |
| 39 | + ); |
| 40 | +} |
| 41 | +impl someClass { |
| 42 | + #[inline] |
| 43 | + pub unsafe fn somePublicMethod(&mut self, foo: ::std::os::raw::c_int) { |
| 44 | + someClass_somePublicMethod(self, foo) |
| 45 | + } |
| 46 | +} |
| 47 | +extern "C" { |
| 48 | + pub fn ExternFunction(); |
| 49 | +} |
| 50 | +extern "C" { |
| 51 | + #[link_name = "\u{1}_ZN3foo18NamespacedFunctionEv"] |
| 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] |
| 60 | +fn bindgen_test_layout_StructWithAllowlistedDefinition() { |
| 61 | + assert_eq!( |
| 62 | + ::std::mem::size_of::<StructWithAllowlistedDefinition>(), |
| 63 | + 8usize, |
| 64 | + concat!("Size of: ", stringify!(StructWithAllowlistedDefinition)) |
| 65 | + ); |
| 66 | + assert_eq!( |
| 67 | + ::std::mem::align_of::<StructWithAllowlistedDefinition>(), |
| 68 | + 8usize, |
| 69 | + concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)) |
| 70 | + ); |
| 71 | + assert_eq!( |
| 72 | + unsafe { |
| 73 | + &(*(::std::ptr::null::<StructWithAllowlistedDefinition>())).other |
| 74 | + as *const _ as usize |
| 75 | + }, |
| 76 | + 0usize, |
| 77 | + concat!( |
| 78 | + "Offset of field: ", |
| 79 | + stringify!(StructWithAllowlistedDefinition), |
| 80 | + "::", |
| 81 | + stringify!(other) |
| 82 | + ) |
| 83 | + ); |
| 84 | +} |
| 85 | +impl Default for StructWithAllowlistedDefinition { |
| 86 | + 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] |
| 100 | +fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { |
| 101 | + assert_eq!( |
| 102 | + ::std::mem::size_of::<StructWithAllowlistedFwdDecl>(), |
| 103 | + 4usize, |
| 104 | + concat!("Size of: ", stringify!(StructWithAllowlistedFwdDecl)) |
| 105 | + ); |
| 106 | + assert_eq!( |
| 107 | + ::std::mem::align_of::<StructWithAllowlistedFwdDecl>(), |
| 108 | + 4usize, |
| 109 | + concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)) |
| 110 | + ); |
| 111 | + assert_eq!( |
| 112 | + unsafe { |
| 113 | + &(*(::std::ptr::null::<StructWithAllowlistedFwdDecl>())).b |
| 114 | + as *const _ as usize |
| 115 | + }, |
| 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] |
| 131 | +fn bindgen_test_layout_AllowlistMe() { |
| 132 | + assert_eq!( |
| 133 | + ::std::mem::size_of::<AllowlistMe>(), |
| 134 | + 4usize, |
| 135 | + concat!("Size of: ", stringify!(AllowlistMe)) |
| 136 | + ); |
| 137 | + assert_eq!( |
| 138 | + ::std::mem::align_of::<AllowlistMe>(), |
| 139 | + 4usize, |
| 140 | + concat!("Alignment of ", stringify!(AllowlistMe)) |
| 141 | + ); |
| 142 | + assert_eq!( |
| 143 | + unsafe { |
| 144 | + &(*(::std::ptr::null::<AllowlistMe>())).foo as *const _ as usize |
| 145 | + }, |
| 146 | + 0usize, |
| 147 | + concat!( |
| 148 | + "Offset of field: ", |
| 149 | + stringify!(AllowlistMe), |
| 150 | + "::", |
| 151 | + stringify!(foo) |
| 152 | + ) |
| 153 | + ); |
| 154 | +} |
0 commit comments