From 24861459b59ea61dd920971bc8ddc9bbbd04242e Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 16 Sep 2009 09:51:47 -0400 Subject: Initialize directory scope with closure of parent The commit "Improve dynamic variable scope implementation" optimized function scopes using an efficient parent scope pointer. However, the parent scope used to initialize a new directory might not exist later (like add_subdirectory called inside a function of the parent scope). This caused CMake to crash when following the dangling pointer to the original parent scope. We fix the problem in this commit by always computing the closure of the parent scope at directory initialization time so that no parent scope pointer is needed. See issue #9538. --- Source/cmMakefile.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 8233fef..1ebf06e 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1428,8 +1428,8 @@ void cmMakefile::InitializeFromParent() { cmMakefile *parent = this->LocalGenerator->GetParent()->GetMakefile(); - // copy the definitions - this->Internal->VarStack.top().Reset(&parent->Internal->VarStack.top()); + // Initialize definitions with the closure of the parent scope. + this->Internal->VarStack.top() = parent->Internal->VarStack.top().Closure(); // copy include paths this->IncludeDirectories = parent->IncludeDirectories; @@ -3422,6 +3422,14 @@ void cmMakefile::RaiseScope(const char *var, const char *varDef) // Now update the definition in the parent scope. up->Set(var, varDef); } + else if(cmMakefile* parent = + this->LocalGenerator->GetParent()->GetMakefile()) + { + // Update the definition in the parent directory top scope. This + // directory's scope was initialized by the closure of the parent + // scope, so we do not need to localize the definition first. + parent->Internal->VarStack.top().Set(var, varDef); + } } -- cgit v0.12