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

Copy should not be derived if blacklisted type is included #944

Closed
upsuper opened this issue Sep 4, 2017 · 4 comments
Closed

Copy should not be derived if blacklisted type is included #944

upsuper opened this issue Sep 4, 2017 · 4 comments

Comments

@upsuper
Copy link
Contributor

upsuper commented Sep 4, 2017

Input C/C++ Header

struct Bar {
};

struct Foo {
  Bar a;
};

Bindgen Invocation

$ bindgen test.hpp --blacklist-type Bar

Actual Results

#[repr(C)]
#[derive(Debug, Copy)]
pub struct Foo {
    pub a: Bar,
}
#[test]
fn bindgen_test_layout_Foo() {
    assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
               "Size of: " , stringify ! ( Foo ) ));
    assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
                "Alignment of " , stringify ! ( Foo ) ));
    assert_eq! (unsafe {
                & ( * ( 0 as * const Foo ) ) . a as * const _ as usize } ,
                0usize , concat ! (
                "Alignment of field: " , stringify ! ( Foo ) , "::" ,
                stringify ! ( a ) ));
}
impl Clone for Foo {
    fn clone(&self) -> Self { *self }
}

Expected Results

struct Foo should not have #[derive(Copy)] because it is unknown whether the blacklisted type is Copy at all. Actually a type being blacklisted is usually a strong indication that it is a complicated type and bindgen shouldn't put any assumption on it at all.

@upsuper upsuper changed the title Copy should not be derived for blacklisted type Copy should not be derived if blacklisted type is included Sep 4, 2017
@upsuper
Copy link
Contributor Author

upsuper commented Sep 5, 2017

I looked into the code for a bit, but failed to figure out the best way to fix. Type blacklisting is based on name path, while derive check is based on item. We probably need some higher level check to stop deriving things when any name in blacklist presents in type declaration.

@emilio
Copy link
Contributor

emilio commented Sep 5, 2017

Yeah, the problem is that the checks act in the whitelisted items, and since we store the types that can't be derived instead of the ones that can, effectively all non-whitelisted items end up deriving copy.

@fitzgen
Copy link
Member

fitzgen commented Sep 5, 2017

I'll whip up a fix for this.

@fitzgen
Copy link
Member

fitzgen commented Sep 5, 2017

Fix in #950

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

No branches or pull requests

3 participants