Skip to content
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

Incorrect codegen for clang block with single arg #1520

Closed
benw opened this issue Feb 11, 2019 · 1 comment
Closed

Incorrect codegen for clang block with single arg #1520

benw opened this issue Feb 11, 2019 · 1 comment

Comments

@benw
Copy link

benw commented Feb 11, 2019

Input C/C++ Header

void foo(void (^callback)(unsigned char));

Bindgen Invocation

$ bindgen --generate-block --block-extern-crate input.h

Actual Results

extern "C" {
    #[link_name = "\u{1}_foo"]
    pub fn foo(callback: _bindgen_ty_id_6);
}
pub type _bindgen_ty_id_6 =
    *const ::block::Block<(::std::os::raw::c_uchar), ()>;

The problem is in the last line: the Block's arg type should be the single-element tuple (c_uchar,) but it is missing the comma. This non-tuple type is incompatible with the BlockArguments trait.

Expected Results

extern "C" {
    #[link_name = "\u{1}_foo"]
    pub fn foo(callback: _bindgen_ty_id_6);
}
pub type _bindgen_ty_id_6 =
    *const ::block::Block<(::std::os::raw::c_uchar,), ()>;

Impact

Trying to invoke this function:

unsafe fn bar(callback: *const Block<(u8,), ()>) {
    foo(callback);
}

leads to error:

error[E0308]: mismatched types
 --> src/lib.rs:7:9
  |
7 |     foo(callback);
  |         ^^^^^^^^ expected u8, found tuple
  |
  = note: expected type `*const ffi::block::Block<u8, ()>`
             found type `*const ffi::block::Block<(u8,), ()>`
@emilio
Copy link
Contributor

emilio commented Feb 11, 2019

Fixed by #1519. Thanks @flier!

@emilio emilio closed this as completed Feb 11, 2019
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

No branches or pull requests

2 participants