Skip to content

Multidimensional array binding has incorrect mutability. #1849

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
jbangelo opened this issue Jul 28, 2020 · 2 comments · Fixed by #1861
Closed

Multidimensional array binding has incorrect mutability. #1849

jbangelo opened this issue Jul 28, 2020 · 2 comments · Fixed by #1861

Comments

@jbangelo
Copy link
Contributor

Input C/C++ Header

void foo(const int array[][5]);

Bindgen Invocation

Using bindgen execute version 0.54.1

$ bindgen array_func.h

Actual Results

extern "C" {
    pub fn foo(array: *mut [::std::os::raw::c_int; 5usize]);
}

Expected Results

extern "C" {
    pub fn foo(array: *const [::std::os::raw::c_int; 5usize]);
}

The pointer in the bindings should not be mutable. In the C function the const applies to all dimensions of the array, and there's no way to legally modify any part of the array. A single dimension array works as expected, so it seems to be just an issue with multidimensional arrays.

@jbangelo
Copy link
Contributor Author

I'd be happy to help resolve this issue, assuming it is indeed a real problem. Pointers/suggestions on where or how to fix this would be appreciated (sorry about the pun 😄).

@emilio
Copy link
Contributor

emilio commented Jul 31, 2020

Hmm, I'd look at similar issues like #1727 and such. e09602b is the fix for that, maybe we're missing a similar check in the code that parses arrays. Though I'd first double-check that that is what the C compiler is doing.

Thanks for filing this!

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

Successfully merging a pull request may close this issue.

2 participants