From cf41afd5e280d275d9a4c596ebc13eb5e30a8949 Mon Sep 17 00:00:00 2001 From: Mikko Lehtonen Date: Fri, 17 Mar 2017 23:25:16 +0200 Subject: objc: Fix infinite recursion While parsing a Objective C property with function pointer type, bindgen hanged and died. This is still not generating valid code function signature for the property, but at least it is not dying. The actual fix was proposed by emilio. --- src/ir/function.rs | 4 ++- tests/expectations/tests/objc_property_fnptr.rs | 35 +++++++++++++++++++++++++ tests/headers/objc_property_fnptr.h | 8 ++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/objc_property_fnptr.rs create mode 100644 tests/headers/objc_property_fnptr.h diff --git a/src/ir/function.rs b/src/ir/function.rs index 23503b05..01689734 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -284,7 +284,9 @@ impl FunctionSig { let ty_ret_type = if cursor.kind() == CXCursor_ObjCInstanceMethodDecl || cursor.kind() == CXCursor_ObjCClassMethodDecl { - try!(cursor.ret_type().ok_or(ParseError::Continue)) + try!(ty.ret_type() + .or_else(|| cursor.ret_type()) + .ok_or(ParseError::Continue)) } else { try!(ty.ret_type().ok_or(ParseError::Continue)) }; diff --git a/tests/expectations/tests/objc_property_fnptr.rs b/tests/expectations/tests/objc_property_fnptr.rs new file mode 100644 index 00000000..044f25d1 --- /dev/null +++ b/tests/expectations/tests/objc_property_fnptr.rs @@ -0,0 +1,35 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + +#![cfg(target_os="macos")] + +#[macro_use] +extern crate objc; +#[allow(non_camel_case_types)] +pub type id = *mut objc::runtime::Object; +pub trait Foo { + unsafe fn func(self) + -> ::std::option::Option ::std::os::raw::c_int>; + unsafe fn setFunc_(self, + func: + ::std::option::Option + ::std::os::raw::c_int>); +} +impl Foo for id { + unsafe fn func(self) + -> + ::std::option::Option ::std::os::raw::c_int> { + msg_send!(self , func) + } + unsafe fn setFunc_(self, + func: + ::std::option::Option + ::std::os::raw::c_int>) { + msg_send!(self , setFunc:func ) + } +} diff --git a/tests/headers/objc_property_fnptr.h b/tests/headers/objc_property_fnptr.h new file mode 100644 index 00000000..8312ba4a --- /dev/null +++ b/tests/headers/objc_property_fnptr.h @@ -0,0 +1,8 @@ +// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-osx-only + +@interface Foo +// FIXME: We are not generating valid code for this +// but at least we should not die +@property int (*func)(char, short, float); +@end -- cgit v1.2.3