Skip to content

Deduplicate names of overloaded virtual methods #48

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
SimonSapin opened this issue Sep 1, 2016 · 0 comments
Closed

Deduplicate names of overloaded virtual methods #48

SimonSapin opened this issue Sep 1, 2016 · 0 comments

Comments

@SimonSapin
Copy link
Contributor

Test case:

class Stream {
    public:
    virtual void write(char* string);
    virtual void write(void* buffer, unsigned int size);
};

Code generated by bindgen 1e26a8a:

#[repr(C)]
#[derive(Debug, Copy)]
pub struct Struct_Stream {
    pub _vftable: *const _vftable_Struct_Stream,
}
#[repr(C)]
pub struct _vftable_Struct_Stream {
    pub write: unsafe extern "C" fn(this: *mut ::std::os::raw::c_void,
                                    string: *mut ::std::os::raw::c_char),
    pub write: unsafe extern "C" fn(this: *mut ::std::os::raw::c_void,
                                    buffer: *mut ::std::os::raw::c_void,
                                    size: ::std::os::raw::c_uint),
}
impl ::std::clone::Clone for Struct_Stream {
    fn clone(&self) -> Self { *self }
}
#[test]
fn bindgen_test_layout_Struct_Stream() {
    assert_eq!(::std::mem::size_of::<Struct_Stream>() , 8usize);
    assert_eq!(::std::mem::align_of::<Struct_Stream>() , 8usize);
}

Struct fields with the same name are an error in Rust. Similar code fails with:

    --> src/bindings.rs:1987:5
     |
1985 |     pub write: unsafe extern "C" fn(this: *mut ::std::os::raw::c_void, b: u8)
     |     - `write` first declared here
1986 |                    -> usize,
1987 |     pub write: unsafe extern "C" fn(this: *mut ::std::os::raw::c_void,
     |     ^ field already declared

The field names should probably be deduplicated by appending an integer, like for names of non-virtual methods.

CC @emilio @nox

bors-servo pushed a commit that referenced this issue Sep 1, 2016
Deduplicate names of virtual overloaded methods. Fix #48

r? @emilio
jeanphilippeD added a commit to jeanphilippeD/rust-bindgen that referenced this issue Sep 25, 2016
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

1 participant