File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
tests/run-make/extern-fn-explicit-align Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 11// Issue #80127: Passing structs via FFI should work with explicit alignment.
22
3- use std:: ffi:: { CString , c_char} ;
3+ use std:: ffi:: { CStr , c_char} ;
44use std:: ptr:: null_mut;
55
6- #[ derive( Clone , Copy , Debug , PartialEq ) ]
6+ #[ derive( Copy , Clone ) ]
77#[ repr( C ) ]
88#[ repr( align( 16 ) ) ]
99pub struct TwoU64s {
@@ -12,7 +12,7 @@ pub struct TwoU64s {
1212}
1313
1414#[ repr( C ) ]
15- #[ derive( Debug , Copy , Clone ) ]
15+ #[ derive( Copy , Clone ) ]
1616pub struct BoolAndU32 {
1717 pub a : bool ,
1818 pub b : u32 ,
@@ -37,10 +37,12 @@ extern "C" {
3737 ) -> i32 ;
3838}
3939
40+ const STRING : & CStr = unsafe { CStr :: from_bytes_with_nul_unchecked ( b"Hello world\0 " ) } ;
41+
4042fn main ( ) {
4143 let two_u64s = TwoU64s { a : 1 , b : 2 } ;
4244 let bool_and_u32 = BoolAndU32 { a : true , b : 3 } ;
43- let string = CString :: new ( "Hello world" ) . unwrap ( ) ;
45+ let string = STRING ;
4446 unsafe {
4547 many_args (
4648 null_mut ( ) ,
You can’t perform that action at this time.
0 commit comments