diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index 6719095ba..f926b7495 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -35,6 +35,37 @@ Expression::Expression(const String& key, ExpressionOperator op, ASSERT(op != OperatorExecute || value.IsObjectType()); } +Value Expression::DeepClone(const Value& value) +{ + if (value.IsObjectType()) { + Array::Ptr array = value; + Array::Ptr result = make_shared(); + + ObjectLock olock(array); + + BOOST_FOREACH(const Value& item, array) { + result->Add(DeepClone(item)); + } + + return result; + } else if (value.IsObjectType()) { + Dictionary::Ptr dict = value; + Dictionary::Ptr result = make_shared(); + + ObjectLock olock(dict); + + String key; + Value item; + BOOST_FOREACH(boost::tuples::tie(key, item), dict) { + result->Set(key, DeepClone(item)); + } + + return result; + } + + return value; +} + void Expression::Execute(const Dictionary::Ptr& dictionary) const { Value oldValue, newValue; @@ -75,6 +106,8 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const dict = make_shared(); valueExprl->Execute(dict); newValue = dict; + } else { + newValue = DeepClone(newValue); } break; @@ -104,7 +137,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const String key; Value value; BOOST_FOREACH(boost::tie(key, value), valueDict) { - dict->Set(key, value); + dict->Set(key, DeepClone(value)); } newValue = dict; @@ -112,11 +145,10 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const if (!array) array = make_shared(); - ObjectLock olock(valueArray); BOOST_FOREACH(const Value& value, valueArray) { - array->Add(value); + array->Add(DeepClone(value)); } newValue = array; diff --git a/lib/config/expression.h b/lib/config/expression.h index 2313d09ad..85e8a2851 100644 --- a/lib/config/expression.h +++ b/lib/config/expression.h @@ -73,6 +73,8 @@ private: ExpressionOperator m_Operator; Value m_Value; DebugInfo m_DebugInfo; + + static Value DeepClone(const Value& value); }; }