diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-10-02 10:01:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-02 10:01:51 -0500 |
commit | 57796e5e2b2b64388f7fb19a344552659e8326c3 (patch) | |
tree | a45799710ab527e21e5e760ed99bdeb986fc5455 | |
parent | 48586e84394890c70f2a6817368b22b057702ed5 (diff) | |
parent | 7b2b342a147993d586b8b028b5de635630afa631 (diff) |
Auto merge of #71 - emilio:vector, r=nox
Stub Vector types with arrays.
Fixes https://github.com/servo/servo/issues/13540
r? @nox
-rw-r--r-- | src/clang.rs | 8 | ||||
-rw-r--r-- | src/ir/ty.rs | 8 | ||||
-rw-r--r-- | tests/expectations/vector.rs | 19 | ||||
-rw-r--r-- | tests/headers/vector.hpp | 3 |
4 files changed, 33 insertions, 5 deletions
diff --git a/src/clang.rs b/src/clang.rs index ec6dbbe5..f98644ce 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -536,16 +536,16 @@ impl Type { } } - // array + // array, vector or complex. pub fn elem_type(&self) -> Type { unsafe { - Type { x: clang_getArrayElementType(self.x) } + Type { x: clang_getElementType(self.x) } } } - pub fn array_size(&self) -> usize { + pub fn num_elements(&self) -> usize { unsafe { - clang_getArraySize(self.x) as usize + clang_getNumElements(self.x) as usize } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 74452243..8227a786 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -538,10 +538,16 @@ impl Type { .expect("Not a complex type?"); TypeKind::Comp(complex) } + // FIXME: We stub vectors as arrays since in 99% of the cases the + // layout is going to be correct, and there's no way we can generate + // vector types properly in Rust for now. + // + // That being said, that should be fixed eventually. + CXType_Vector | CXType_ConstantArray => { let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx) .expect("Not able to resolve array element?"); - TypeKind::Array(inner, ty.array_size()) + TypeKind::Array(inner, ty.num_elements()) } #[cfg(not(feature="llvm_stable"))] CXType_Elaborated => { diff --git a/tests/expectations/vector.rs b/tests/expectations/vector.rs new file mode 100644 index 00000000..b8ca5735 --- /dev/null +++ b/tests/expectations/vector.rs @@ -0,0 +1,19 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy)] +pub struct foo { + pub mMember: [::std::os::raw::c_longlong; 1usize], +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!(::std::mem::size_of::<foo>() , 8usize); + assert_eq!(::std::mem::align_of::<foo>() , 8usize); +} +impl Clone for foo { + fn clone(&self) -> Self { *self } +} diff --git a/tests/headers/vector.hpp b/tests/headers/vector.hpp new file mode 100644 index 00000000..4707f77f --- /dev/null +++ b/tests/headers/vector.hpp @@ -0,0 +1,3 @@ +struct foo { + __attribute__((__vector_size__(1 * sizeof(long long)))) long long mMember; +}; |