-
Notifications
You must be signed in to change notification settings - Fork 776
Closed
Labels
Description
Input C/C++ Header
#pragma pack(push, 2)
struct Packed {
char a;
short b;
char c;
int d;
};
#pragma pack(pop)Bindgen Invocation
$ bindgen input.h --whitelist-type Packed
Actual Results
Bindings:
/* automatically generated by rust-bindgen 0.56.0 */
#[repr(C, packed(2))]
#[derive(Debug, Copy, Clone)]
pub struct Packed {
pub a: ::std::os::raw::c_char,
pub b: ::std::os::raw::c_short,
pub c: ::std::os::raw::c_char,
pub d: ::std::os::raw::c_int,
pub __bindgen_padding_0: [u8; 2usize],
}
#[test]
fn bindgen_test_layout_Packed() {
assert_eq!(
::std::mem::size_of::<Packed>(),
10usize,
concat!("Size of: ", stringify!(Packed))
);
assert_eq!(
::std::mem::align_of::<Packed>(),
2usize,
concat!("Alignment of ", stringify!(Packed))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Packed>())).a as *const _ as usize },
0usize,
concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Packed>())).b as *const _ as usize },
2usize,
concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Packed>())).c as *const _ as usize },
4usize,
concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Packed>())).d as *const _ as usize },
6usize,
concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d))
);
}Layout Test:
running 1 test
test bindgen_test_layout_Packed ... FAILED
failures:
---- bindgen_test_layout_Packed stdout ----
thread 'bindgen_test_layout_Packed' panicked at 'assertion failed: `(left == right)`
left: `12`,
right: `10`: Size of: Packed', layout.rs:14:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
bindgen_test_layout_Packed
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
Expected Results
Bindings:
/* automatically generated by rust-bindgen 0.56.0 */
#[repr(C, packed(2))]
#[derive(Debug, Copy, Clone)]
pub struct Packed {
pub a: ::std::os::raw::c_char,
pub b: ::std::os::raw::c_short,
pub c: ::std::os::raw::c_char,
pub d: ::std::os::raw::c_int,
}
#[test]
fn bindgen_test_layout_Packed() {
assert_eq!(
::std::mem::size_of::<Packed>(),
10usize,
concat!("Size of: ", stringify!(Packed))
);
assert_eq!(
::std::mem::align_of::<Packed>(),
2usize,
concat!("Alignment of ", stringify!(Packed))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Packed>())).a as *const _ as usize },
0usize,
concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Packed>())).b as *const _ as usize },
2usize,
concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Packed>())).c as *const _ as usize },
4usize,
concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<Packed>())).d as *const _ as usize },
6usize,
concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d))
);
}Layout Test:
running 1 test
test bindgen_test_layout_Packed ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out