-
Notifications
You must be signed in to change notification settings - Fork 323
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
repr(transparent)
on a tuple struct wrapping an array
#777
Comments
related to #528 |
Is the ABI of |
are you saying that #[repr(transparent)]
pub struct K([u64; 2]);
#[no_mangle]
pub unsafe extern "C" fn function(arg: K) -> K {
a
} |
Yes, I don't see how that's safer than just |
well, I think so. I think the main fuss about arrays is that they decay into pointers in C. Other then that, I would expect the ABI to be the same as C ABI. Therefore, if you generate an array wrapped in a struct in the C header file, you should be able to use arrays in FFI on Rust side
Seems this is something we're going to have to ask on a Rust channel. I'll see about that |
Sure, as long as the Rust side also wraps them on a struct. But |
from the looks of it, you might be correct. All in all, I agree with your suggestion now, and that is to refuse to generate |
I think this was a rust bug, and it triggers improper_ctypes now. |
1: With the latest
cbindgen
, the following code:correctly produces:
whereas the following code:
incorrectly produces:
The 2nd example is incorrect because arrays in C decay to pointers (generated
typedef
is just an alias for an array) which means that the generated binding doesn't have the same ABI as it's rust equivalent. I see no reason to forbid this conversion (as is done for[u64;2]
), rather I would expect that the same code is generated as in the 1st example2: As a side note, I would also like to ask why is there no workaround to support raw
[u64;2]
incbindgen
like:Possible solutions to support this are to generate a custom wrapper struct on the C side, or maybe add a
cbindgen.toml
optionSomewhat related to #171 but this issue is, as far as I can see, resolved and should be closed
The text was updated successfully, but these errors were encountered: