From 4b42d82d7269a3146fbe09d88f5da936bf49452f Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 16 Apr 2015 17:18:06 +0300 Subject: [PATCH] Issue #464 just clear local context of the interpreter, not initialize it from scratch --- src/ParametersPlugin/ParametersPlugin_Parameter.cpp | 5 +++-- src/ParametersPlugin/ParametersPlugin_PyInterp.cpp | 6 ++++++ src/ParametersPlugin/ParametersPlugin_PyInterp.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp index 70840ccff..48f5d7312 100644 --- a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp @@ -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 anExprParams = myInterp->compile(theExpression); // find expression's params in the model std::list 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; } diff --git a/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp b/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp index 7a5f42c4f..4afbfaa2a 100644 --- a/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp +++ b/src/ParametersPlugin/ParametersPlugin_PyInterp.cpp @@ -69,6 +69,12 @@ void ParametersPlugin_PyInterp::extendLocalContext(const std::list& } } +void ParametersPlugin_PyInterp::clearLocalContext() +{ + PyLockWrapper lck; + PyDict_Clear(_local_context); +} + double ParametersPlugin_PyInterp::evaluate(const std::string& theExpression, std::string& theError) { diff --git a/src/ParametersPlugin/ParametersPlugin_PyInterp.h b/src/ParametersPlugin/ParametersPlugin_PyInterp.h index 4151f4e23..0e3cdee56 100644 --- a/src/ParametersPlugin/ParametersPlugin_PyInterp.h +++ b/src/ParametersPlugin/ParametersPlugin_PyInterp.h @@ -22,6 +22,7 @@ class PARAMETERSPLUGIN_EXPORT ParametersPlugin_PyInterp : public PyInterp_Interp std::list compile(const std::string&); void extendLocalContext(const std::list&); + void clearLocalContext(); double evaluate(const std::string&, std::string&); protected: -- 2.39.2