c2rust
c2rust copied to clipboard
analyze: removing `mut` from `static` introduces Sync errors
static mut X: *mut T = ...; is legal, but static X: *mut T = ...; is not; the latter triggers the error "*mut T cannot be shared between threads safely", since *mut T does not implement Sync.
This happens in several places in lighttpd (33 errors)
If these statics are never written to (as should be the precondition for removing mut), what value of *mut type are they being initialized to? We might just be able to rewrite to static X: &'static T = ...;.
It's worth noting that *const has the same problem--we need a non-raw pointer here.
what value of
*muttype are they being initialized to?
Mostly null, but I see one that's an array of string literals (devices, in li_rand_device_bytes) and another that's a pointer to another static (log_errh).
If they're not mut and initialized to null, then what use are they in the first place?
I checked a few of the nulls manually and they're modified, but only in functions that we fail to analyze at the moment.
That means we have to assume a failing function modifies all globals, right? Or something similar (maybe we could do a more cursory check to see if it's referenced at all in that function). Or is this something that might be more worthwhile to fix in the transpiler (translate static const as static not static mut)?