1
Fork 0

extern-fn-explicit-align test: cleanup

This commit is contained in:
Erik Desjardins 2023-05-20 01:24:33 -04:00
parent 5f4472e451
commit bc9d26aee6

View file

@ -1,9 +1,9 @@
// Issue #80127: Passing structs via FFI should work with explicit alignment. // Issue #80127: Passing structs via FFI should work with explicit alignment.
use std::ffi::{CString, c_char}; use std::ffi::{CStr, c_char};
use std::ptr::null_mut; use std::ptr::null_mut;
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
#[repr(align(16))] #[repr(align(16))]
pub struct TwoU64s { pub struct TwoU64s {
@ -12,7 +12,7 @@ pub struct TwoU64s {
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Copy, Clone)]
pub struct BoolAndU32 { pub struct BoolAndU32 {
pub a: bool, pub a: bool,
pub b: u32, pub b: u32,
@ -37,10 +37,12 @@ extern "C" {
) -> i32; ) -> i32;
} }
const STRING: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"Hello world\0") };
fn main() { fn main() {
let two_u64s = TwoU64s { a: 1, b: 2 }; let two_u64s = TwoU64s { a: 1, b: 2 };
let bool_and_u32 = BoolAndU32 { a: true, b: 3 }; let bool_and_u32 = BoolAndU32 { a: true, b: 3 };
let string = CString::new("Hello world").unwrap(); let string = STRING;
unsafe { unsafe {
many_args( many_args(
null_mut(), null_mut(),