diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 1b9a79155a..7b97b47727 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -163,6 +163,7 @@ fn main() { .blacklist_function("my_prefixed_function_to_remove") .constified_enum("my_prefixed_enum_to_be_constified") .opaque_type("my_prefixed_templated_foo") + .opaque_type("CoordOpaque") .generate() .expect("Unable to generate bindings"); diff --git a/bindgen-integration/cpp/Test.cc b/bindgen-integration/cpp/Test.cc index 71a0a4b9c7..1b13519087 100644 --- a/bindgen-integration/cpp/Test.cc +++ b/bindgen-integration/cpp/Test.cc @@ -144,3 +144,12 @@ Coord coord(double x, double y, double z, double t) { res.v[3] = t; return res; } + +CoordOpaque coord_opaque(double x, double y, double z, double t) { + CoordOpaque res; + res.v[0] = x; + res.v[1] = y; + res.v[2] = z; + res.v[3] = t; + return res; +} diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index 51a6e4b87f..39a6256d18 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -232,3 +232,9 @@ typedef union { } Coord; Coord coord(double x, double y, double z, double t); + +typedef struct { + double v[4]; +} CoordOpaque; + +CoordOpaque coord_opaque(double x, double y, double z, double t); diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 0d6989616c..8ff3abf5e6 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -7,6 +7,7 @@ mod bindings { use std::ffi::CStr; use std::mem; use std::os::raw::c_int; +use std::slice; #[allow(unused)] use bindings::testing::Bar; // This type is generated from module_raw_line. @@ -269,3 +270,14 @@ fn test_homogeneous_aggregate_float_union() { assert_eq!([1., 2., 3., 4.], coord.v) } } + +// https://github.com/rust-lang/rust-bindgen/issues/1973 +#[cfg_attr(target_arch = "aarch64", should_panic)] // This line should be removed after the bug linked above is fixed +#[test] +fn test_homogeneous_aggregate_float_opaque() { + unsafe { + let coord = &bindings::coord_opaque(1., 2., 3., 4.); + let v = unsafe { slice::from_raw_parts(coord as *const f64, 4) }; + assert_eq!([1., 2., 3., 4.], v) + } +}