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 into
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
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
i think you are overreacting. afaik, it doesn't introduce safety issues
of course but it centralized its management |
|
How about adding |
How would that help? |
|
I think we should remove use of these functions instead: #12238 |
|
Can we wrap Mutex here? |
|
A mutex doesn't address the soundness issue, see rust-lang/rust#124636 (comment). cc: @ChrisDenton |
|
In an application if you can be 100% certain there is only one thread then it is safe to mutate the environment because another function literally can't be called while you're using If there are, or could be, multiple threads then there would need to be some way to guarantee that no thread (directly or indirectly) accesses the environment. This is practically impossible to uphold since many things can read the environment (e.g. almost any libc function reserves the right to do so). A mutex doesn't really help. |
|
@sylvestre The proposed |
|
It's a bit weird to "centralize" unsafe functions into a single function not marked as |
No description provided.