1
0
Эх сурвалжийг харах

BUG: Pop a function scope even on error

This uses an automatic variable to push and pop variable scope inside a
function call.  Previously if the function failed its scope would not be
popped.  This approach guarantees a balanced push/pop.
Brad King 17 жил өмнө
parent
commit
9551cafd69

+ 2 - 3
Source/cmFunctionCommand.cxx

@@ -104,7 +104,8 @@ bool cmFunctionHelperCommand::InvokeInitialPass
     }
     }
 
 
   // we push a scope on the makefile
   // we push a scope on the makefile
-  this->Makefile->PushScope();
+  cmMakefile::ScopePushPop varScope(this->Makefile);
+  static_cast<void>(varScope);
 
 
   // set the value of argc
   // set the value of argc
   cmOStringStream strStream;
   cmOStringStream strStream;
@@ -167,13 +168,11 @@ bool cmFunctionHelperCommand::InvokeInitialPass
       }
       }
     if (status.GetReturnInvoked())
     if (status.GetReturnInvoked())
       {
       {
-      this->Makefile->PopScope();
       return true;
       return true;
       }
       }
     }
     }
 
 
   // pop scope on the makefile
   // pop scope on the makefile
-  this->Makefile->PopScope();
   return true;
   return true;
 }
 }
 
 

+ 10 - 0
Source/cmMakefile.h

@@ -780,6 +780,16 @@ public:
   void PopScope();
   void PopScope();
   void RaiseScope(const char *var, const char *value);
   void RaiseScope(const char *var, const char *value);
 
 
+  /** Helper class to push and pop scopes automatically.  */
+  class ScopePushPop
+  {
+  public:
+    ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
+    ~ScopePushPop() { this->Makefile->PopScope(); }
+  private:
+    cmMakefile* Makefile;
+  };
+
   void IssueMessage(cmake::MessageType t,
   void IssueMessage(cmake::MessageType t,
                     std::string const& text) const;
                     std::string const& text) const;