Brian Silverman | 8751d48 | 2022-05-18 23:28:44 -0700 | [diff] [blame] | 1 | extern "C" { |
| 2 | fn c_return5() -> u8; |
| 3 | fn c_take5(x: *mut u8); |
| 4 | } |
| 5 | |
| 6 | #[no_mangle] |
| 7 | pub unsafe extern "C" fn rust_return5() -> i32 { |
| 8 | let layout = std::alloc::Layout::from_size_align(1, 1).unwrap(); |
| 9 | let a = std::alloc::alloc(layout); |
| 10 | *a = c_return5(); |
| 11 | // Do something so the compiler can't optimize out the alloc+free pair, which would invalidate |
| 12 | // this test. |
| 13 | if *a != 5 { |
| 14 | c_take5(a); |
| 15 | } else { |
| 16 | std::alloc::dealloc(a, layout); |
| 17 | } |
| 18 | 5 |
| 19 | } |