diff options
author | Mikko Lehtonen <scoopr@iki.fi> | 2017-03-17 23:25:16 +0200 |
---|---|---|
committer | Mikko Lehtonen <scoopr@iki.fi> | 2017-05-03 00:54:14 +0300 |
commit | cf41afd5e280d275d9a4c596ebc13eb5e30a8949 (patch) | |
tree | 1fef9226e41c15898282425e9bafc1fbbd767383 | |
parent | c266097617f199d66b422a27ecd0bf22c6a9fdb2 (diff) |
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.
-rw-r--r-- | src/ir/function.rs | 4 | ||||
-rw-r--r-- | tests/expectations/tests/objc_property_fnptr.rs | 35 | ||||
-rw-r--r-- | tests/headers/objc_property_fnptr.h | 8 |
3 files changed, 46 insertions, 1 deletions
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<unsafe extern "C" fn() -> ::std::os::raw::c_int>; + unsafe fn setFunc_(self, + func: + ::std::option::Option<unsafe extern "C" fn() + -> + ::std::os::raw::c_int>); +} +impl Foo for id { + unsafe fn func(self) + -> + ::std::option::Option<unsafe extern "C" fn() + -> ::std::os::raw::c_int> { + msg_send!(self , func) + } + unsafe fn setFunc_(self, + func: + ::std::option::Option<unsafe extern "C" fn() + -> + ::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 |