diff options
author | catdesk <catdesk@tuta.io> | 2016-10-29 16:20:28 +0200 |
---|---|---|
committer | Keith Yeung <kungfukeith11@gmail.com> | 2016-10-29 20:16:35 -0700 |
commit | 7dac42001d1dfe4b7f76027e94f95ea8d6dc141b (patch) | |
tree | 6e642903ea1baaea203db36a6da38735355d19ea | |
parent | f7b5fae91b212345bc8ce462cc700f4619e2a708 (diff) |
Change clang::Type::num_elements to return Option
-rwxr-xr-x | src/clang.rs | 9 | ||||
-rw-r--r-- | src/ir/ty.rs | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/clang.rs b/src/clang.rs index c0934055..40cd0ad7 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 3a17b374..46a8aa20 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -673,7 +673,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. |