#include <stdint.h>
void my_func(uint8_t arr[20]);
$ bindgen test.h
extern "C" {
pub fn my_func(arr: *mut u8);
}
I would've want it to produce this code instead:
extern "C" {
pub fn my_func(arr: *mut [u8; 20]);
}
Per IRC discussion, this is patchable, assuming they're equivalent, but it's not 100% clear to me they are, as pointers to slices and array in rust are so weird.
I really hope they're equivalent, let's see if someone that knows will answer.
posted also in the forum after someone asked me to https://users.rust-lang.org/t/is-using-array-pointers-with-ffi-ub/28197
Right now the responses in the forum seems to suggest that this isn't UB, and there's a difference between slices and arrays.
But I hoped that someone more known in the community will respond.
@emilio The memory structure of the type *const T and *const [u8; size_of::<T>()] are the same, seeing as they're contiguous. Seeing as they're the same, and *const T is the same as const *uint8_t, const *uint8_t also has to be the same as *const [u8; size_of::<T>()], and the fix elichai is proposing is a valid one.
Source:
An array is a collection of objects of the same type
T, stored in contiguous memory.
https://doc.rust-lang.org/rust-by-example/primitives/array.html
Yes. This should be pretty easy to patch:
Probably worth making it configurable, given it's trivial to keep both behaviors.
how do you want to pass the desired behavior? add an option to the builder?
I can give this a try and make a PR
Yeah, the options should be accessible from there, see similar uses of ctx.options() in that file.
ok, thanks that way it shouldn't even be a breaking change if the default stays the same :)
Yeah, that's definitely a plus :)
Most helpful comment
@emilio The memory structure of the type
*const Tand*const [u8; size_of::<T>()]are the same, seeing as they're contiguous. Seeing as they're the same, and*const Tis the same asconst *uint8_t,const *uint8_talso has to be the same as*const [u8; size_of::<T>()], and the fix elichai is proposing is a valid one.Source: