[Cmake-commits] [cmake-commits] king committed cmCMakePolicyCommand.cxx 1.4 1.5 cmMakefile.cxx 1.498 1.499 cmMakefile.h 1.249 1.250
cmake-commits at cmake.org
cmake-commits at cmake.org
Thu Jan 22 10:57:18 EST 2009
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv22805/Source
Modified Files:
cmCMakePolicyCommand.cxx cmMakefile.cxx cmMakefile.h
Log Message:
ENH: Create policy scope barriers
This creates a barrier mechanism to prevent user code from using
cmake_policy(POP) to pop a scope it didn't push with cmake_policy(PUSH).
Index: cmCMakePolicyCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCMakePolicyCommand.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -C 2 -d -r1.4 -r1.5
*** cmCMakePolicyCommand.cxx 18 Aug 2008 13:53:06 -0000 1.4
--- cmCMakePolicyCommand.cxx 22 Jan 2009 15:57:15 -0000 1.5
***************
*** 44,48 ****
return false;
}
! return this->Makefile->PushPolicy();
}
else if(args[0] == "POP")
--- 44,49 ----
return false;
}
! this->Makefile->PushPolicy();
! return true;
}
else if(args[0] == "POP")
***************
*** 53,65 ****
return false;
}
! if(this->Makefile->PopPolicy(false))
! {
! return true;
! }
! else
! {
! this->SetError("POP without matching PUSH");
! return false;
! }
}
else if(args[0] == "VERSION")
--- 54,59 ----
return false;
}
! this->Makefile->PopPolicy();
! return true;
}
else if(args[0] == "VERSION")
Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.249
retrieving revision 1.250
diff -C 2 -d -r1.249 -r1.250
*** cmMakefile.h 22 Jan 2009 15:57:09 -0000 1.249
--- cmMakefile.h 22 Jan 2009 15:57:16 -0000 1.250
***************
*** 352,358 ****
PolicyPushPop(cmMakefile* m);
~PolicyPushPop();
private:
cmMakefile* Makefile;
! size_t PolicyDepth;
};
friend class PolicyPushPop;
--- 352,359 ----
PolicyPushPop(cmMakefile* m);
~PolicyPushPop();
+ void Quiet() { this->ReportError = false; }
private:
cmMakefile* Makefile;
! bool ReportError;
};
friend class PolicyPushPop;
***************
*** 943,949 ****
// Internal policy stack management.
! bool PushPolicy();
! bool PopPolicy(bool reportError = true);
friend class cmCMakePolicyCommand;
// stack of policy settings
--- 944,954 ----
// Internal policy stack management.
! void PushPolicy();
! void PopPolicy();
! void PushPolicyBarrier();
! void PopPolicyBarrier(bool reportError = true);
friend class cmCMakePolicyCommand;
+ class IncludeScope;
+ friend class IncludeScope;
// stack of policy settings
***************
*** 957,960 ****
--- 962,966 ----
typedef std::vector<PolicyStackEntry> PolicyStackType;
PolicyStackType PolicyStack;
+ std::vector<PolicyStackType::size_type> PolicyBarriers;
cmPolicies::PolicyStatus GetPolicyStatusInternal(cmPolicies::PolicyID id);
Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.498
retrieving revision 1.499
diff -C 2 -d -r1.498 -r1.499
*** cmMakefile.cxx 22 Jan 2009 15:56:49 -0000 1.498
--- cmMakefile.cxx 22 Jan 2009 15:57:15 -0000 1.499
***************
*** 151,154 ****
--- 151,157 ----
this->PushPolicy();
+ // Protect the directory-level policies.
+ this->PushPolicyBarrier();
+
// By default the check is not done. It is enabled by
// cmListFileCache in the top level if necessary.
***************
*** 442,445 ****
--- 445,476 ----
}
+ //----------------------------------------------------------------------------
+ class cmMakefile::IncludeScope
+ {
+ public:
+ IncludeScope(cmMakefile* mf);
+ ~IncludeScope();
+ void Quiet() { this->ReportError = false; }
+ private:
+ cmMakefile* Makefile;
+ bool ReportError;
+ };
+
+ //----------------------------------------------------------------------------
+ cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf):
+ Makefile(mf), ReportError(true)
+ {
+ // The included file cannot pop our policy scope.
+ this->Makefile->PushPolicyBarrier();
+ }
+
+ //----------------------------------------------------------------------------
+ cmMakefile::IncludeScope::~IncludeScope()
+ {
+ // Enforce matching policy scopes inside the included file.
+ this->Makefile->PopPolicyBarrier(this->ReportError);
+ }
+
+ //----------------------------------------------------------------------------
// Parse the given CMakeLists.txt file executing all commands
//
***************
*** 534,541 ****
{
LexicalPushPop lexScope(this);
! bool endScopeNicely = true;
!
! // Save the current policy stack depth.
! size_t const policy_depth = this->PolicyStack.size();
// Run the parsed commands.
--- 565,569 ----
{
LexicalPushPop lexScope(this);
! IncludeScope incScope(this);
// Run the parsed commands.
***************
*** 548,553 ****
{
// Exit early due to error.
- endScopeNicely = false;
lexScope.Quiet();
break;
}
--- 576,581 ----
{
// Exit early due to error.
lexScope.Quiet();
+ incScope.Quiet();
break;
}
***************
*** 558,572 ****
}
}
-
- // Restore policy stack depth.
- while(this->PolicyStack.size() > policy_depth)
- {
- if(endScopeNicely)
- {
- this->IssueMessage(cmake::FATAL_ERROR,
- "cmake_policy PUSH without matching POP");
- }
- this->PopPolicy(false);
- }
}
--- 586,589 ----
***************
*** 3676,3683 ****
//----------------------------------------------------------------------------
! cmMakefile::PolicyPushPop::PolicyPushPop(cmMakefile* m): Makefile(m)
{
this->Makefile->PushPolicy();
! this->PolicyDepth = this->Makefile->PolicyStack.size();
}
--- 3693,3701 ----
//----------------------------------------------------------------------------
! cmMakefile::PolicyPushPop::PolicyPushPop(cmMakefile* m):
! Makefile(m), ReportError(true)
{
this->Makefile->PushPolicy();
! this->Makefile->PushPolicyBarrier();
}
***************
*** 3685,3727 ****
cmMakefile::PolicyPushPop::~PolicyPushPop()
{
! // Enforce matching PUSH/POP pairs.
! if(this->Makefile->PolicyStack.size() < this->PolicyDepth)
{
! this->Makefile->IssueMessage(cmake::FATAL_ERROR,
! "cmake_policy POP without matching PUSH");
! return;
}
! while(this->Makefile->PolicyStack.size() > this->PolicyDepth)
{
! this->Makefile->IssueMessage(cmake::FATAL_ERROR,
! "cmake_policy PUSH without matching POP");
! this->Makefile->PopPolicy(false);
}
-
- // Pop our scope.
- this->Makefile->PopPolicy();
}
//----------------------------------------------------------------------------
! bool cmMakefile::PushPolicy()
{
! // Allocate a new stack entry.
! this->PolicyStack.push_back(PolicyStackEntry());
! return true;
}
! bool cmMakefile::PopPolicy(bool reportError)
{
! if(this->PolicyStack.size() == 1)
{
if(reportError)
{
! cmSystemTools::Error("Attempt to pop the policy stack past "
! "it's beginning.");
}
! return false;
}
! this->PolicyStack.pop_back();
! return true;
}
--- 3703,3755 ----
cmMakefile::PolicyPushPop::~PolicyPushPop()
{
! this->Makefile->PopPolicyBarrier(this->ReportError);
! this->Makefile->PopPolicy();
! }
!
! //----------------------------------------------------------------------------
! void cmMakefile::PushPolicy()
! {
! // Allocate a new stack entry.
! this->PolicyStack.push_back(PolicyStackEntry());
! }
!
! //----------------------------------------------------------------------------
! void cmMakefile::PopPolicy()
! {
! if(this->PolicyStack.size() > this->PolicyBarriers.back())
{
! this->PolicyStack.pop_back();
}
! else
{
! this->IssueMessage(cmake::FATAL_ERROR,
! "cmake_policy POP without matching PUSH");
}
}
//----------------------------------------------------------------------------
! void cmMakefile::PushPolicyBarrier()
{
! this->PolicyBarriers.push_back(this->PolicyStack.size());
}
! //----------------------------------------------------------------------------
! void cmMakefile::PopPolicyBarrier(bool reportError)
{
! // Remove any extra entries pushed on the barrier.
! PolicyStackType::size_type barrier = this->PolicyBarriers.back();
! while(this->PolicyStack.size() > barrier)
{
if(reportError)
{
! this->IssueMessage(cmake::FATAL_ERROR,
! "cmake_policy PUSH without matching POP");
! reportError = false;
}
! this->PopPolicy();
}
!
! // Remove the barrier.
! this->PolicyBarriers.pop_back();
}
More information about the Cmake-commits
mailing list