diff options
author | Jean-Philippe DUFRAIGNE <j.dufraigne@gmail.com> | 2016-10-29 15:53:11 +0100 |
---|---|---|
committer | Jean-Philippe DUFRAIGNE <j.dufraigne@gmail.com> | 2016-10-29 22:33:06 +0100 |
commit | 17494dee60f5ede0486d8da4d2227d41c4c311c1 (patch) | |
tree | 392d926f088920ea28bba2d7a53b66d4cf7e22b8 | |
parent | 79407f3690f8488ec07fc310e885cba5b4e03162 (diff) |
Return Option<Type> in clang::Type::ret_type fix #141
Also reduce the scope for unsafe code
-rwxr-xr-x | src/clang.rs | 9 | ||||
-rw-r--r-- | src/ir/function.rs | 3 | ||||
-rw-r--r-- | src/ir/ty.rs | 2 |
3 files changed, 9 insertions, 5 deletions
diff --git a/src/clang.rs b/src/clang.rs index c0934055..543c52a9 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -714,9 +714,12 @@ impl Type { /// Given that this type is a function type, get the type of its return /// value. - pub fn ret_type(&self) -> Type { - unsafe { - Type { x: clang_getResultType(self.x) } + pub fn ret_type(&self) -> Option<Type> { + let rt = Type { x: unsafe { clang_getResultType(self.x) } }; + if rt.kind() == CXType_Invalid { + None + } else { + Some(rt) } } diff --git a/src/ir/function.rs b/src/ir/function.rs index 2693eddf..0cf23f43 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -186,7 +186,8 @@ impl FunctionSig { } } - let ret = try!(Item::from_ty(&ty.ret_type(), None, None, ctx)); + let ty_ret_type = try!(ty.ret_type().ok_or(ParseError::Continue)); + let ret = try!(Item::from_ty(&ty_ret_type, None, None, ctx)); let abi = get_abi(ty.call_conv()); Ok(Self::new(ret, args, ty.is_variadic(), abi)) diff --git a/src/ir/ty.rs b/src/ir/ty.rs index bbb666bc..7c640f30 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -499,7 +499,7 @@ impl Type { // tests/headers/func_ptr_in_struct.h), so we do a // guess here trying to see if it has a valid return // type. - if ty.ret_type().kind() != CXType_Invalid { + if ty.ret_type().is_some() { let signature = try!(FunctionSig::from_ty(ty, &location.unwrap_or(cursor), ctx)); TypeKind::Function(signature) |