From ec1bf60941a6df2c44bafecd39c69ec9faaa69ef Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 16 May 2024 20:15:34 -0500 Subject: [PATCH] Add note about possible safety issue with GLOBAL_NODE --- src/env/environment_impl.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/env/environment_impl.rs b/src/env/environment_impl.rs index 010084bf2..e1712cd6a 100644 --- a/src/env/environment_impl.rs +++ b/src/env/environment_impl.rs @@ -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); } @@ -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 { + // 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);