|
| 1 | +/* automatically generated by rust-bindgen */ |
| 2 | + |
| 3 | +#![allow( |
| 4 | + dead_code, |
| 5 | + non_snake_case, |
| 6 | + non_camel_case_types, |
| 7 | + non_upper_case_globals |
| 8 | +)] |
| 9 | +#![cfg(feature = "nightly")] |
| 10 | + |
| 11 | +/// This should not be opaque; we can see the attributes and can pack the |
| 12 | +/// struct. |
| 13 | +#[repr(C, packed)] |
| 14 | +#[derive(Debug, Default, Copy, Clone)] |
| 15 | +pub struct AlignedToOne { |
| 16 | + pub i: ::std::os::raw::c_int, |
| 17 | +} |
| 18 | +#[test] |
| 19 | +fn bindgen_test_layout_AlignedToOne() { |
| 20 | + assert_eq!( |
| 21 | + ::std::mem::size_of::<AlignedToOne>(), |
| 22 | + 4usize, |
| 23 | + concat!("Size of: ", stringify!(AlignedToOne)) |
| 24 | + ); |
| 25 | + assert_eq!( |
| 26 | + ::std::mem::align_of::<AlignedToOne>(), |
| 27 | + 1usize, |
| 28 | + concat!("Alignment of ", stringify!(AlignedToOne)) |
| 29 | + ); |
| 30 | + assert_eq!( |
| 31 | + unsafe { &(*(::std::ptr::null::<AlignedToOne>())).i as *const _ as usize }, |
| 32 | + 0usize, |
| 33 | + concat!( |
| 34 | + "Offset of field: ", |
| 35 | + stringify!(AlignedToOne), |
| 36 | + "::", |
| 37 | + stringify!(i) |
| 38 | + ) |
| 39 | + ); |
| 40 | +} |
| 41 | +/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. |
| 42 | +#[repr(C, packed(2))] |
| 43 | +#[derive(Debug, Default, Copy, Clone)] |
| 44 | +pub struct AlignedToTwo { |
| 45 | + pub i: ::std::os::raw::c_int, |
| 46 | +} |
| 47 | +#[test] |
| 48 | +fn bindgen_test_layout_AlignedToTwo() { |
| 49 | + assert_eq!( |
| 50 | + ::std::mem::size_of::<AlignedToTwo>(), |
| 51 | + 4usize, |
| 52 | + concat!("Size of: ", stringify!(AlignedToTwo)) |
| 53 | + ); |
| 54 | + assert_eq!( |
| 55 | + ::std::mem::align_of::<AlignedToTwo>(), |
| 56 | + 2usize, |
| 57 | + concat!("Alignment of ", stringify!(AlignedToTwo)) |
| 58 | + ); |
| 59 | + assert_eq!( |
| 60 | + unsafe { &(*(::std::ptr::null::<AlignedToTwo>())).i as *const _ as usize }, |
| 61 | + 0usize, |
| 62 | + concat!( |
| 63 | + "Offset of field: ", |
| 64 | + stringify!(AlignedToTwo), |
| 65 | + "::", |
| 66 | + stringify!(i) |
| 67 | + ) |
| 68 | + ); |
| 69 | +} |
| 70 | +/// This should not be opaque because although `libclang` doesn't give us the |
| 71 | +/// `#pragma pack(1)`, we can detect that alignment is 1 and add |
| 72 | +/// `#[repr(packed)]` to the struct ourselves. |
| 73 | +#[repr(C, packed)] |
| 74 | +#[derive(Debug, Default, Copy, Clone)] |
| 75 | +pub struct PackedToOne { |
| 76 | + pub x: ::std::os::raw::c_int, |
| 77 | + pub y: ::std::os::raw::c_int, |
| 78 | +} |
| 79 | +#[test] |
| 80 | +fn bindgen_test_layout_PackedToOne() { |
| 81 | + assert_eq!( |
| 82 | + ::std::mem::size_of::<PackedToOne>(), |
| 83 | + 8usize, |
| 84 | + concat!("Size of: ", stringify!(PackedToOne)) |
| 85 | + ); |
| 86 | + assert_eq!( |
| 87 | + ::std::mem::align_of::<PackedToOne>(), |
| 88 | + 1usize, |
| 89 | + concat!("Alignment of ", stringify!(PackedToOne)) |
| 90 | + ); |
| 91 | + assert_eq!( |
| 92 | + unsafe { &(*(::std::ptr::null::<PackedToOne>())).x as *const _ as usize }, |
| 93 | + 0usize, |
| 94 | + concat!( |
| 95 | + "Offset of field: ", |
| 96 | + stringify!(PackedToOne), |
| 97 | + "::", |
| 98 | + stringify!(x) |
| 99 | + ) |
| 100 | + ); |
| 101 | + assert_eq!( |
| 102 | + unsafe { &(*(::std::ptr::null::<PackedToOne>())).y as *const _ as usize }, |
| 103 | + 4usize, |
| 104 | + concat!( |
| 105 | + "Offset of field: ", |
| 106 | + stringify!(PackedToOne), |
| 107 | + "::", |
| 108 | + stringify!(y) |
| 109 | + ) |
| 110 | + ); |
| 111 | +} |
| 112 | +/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. |
| 113 | +#[repr(C, packed(2))] |
| 114 | +#[derive(Debug, Default, Copy, Clone)] |
| 115 | +pub struct PackedToTwo { |
| 116 | + pub x: ::std::os::raw::c_int, |
| 117 | + pub y: ::std::os::raw::c_int, |
| 118 | +} |
| 119 | +#[test] |
| 120 | +fn bindgen_test_layout_PackedToTwo() { |
| 121 | + assert_eq!( |
| 122 | + ::std::mem::size_of::<PackedToTwo>(), |
| 123 | + 8usize, |
| 124 | + concat!("Size of: ", stringify!(PackedToTwo)) |
| 125 | + ); |
| 126 | + assert_eq!( |
| 127 | + ::std::mem::align_of::<PackedToTwo>(), |
| 128 | + 2usize, |
| 129 | + concat!("Alignment of ", stringify!(PackedToTwo)) |
| 130 | + ); |
| 131 | + assert_eq!( |
| 132 | + unsafe { &(*(::std::ptr::null::<PackedToTwo>())).x as *const _ as usize }, |
| 133 | + 0usize, |
| 134 | + concat!( |
| 135 | + "Offset of field: ", |
| 136 | + stringify!(PackedToTwo), |
| 137 | + "::", |
| 138 | + stringify!(x) |
| 139 | + ) |
| 140 | + ); |
| 141 | + assert_eq!( |
| 142 | + unsafe { &(*(::std::ptr::null::<PackedToTwo>())).y as *const _ as usize }, |
| 143 | + 4usize, |
| 144 | + concat!( |
| 145 | + "Offset of field: ", |
| 146 | + stringify!(PackedToTwo), |
| 147 | + "::", |
| 148 | + stringify!(y) |
| 149 | + ) |
| 150 | + ); |
| 151 | +} |
0 commit comments