Salome HOME
Issue #464 just clear local context of the interpreter, not initialize it from scratch
authorsbh <sergey.belash@opencascade.com>
Thu, 16 Apr 2015 14:18:06 +0000 (17:18 +0300)
committersbh <sergey.belash@opencascade.com>
Thu, 16 Apr 2015 14:18:06 +0000 (17:18 +0300)
src/ParametersPlugin/ParametersPlugin_Parameter.cpp
src/ParametersPlugin/ParametersPlugin_PyInterp.cpp
src/ParametersPlugin/ParametersPlugin_PyInterp.h

index 70840ccff61641a071de1ab711ca1ba972df0a98..48f5d731236e99c4d008b66a7bccb0206c73d53f 100644 (file)
@@ -18,6 +18,7 @@
 ParametersPlugin_Parameter::ParametersPlugin_Parameter()
 {
   myInterp = new ParametersPlugin_PyInterp();
+  myInterp->initialize();
 }
 
 ParametersPlugin_Parameter::~ParametersPlugin_Parameter()
@@ -76,7 +77,7 @@ void ParametersPlugin_Parameter::execute()
 
 double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, std::string& theError)
 {
-  myInterp->initialize();
+
   std::list<std::string> anExprParams = myInterp->compile(theExpression);
   // find expression's params in the model
   std::list<std::string> aContext;
@@ -92,6 +93,6 @@ double ParametersPlugin_Parameter::evaluate(const std::string& theExpression, st
   }
   myInterp->extendLocalContext(aContext);
   double result = myInterp->evaluate(theExpression, theError);
-  myInterp->destroy();
+  myInterp->clearLocalContext();
   return result;
 }
index 7a5f42c4fe5243e9abf000951c50ce36971aded1..4afbfaa2a93f75a404e12d1f7cd57c2dd6bb12ee 100644 (file)
@@ -69,6 +69,12 @@ void ParametersPlugin_PyInterp::extendLocalContext(const std::list<std::string>&
   }
 }
 
+void ParametersPlugin_PyInterp::clearLocalContext()
+{
+  PyLockWrapper lck;
+  PyDict_Clear(_local_context);
+}
+
 
 double ParametersPlugin_PyInterp::evaluate(const std::string& theExpression, std::string& theError)
 {
index 4151f4e231cf192a3dd18c3cb26b06b7db318dd0..0e3cdee56401f7819ae60e5d31ce7a63102f2a99 100644 (file)
@@ -22,6 +22,7 @@ class PARAMETERSPLUGIN_EXPORT ParametersPlugin_PyInterp : public PyInterp_Interp
 
   std::list<std::string> compile(const std::string&);
   void extendLocalContext(const std::list<std::string>&);
+  void clearLocalContext();
   double evaluate(const std::string&, std::string&);
 
  protected: