Files
cbindgen/tests/rust/transform-op.rs
T
Emilio Cobos Álvarez b2e224354b Use placement new for constructing in tagged unions' helper methods.
Using operator= is not quite sound in presence of destructors and operator
overloading.

It's perfectly fine to assume that the left-hand-side of an operator= expression
is valid memory, however we're using uninitialized memory here, that may not be
the case.

Use placement new to properly construct tagged unions. I don't need this with
any urgency, but it's the right thing to do in presence of complex types, and
the current code seems a bomb waiting to explode :)
2019-05-10 18:15:39 +02:00

44 lines
645 B
Rust

#[repr(C)]
pub struct Point<T> {
pub x: T,
pub y: T,
}
#[repr(u8)]
pub enum Foo<T> {
Foo { x: i32, y: Point<T>, z: Point<f32>, },
Bar(T),
Baz(Point<T>),
Bazz,
}
#[repr(C)]
pub enum Bar<T> {
Bar1 { x: i32, y: Point<T>, z: Point<f32>, u: unsafe extern "C" fn(i32) -> i32, },
Bar2(T),
Bar3(Point<T>),
Bar4,
}
#[repr(u8)]
pub enum Baz {
Baz1(Bar<u32>),
Baz2(Point<i32>),
Baz3,
}
#[repr(C, u8)]
pub enum Taz {
Taz1(Bar<u32>),
Taz2(Baz),
Taz3,
}
#[no_mangle]
pub extern "C" fn foo(
foo: *const Foo<i32>,
bar: *const Bar<i32>,
baz: *const Baz,
taz: *const Taz,
) {}