Skip to content

Commit

Permalink
Add note about possible safety issue with GLOBAL_NODE
Browse files Browse the repository at this point in the history
  • Loading branch information
mqudsi committed May 17, 2024
1 parent 66618d6 commit ec1bf60
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/env/environment_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ impl Iterator for EnvNodeIter {
}

lazy_static! {
/// XXX: Possible safety issue here as EnvNodeRef is not Send/Sync and shouldn't
/// be placed in a static context without some sort of Send/Sync wrapper.
/// lazy_static papers over this but it triggers rust lints if you use
/// once_cell::sync::Lazy or std::sync::OnceLock instead.
static ref GLOBAL_NODE: EnvNodeRef = EnvNodeRef::new(false, None);
}

Expand Down Expand Up @@ -699,6 +703,7 @@ pub struct EnvStackImpl {
impl EnvStackImpl {
/// Return a new impl representing global variables, with a single local scope.
pub fn new() -> EnvMutex<EnvStackImpl> {
// XXX: Safety issue: We are accessing GLOBAL_NODE without having the global mutex locked!
let globals = GLOBAL_NODE.clone();
let locals = EnvNodeRef::new(false, None);
let base = EnvScopedImpl::new(locals, globals);
Expand Down

0 comments on commit ec1bf60

Please sign in to comment.