Skip to content

Objective-c header from CAMediaTimingFunction panics. #1703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
simlay opened this issue Jan 4, 2020 · 1 comment · Fixed by #1704
Closed

Objective-c header from CAMediaTimingFunction panics. #1703

simlay opened this issue Jan 4, 2020 · 1 comment · Fixed by #1704

Comments

@simlay
Copy link
Contributor

simlay commented Jan 4, 2020

If you try to make bindgen work for all of the UIKit iOS Framework one of the issues that comes up is the reference to initWithControlPoints.

It seems that thesplit_name logic in

let split_name: Vec<_> = self
. self.name here is initWithControlPoints::::, and the .filter(|p| !p.is_empty()) removes the empty parameters.

Input C/C++ Header

@interface CAMediaTimingFunction
- (instancetype)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y;
@end

Bindgen Invocation

$ bindgen input.h -- -x objective-c

Actual Results

$ RUST_BACKTRACE=1 bindgen input.h -- -x objective-c
cargo:warning=couldn't execute `llvm-config --prefix` (error: No such file or directory (os error 2))
cargo:warning=set the LLVM_CONFIG_PATH environment variable to a valid `llvm-config` executable
thread 'main' panicked at 'Incorrect method name or arguments for objc method, [TokenStream [Ident { sym: c1x }, Punct { op: ':', spacing: Alone }, Ident { sym: f32 }], TokenStream [Ident { sym: c1y }, Punct { op: ':', spacing: Alone }, Ident { sym: f32 }], TokenStream [Ident { sym: c2x }, Punct { op: ':', spacing: Alone }, Ident { sym: f32 }], TokenStream [Ident { sym: c2y }, Punct { op: ':', spacing: Alone }, Ident { sym: f32 }]] vs [Ident(initWithControlPoints)]', /Users/simlay/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.51.1/src/ir/objc.rs:232:13
stack backtrace:
   0: std::panicking::default_hook::{{closure}}
   1: std::panicking::default_hook
   2: std::panicking::rust_panic_with_hook
   3: std::panicking::continue_panic_fmt
   4: std::panicking::begin_panic_fmt
   5: bindgen::ir::objc::ObjCMethod::format_method_call
   6: bindgen::codegen::objc_method_codegen
   7: <bindgen::ir::objc::ObjCInterface as bindgen::codegen::CodeGenerator>::codegen
   8: <bindgen::ir::ty::Type as bindgen::codegen::CodeGenerator>::codegen
   9: <bindgen::ir::item::Item as bindgen::codegen::CodeGenerator>::codegen
  10: <bindgen::ir::module::Module as bindgen::codegen::CodeGenerator>::codegen::{{closure}}
  11: <bindgen::ir::module::Module as bindgen::codegen::CodeGenerator>::codegen
  12: <bindgen::ir::item::Item as bindgen::codegen::CodeGenerator>::codegen
  13: bindgen::ir::context::BindgenContext::gen
  14: bindgen::Builder::generate
  15: std::panicking::try::do_call
  16: __rust_maybe_catch_panic
  17: bindgen::main
  18: std::rt::lang_start::{{closure}}
  19: std::panicking::try::do_call
  20: __rust_maybe_catch_panic
  21: std::rt::lang_start_internal
  22: main

Expected Results

To not panic?

From what I can tell it should produce:

use objc;
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
pub trait CAMediaTimingFunction {
    unsafe fn initWithControlPoints____(
        self,
        c1x: f32,
        c1y: f32,
        c2x: f32,
        c2y: f32,
    ) -> instancetype;
}
impl CAMediaTimingFunction for id {
    unsafe fn initWithControlPoints____(
        self,
        c1x: f32,
        c1y: f32,
        c2x: f32,
        c2y: f32,
    ) -> instancetype {
        msg_send!(self, initWithControlPoints: c1x:c1x c1y:c1y c2x:c2x c2y:c2y)
    }
}
pub type instancetype = id;
@simlay
Copy link
Contributor Author

simlay commented Jan 4, 2020

After more investigation, this is because the method keywords are not there. CIImage has a better example of this.

There's not a ton of documentation around this (and I'm not an expert at objective-c syntax) but from what I can tell when the method keywords aren't there, you just use the internal name.

Also, in case you're curios these method declarations go against apple's guidelines for method declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant