blob: 20fdb9736d0ba30e062d2574d007cf5f3697f5ce [file] [log] [blame]
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]
pub type AnotherInt = ::std::os::raw::c_int;
#[repr(C)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct C {
pub c: C_MyInt,
pub ptr: *mut C_MyInt,
pub arr: [C_MyInt; 10usize],
pub d: AnotherInt,
pub other_ptr: *mut AnotherInt,
}
pub type C_MyInt = ::std::os::raw::c_int;
pub type C_Lookup = *const ::std::os::raw::c_char;
#[test]
fn bindgen_test_layout_C() {
assert_eq!(
::std::mem::size_of::<C>(),
72usize,
concat!("Size of: ", stringify!(C))
);
assert_eq!(
::std::mem::align_of::<C>(),
8usize,
concat!("Alignment of ", stringify!(C))
);
assert_eq!(
{
let struct_instance = unsafe { std::mem::zeroed::<C>() };
let struct_ptr = &struct_instance as *const C;
let field_ptr = std::ptr::addr_of!(struct_instance.c);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
std::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
0usize,
concat!("Offset of field: ", stringify!(C), "::", stringify!(c))
);
assert_eq!(
{
let struct_instance = unsafe { std::mem::zeroed::<C>() };
let struct_ptr = &struct_instance as *const C;
let field_ptr = std::ptr::addr_of!(struct_instance.ptr);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
std::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
8usize,
concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr))
);
assert_eq!(
{
let struct_instance = unsafe { std::mem::zeroed::<C>() };
let struct_ptr = &struct_instance as *const C;
let field_ptr = std::ptr::addr_of!(struct_instance.arr);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
std::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
16usize,
concat!("Offset of field: ", stringify!(C), "::", stringify!(arr))
);
assert_eq!(
{
let struct_instance = unsafe { std::mem::zeroed::<C>() };
let struct_ptr = &struct_instance as *const C;
let field_ptr = std::ptr::addr_of!(struct_instance.d);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
std::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
56usize,
concat!("Offset of field: ", stringify!(C), "::", stringify!(d))
);
assert_eq!(
{
let struct_instance = unsafe { std::mem::zeroed::<C>() };
let struct_ptr = &struct_instance as *const C;
let field_ptr = std::ptr::addr_of!(struct_instance.other_ptr);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
std::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
64usize,
concat!(
"Offset of field: ",
stringify!(C),
"::",
stringify!(other_ptr)
)
);
}
extern "C" {
#[link_name = "\u{1}_ZN1C6methodEi"]
pub fn C_method(this: *mut C, c: C_MyInt);
}
extern "C" {
#[link_name = "\u{1}_ZN1C9methodRefERi"]
pub fn C_methodRef(this: *mut C, c: *mut C_MyInt);
}
extern "C" {
#[link_name = "\u{1}_ZN1C16complexMethodRefERPKc"]
pub fn C_complexMethodRef(this: *mut C, c: *mut C_Lookup);
}
extern "C" {
#[link_name = "\u{1}_ZN1C13anotherMethodEi"]
pub fn C_anotherMethod(this: *mut C, c: AnotherInt);
}
impl Default for C {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
impl C {
#[inline]
pub unsafe fn method(&mut self, c: C_MyInt) {
C_method(self, c)
}
#[inline]
pub unsafe fn methodRef(&mut self, c: *mut C_MyInt) {
C_methodRef(self, c)
}
#[inline]
pub unsafe fn complexMethodRef(&mut self, c: *mut C_Lookup) {
C_complexMethodRef(self, c)
}
#[inline]
pub unsafe fn anotherMethod(&mut self, c: AnotherInt) {
C_anotherMethod(self, c)
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct D {
pub _base: C,
pub ptr: *mut C_MyInt,
}
#[test]
fn bindgen_test_layout_D() {
assert_eq!(
::std::mem::size_of::<D>(),
80usize,
concat!("Size of: ", stringify!(D))
);
assert_eq!(
::std::mem::align_of::<D>(),
8usize,
concat!("Alignment of ", stringify!(D))
);
assert_eq!(
{
let struct_instance = unsafe { std::mem::zeroed::<D>() };
let struct_ptr = &struct_instance as *const D;
let field_ptr = std::ptr::addr_of!(struct_instance.ptr);
let struct_address = struct_ptr as usize;
let field_address = field_ptr as usize;
std::mem::forget(struct_instance);
field_address.checked_sub(struct_address).unwrap()
},
72usize,
concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr))
);
}
impl Default for D {
fn default() -> Self {
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}