-
Notifications
You must be signed in to change notification settings - Fork 252
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
Static string is not borrowed correctly when used multiple times #743
Comments
I think this a transpiler bug. I'm also unsure how we should be properly handling this coming from an array (e.x.
This works when the mutable pointer is not actually written to, as I believe is the case in your use case, but it definitely could be written to, and according to my interpretation of this documentation, that would be UB, as it's not done through an Also, I'm unsure why we're using |
It sounds like |
Inlining and cloning shouldn't be necessary. I'm thinking what should be done is to create the mutable array as the backing store, and then immediately shadow it as a mutable pointer, which is then used for all use-sites. So something like this: let mut pos = pos.as_mut_ptr(); That more closely matches C's array-to-pointer decaying and gets us immediately back to pointer land in Rust, vs. reference land, which the array is in. I also noticed that the generated code is UB: let mut pos: [libc::c_char; 49] = *::core::mem::transmute::<&[u8; 49], &mut [libc::c_char; 49]>(
b"distance between cell centers should be positive\0",
);
let mut pos: [std::ffi::c_char; 49] = unsafe {
::core::mem::transmute::<[u8; 49], [std::ffi::c_char; 49]>(
*b"distance between cell centers should be positive\0",
)
}; |
(note, I probably don't know c2rust enough to correctly describe the problem)
When transpiling the c library h3, there exists a static string (in a macro?):
https://github.com/uber/h3/blob/139e5bff48ec16e5af745136d514a5b104869427/src/apps/testapps/testH3CellAreaExhaustive.c#L53
Which is transpiled like so:
I don't believe it should be mutable as the string is never changed. The variable is later referenced multiple times like this:
which throws a borrow checker error. I was able to fix the issue by just inlining the static string at the
pos.as_mut_ptr()
callsite.Code in LegNeato/unsafe-h3lib@386d0f4#r89264842 (note, takes a bit to load)
The text was updated successfully, but these errors were encountered: