immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.91k stars 229 forks source link

(`c2rust transpile`) Translate `static const`s without raw ptrs as non-`mut` `static`s #925

Open kkysen opened 1 year ago

kkysen commented 1 year ago

Currently, c2rust transpile translates all statics as static muts. This is still done even when the static in C is marked const. static muts are unsafe to access, so translating them as non-mut statics would be greatly beneficial. One caveat is that non-mut statics can't have any raw pointers anywhere inside them, so for those cases, we'll have to keep using a static mut, or possibly replace the raw pointers with Option<&'static _>s, as those raw pointers do have to be known at compile time. But at the very least, the simple static const cases with no raw pointers should be translated as non-mut statics. This would fix #907, as well as make manual transpilation like in rav1d easier (e.x. https://github.com/memorysafety/rav1d/pull/182/commits/27309d59cff90d889fa7338c3a69ccaad4c0dee4).