Skip to content

Commit

Permalink
Add failing regression test for opaque types in rust-lang#1973.
Browse files Browse the repository at this point in the history
  • Loading branch information
saleemrashid committed Feb 7, 2021
1 parent 17476e9 commit d6e6811
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions bindgen-integration/build.rs
Expand Up @@ -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<my_prefixed_baz>")
.opaque_type("CoordOpaque")
.generate()
.expect("Unable to generate bindings");

Expand Down
9 changes: 9 additions & 0 deletions bindgen-integration/cpp/Test.cc
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions bindgen-integration/cpp/Test.h
Expand Up @@ -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);
12 changes: 12 additions & 0 deletions bindgen-integration/src/lib.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}

0 comments on commit d6e6811

Please sign in to comment.