uucore: centralize unsafe env::set_var/remove_var in a wrapper module#12068
uucore: centralize unsafe env::set_var/remove_var in a wrapper module#12068sylvestre wants to merge 1 commit intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
2b3c43d to
14394df
Compare
|
@oech3 wdyt ? :) |
|
This does not make set_var an actual thread safe function... |
| /// | ||
| /// Wrapper around [`std::env::set_var`]. See the module documentation for | ||
| /// the safety considerations callers must uphold. | ||
| pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) { |
There was a problem hiding this comment.
This violates Rust's safety model. Safe Rust code must never be able to trigger UB by calling a safe function according to its documented signature. This wrapper makes the function safe to call from anywhere, but does not enforce the required invariants.
There was a problem hiding this comment.
sure but i don't think it is a big deal. i don't think we have a program dealing with env variable in a parallel context
There was a problem hiding this comment.
I think violating the safety model is a big deal...
Since we seem to set/remove vars only in tests, could we lock the environment using env-lock crate?.
of course but it centralized its management |
No description provided.