summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/clang.rs9
-rw-r--r--src/ir/ty.rs2
2 files changed, 7 insertions, 4 deletions
diff --git a/src/clang.rs b/src/clang.rs
index ae4a3f44..77cead95 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -678,9 +678,12 @@ impl Type {
/// Given that this type is an array or vector type, return its number of
/// elements.
- pub fn num_elements(&self) -> usize {
- unsafe {
- clang_getNumElements(self.x) as usize
+ pub fn num_elements(&self) -> Option<usize> {
+ let num_elements_returned = unsafe { clang_getNumElements(self.x) };
+ if num_elements_returned != -1 {
+ Some(num_elements_returned as usize)
+ } else {
+ None
}
}
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index 09059528..c55d7622 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -681,7 +681,7 @@ impl Type {
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.num_elements())
+ TypeKind::Array(inner, ty.num_elements().unwrap())
}
// A complex number is always a real and an imaginary part, so
// represent that as a two-item array.