Merge pull request #7364 from Icinga/feature/expression-namespacevalue-intrusive-pointers-7361

Replace classic shared pointers to Expression and NamespaceValue with intrusive ones
This commit is contained in:
Michael Friedrich 2019-10-22 08:55:37 +02:00 committed by GitHub
commit 11394498e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 183 additions and 103 deletions

View File

@ -61,6 +61,7 @@ set(base_SOURCES
scriptutils.cpp scriptutils.hpp
serializer.cpp serializer.hpp
shared.hpp
shared-object.hpp
singleton.hpp
socket.cpp socket.hpp
stacktrace.cpp stacktrace.hpp

View File

@ -60,28 +60,28 @@ private:
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), false); \
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
nsp->SetAttribute(#name, std::make_shared<ConstEmbeddedNamespaceValue>(sf)); \
nsp->SetAttribute(#name, new ConstEmbeddedNamespaceValue(sf)); \
}, 10)
#define REGISTER_SAFE_FUNCTION(ns, name, callback, args) \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), true); \
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
nsp->SetAttribute(#name, std::make_shared<ConstEmbeddedNamespaceValue>(sf)); \
nsp->SetAttribute(#name, new ConstEmbeddedNamespaceValue(sf)); \
}, 10)
#define REGISTER_FUNCTION_NONCONST(ns, name, callback, args) \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), false); \
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
nsp->SetAttribute(#name, std::make_shared<EmbeddedNamespaceValue>(sf)); \
nsp->SetAttribute(#name, new EmbeddedNamespaceValue(sf)); \
}, 10)
#define REGISTER_SAFE_FUNCTION_NONCONST(ns, name, callback, args) \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), true); \
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
nsp->SetAttribute(#name, std::make_shared<EmbeddedNamespaceValue>(sf)); \
nsp->SetAttribute(#name, new EmbeddedNamespaceValue(sf)); \
}, 10)
}

View File

@ -25,5 +25,5 @@ INITIALIZE_ONCE([]() {
jsonNSBehavior->Freeze();
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
systemNS->SetAttribute("Json", std::make_shared<ConstEmbeddedNamespaceValue>(jsonNS));
systemNS->SetAttribute("Json", new ConstEmbeddedNamespaceValue(jsonNS));
});

View File

@ -181,5 +181,5 @@ INITIALIZE_ONCE([]() {
mathNSBehavior->Freeze();
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
systemNS->SetAttribute("Math", std::make_shared<ConstEmbeddedNamespaceValue>(mathNS));
systemNS->SetAttribute("Math", new ConstEmbeddedNamespaceValue(mathNS));
});

View File

@ -75,7 +75,7 @@ void Namespace::RemoveAttribute(const String& field)
m_Data.erase(it);
}
std::shared_ptr<NamespaceValue> Namespace::GetAttribute(const String& key) const
NamespaceValue::Ptr Namespace::GetAttribute(const String& key) const
{
ObjectLock olock(this);
@ -87,7 +87,7 @@ std::shared_ptr<NamespaceValue> Namespace::GetAttribute(const String& key) const
return it->second;
}
void Namespace::SetAttribute(const String& key, const std::shared_ptr<NamespaceValue>& nsVal)
void Namespace::SetAttribute(const String& key, const NamespaceValue::Ptr& nsVal)
{
ObjectLock olock(this);
@ -162,7 +162,7 @@ void ConstEmbeddedNamespaceValue::Set(const Value& value, bool overrideFrozen, c
void NamespaceBehavior::Register(const Namespace::Ptr& ns, const String& field, const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) const
{
ns->SetAttribute(field, std::make_shared<EmbeddedNamespaceValue>(value));
ns->SetAttribute(field, new EmbeddedNamespaceValue(value));
}
void NamespaceBehavior::Remove(const Namespace::Ptr& ns, const String& field, bool overrideFrozen)
@ -182,7 +182,7 @@ void ConstNamespaceBehavior::Register(const Namespace::Ptr& ns, const String& fi
if (m_Frozen && !overrideFrozen)
BOOST_THROW_EXCEPTION(ScriptError("Namespace is read-only and must not be modified.", debugInfo));
ns->SetAttribute(field, std::make_shared<ConstEmbeddedNamespaceValue>(value));
ns->SetAttribute(field, new ConstEmbeddedNamespaceValue(value));
}
void ConstNamespaceBehavior::Remove(const Namespace::Ptr& ns, const String& field, bool overrideFrozen)

View File

@ -5,6 +5,7 @@
#include "base/i2-base.hpp"
#include "base/object.hpp"
#include "base/shared-object.hpp"
#include "base/value.hpp"
#include "base/debuginfo.hpp"
#include <map>
@ -14,8 +15,10 @@
namespace icinga
{
struct NamespaceValue
struct NamespaceValue : public SharedObject
{
DECLARE_PTR_TYPEDEFS(NamespaceValue);
virtual Value Get(const DebugInfo& debugInfo = DebugInfo()) const = 0;
virtual void Set(const Value& value, bool overrideFrozen, const DebugInfo& debugInfo = DebugInfo()) = 0;
};
@ -66,9 +69,9 @@ class Namespace final : public Object
public:
DECLARE_OBJECT(Namespace);
typedef std::map<String, std::shared_ptr<NamespaceValue> >::iterator Iterator;
typedef std::map<String, NamespaceValue::Ptr>::iterator Iterator;
typedef std::map<String, std::shared_ptr<NamespaceValue> >::value_type Pair;
typedef std::map<String, NamespaceValue::Ptr>::value_type Pair;
Namespace(NamespaceBehavior *behavior = new NamespaceBehavior);
@ -78,8 +81,8 @@ public:
bool Contains(const String& field) const;
void Remove(const String& field, bool overrideFrozen = false);
std::shared_ptr<NamespaceValue> GetAttribute(const String& field) const;
void SetAttribute(const String& field, const std::shared_ptr<NamespaceValue>& nsVal);
NamespaceValue::Ptr GetAttribute(const String& field) const;
void SetAttribute(const String& field, const NamespaceValue::Ptr& nsVal);
void RemoveAttribute(const String& field);
Iterator Begin();
@ -93,7 +96,7 @@ public:
static Object::Ptr GetPrototype();
private:
std::map<String, std::shared_ptr<NamespaceValue> > m_Data;
std::map<String, NamespaceValue::Ptr> m_Data;
std::unique_ptr<NamespaceBehavior> m_Behavior;
};

View File

@ -22,22 +22,22 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
auto systemNSBehavior = new ConstNamespaceBehavior();
systemNSBehavior->Freeze();
Namespace::Ptr systemNS = new Namespace(systemNSBehavior);
globalNS->SetAttribute("System", std::make_shared<ConstEmbeddedNamespaceValue>(systemNS));
globalNS->SetAttribute("System", new ConstEmbeddedNamespaceValue(systemNS));
systemNS->SetAttribute("Configuration", std::make_shared<EmbeddedNamespaceValue>(new Configuration()));
systemNS->SetAttribute("Configuration", new EmbeddedNamespaceValue(new Configuration()));
auto typesNSBehavior = new ConstNamespaceBehavior();
typesNSBehavior->Freeze();
Namespace::Ptr typesNS = new Namespace(typesNSBehavior);
globalNS->SetAttribute("Types", std::make_shared<ConstEmbeddedNamespaceValue>(typesNS));
globalNS->SetAttribute("Types", new ConstEmbeddedNamespaceValue(typesNS));
auto statsNSBehavior = new ConstNamespaceBehavior();
statsNSBehavior->Freeze();
Namespace::Ptr statsNS = new Namespace(statsNSBehavior);
globalNS->SetAttribute("StatsFunctions", std::make_shared<ConstEmbeddedNamespaceValue>(statsNS));
globalNS->SetAttribute("StatsFunctions", new ConstEmbeddedNamespaceValue(statsNS));
Namespace::Ptr internalNS = new Namespace(l_InternalNSBehavior);
globalNS->SetAttribute("Internal", std::make_shared<ConstEmbeddedNamespaceValue>(internalNS));
globalNS->SetAttribute("Internal", new ConstEmbeddedNamespaceValue(internalNS));
}, 1000);
INITIALIZE_ONCE_WITH_PRIORITY([]() {

View File

@ -65,7 +65,7 @@ void ScriptGlobal::Set(const String& name, const Value& value, bool overrideFroz
void ScriptGlobal::SetConst(const String& name, const Value& value)
{
GetGlobals()->SetAttribute(name, std::make_shared<ConstEmbeddedNamespaceValue>(value));
GetGlobals()->SetAttribute(name, new ConstEmbeddedNamespaceValue(value));
}
bool ScriptGlobal::Exists(const String& name)

View File

@ -0,0 +1,73 @@
/* Icinga 2 | (c) 2019 Icinga GmbH | GPLv2+ */
#ifndef SHARED_OBJECT_H
#define SHARED_OBJECT_H
#include "base/atomic.hpp"
#include "base/object.hpp"
#include <cstdint>
namespace icinga
{
class SharedObject;
inline void intrusive_ptr_add_ref(SharedObject *object);
inline void intrusive_ptr_release(SharedObject *object);
/**
* Seemless and polymorphistic base for any class to create shared pointers of.
* Saves a memory allocation compared to std::shared_ptr.
*
* @ingroup base
*/
class SharedObject
{
friend void intrusive_ptr_add_ref(SharedObject *object);
friend void intrusive_ptr_release(SharedObject *object);
protected:
inline SharedObject() : m_References(0)
{
}
inline SharedObject(const SharedObject&) : SharedObject()
{
}
inline SharedObject(SharedObject&&) : SharedObject()
{
}
inline SharedObject& operator=(const SharedObject&)
{
return *this;
}
inline SharedObject& operator=(SharedObject&&)
{
return *this;
}
inline virtual
~SharedObject() = default;
private:
Atomic<uint_fast64_t> m_References;
};
inline void intrusive_ptr_add_ref(SharedObject *object)
{
object->m_References.fetch_add(1);
}
inline void intrusive_ptr_release(SharedObject *object)
{
if (object->m_References.fetch_sub(1) == 1u) {
delete object;
}
}
}
#endif /* SHARED_OBJECT_H */

View File

@ -9,8 +9,8 @@ using namespace icinga;
ApplyRule::RuleMap ApplyRule::m_Rules;
ApplyRule::TypeMap ApplyRule::m_Types;
ApplyRule::ApplyRule(String targetType, String name, std::shared_ptr<Expression> expression,
std::shared_ptr<Expression> filter, String package, String fkvar, String fvvar, std::shared_ptr<Expression> fterm,
ApplyRule::ApplyRule(String targetType, String name, Expression::Ptr expression,
Expression::Ptr filter, String package, String fkvar, String fvvar, Expression::Ptr fterm,
bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope)
: m_TargetType(std::move(targetType)), m_Name(std::move(name)), m_Expression(std::move(expression)), m_Filter(std::move(filter)), m_Package(std::move(package)), m_FKVar(std::move(fkvar)),
m_FVVar(std::move(fvvar)), m_FTerm(std::move(fterm)), m_IgnoreOnError(ignoreOnError), m_DebugInfo(std::move(di)), m_Scope(std::move(scope)), m_HasMatches(false)
@ -26,12 +26,12 @@ String ApplyRule::GetName() const
return m_Name;
}
std::shared_ptr<Expression> ApplyRule::GetExpression() const
Expression::Ptr ApplyRule::GetExpression() const
{
return m_Expression;
}
std::shared_ptr<Expression> ApplyRule::GetFilter() const
Expression::Ptr ApplyRule::GetFilter() const
{
return m_Filter;
}
@ -51,7 +51,7 @@ String ApplyRule::GetFVVar() const
return m_FVVar;
}
std::shared_ptr<Expression> ApplyRule::GetFTerm() const
Expression::Ptr ApplyRule::GetFTerm() const
{
return m_FTerm;
}
@ -72,8 +72,8 @@ Dictionary::Ptr ApplyRule::GetScope() const
}
void ApplyRule::AddRule(const String& sourceType, const String& targetType, const String& name,
const std::shared_ptr<Expression>& expression, const std::shared_ptr<Expression>& filter, const String& package, const String& fkvar,
const String& fvvar, const std::shared_ptr<Expression>& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope)
const Expression::Ptr& expression, const Expression::Ptr& filter, const String& package, const String& fkvar,
const String& fvvar, const Expression::Ptr& fterm, bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope)
{
m_Rules[sourceType].push_back(ApplyRule(targetType, name, expression, filter, package, fkvar, fvvar, fterm, ignoreOnError, di, scope));
}

View File

@ -21,12 +21,12 @@ public:
String GetTargetType() const;
String GetName() const;
std::shared_ptr<Expression> GetExpression() const;
std::shared_ptr<Expression> GetFilter() const;
Expression::Ptr GetExpression() const;
Expression::Ptr GetFilter() const;
String GetPackage() const;
String GetFKVar() const;
String GetFVVar() const;
std::shared_ptr<Expression> GetFTerm() const;
Expression::Ptr GetFTerm() const;
bool GetIgnoreOnError() const;
DebugInfo GetDebugInfo() const;
Dictionary::Ptr GetScope() const;
@ -35,8 +35,8 @@ public:
bool EvaluateFilter(ScriptFrame& frame) const;
static void AddRule(const String& sourceType, const String& targetType, const String& name, const std::shared_ptr<Expression>& expression,
const std::shared_ptr<Expression>& filter, const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr<Expression>& fterm,
static void AddRule(const String& sourceType, const String& targetType, const String& name, const Expression::Ptr& expression,
const Expression::Ptr& filter, const String& package, const String& fkvar, const String& fvvar, const Expression::Ptr& fterm,
bool ignoreOnError, const DebugInfo& di, const Dictionary::Ptr& scope);
static std::vector<ApplyRule>& GetRules(const String& type);
@ -50,12 +50,12 @@ public:
private:
String m_TargetType;
String m_Name;
std::shared_ptr<Expression> m_Expression;
std::shared_ptr<Expression> m_Filter;
Expression::Ptr m_Expression;
Expression::Ptr m_Filter;
String m_Package;
String m_FKVar;
String m_FVVar;
std::shared_ptr<Expression> m_FTerm;
Expression::Ptr m_FTerm;
bool m_IgnoreOnError;
DebugInfo m_DebugInfo;
Dictionary::Ptr m_Scope;
@ -64,8 +64,8 @@ private:
static TypeMap m_Types;
static RuleMap m_Rules;
ApplyRule(String targetType, String name, std::shared_ptr<Expression> expression,
std::shared_ptr<Expression> filter, String package, String fkvar, String fvvar, std::shared_ptr<Expression> fterm,
ApplyRule(String targetType, String name, Expression::Ptr expression,
Expression::Ptr filter, String package, String fkvar, String fvvar, Expression::Ptr fterm,
bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope);
};

View File

@ -596,7 +596,7 @@ lterm: T_LIBRARY rterm
}
| T_USING rterm
{
std::shared_ptr<Expression> expr{$2};
Expression::Ptr expr{$2};
context->AddImport(expr);
$$ = MakeLiteralRaw();
}

View File

@ -345,12 +345,12 @@ bool ConfigCompiler::IsAbsolutePath(const String& path)
#endif /* _WIN32 */
}
void ConfigCompiler::AddImport(const std::shared_ptr<Expression>& import)
void ConfigCompiler::AddImport(const Expression::Ptr& import)
{
m_Imports.push_back(import);
}
std::vector<std::shared_ptr<Expression> > ConfigCompiler::GetImports() const
std::vector<Expression::Ptr> ConfigCompiler::GetImports() const
{
return m_Imports;
}

View File

@ -92,8 +92,8 @@ public:
void SetPackage(const String& package);
String GetPackage() const;
void AddImport(const std::shared_ptr<Expression>& import);
std::vector<std::shared_ptr<Expression> > GetImports() const;
void AddImport(const Expression::Ptr& import);
std::vector<Expression::Ptr> GetImports() const;
static void CollectIncludes(std::vector<std::unique_ptr<Expression> >& expressions,
const String& file, const String& zone, const String& package);
@ -114,13 +114,13 @@ public:
static bool HasZoneConfigAuthority(const String& zoneName);
private:
std::promise<std::shared_ptr<Expression> > m_Promise;
std::promise<Expression::Ptr> m_Promise;
String m_Path;
std::istream *m_Input;
String m_Zone;
String m_Package;
std::vector<std::shared_ptr<Expression> > m_Imports;
std::vector<Expression::Ptr> m_Imports;
void *m_Scanner;

View File

@ -47,8 +47,8 @@ REGISTER_FUNCTION(Internal, run_with_activation_context, &ConfigItem::RunWithAct
* @param debuginfo Debug information.
*/
ConfigItem::ConfigItem(Type::Ptr type, String name,
bool abstract, std::shared_ptr<Expression> exprl,
std::shared_ptr<Expression> filter, bool defaultTmpl, bool ignoreOnError,
bool abstract, Expression::Ptr exprl,
Expression::Ptr filter, bool defaultTmpl, bool ignoreOnError,
DebugInfo debuginfo, Dictionary::Ptr scope,
String zone, String package)
: m_Type(std::move(type)), m_Name(std::move(name)), m_Abstract(abstract),
@ -124,7 +124,7 @@ ConfigObject::Ptr ConfigItem::GetObject() const
*
* @returns The expression list.
*/
std::shared_ptr<Expression> ConfigItem::GetExpression() const
Expression::Ptr ConfigItem::GetExpression() const
{
return m_Expression;
}
@ -134,7 +134,7 @@ std::shared_ptr<Expression> ConfigItem::GetExpression() const
*
* @returns The filter expression.
*/
std::shared_ptr<Expression> ConfigItem::GetFilter() const
Expression::Ptr ConfigItem::GetFilter() const
{
return m_Filter;
}

View File

@ -24,8 +24,8 @@ public:
DECLARE_PTR_TYPEDEFS(ConfigItem);
ConfigItem(Type::Ptr type, String name, bool abstract,
std::shared_ptr<Expression> exprl,
std::shared_ptr<Expression> filter,
Expression::Ptr exprl,
Expression::Ptr filter,
bool defaultTmpl, bool ignoreOnError, DebugInfo debuginfo,
Dictionary::Ptr scope, String zone,
String package);
@ -38,8 +38,8 @@ public:
std::vector<ConfigItem::Ptr> GetParents() const;
std::shared_ptr<Expression> GetExpression() const;
std::shared_ptr<Expression> GetFilter() const;
Expression::Ptr GetExpression() const;
Expression::Ptr GetFilter() const;
void Register();
void Unregister();
@ -68,8 +68,8 @@ private:
String m_Name; /**< The name. */
bool m_Abstract; /**< Whether this is a template. */
std::shared_ptr<Expression> m_Expression;
std::shared_ptr<Expression> m_Filter;
Expression::Ptr m_Expression;
Expression::Ptr m_Filter;
bool m_DefaultTmpl;
bool m_IgnoreOnError;
DebugInfo m_DebugInfo; /**< Debug information. */

View File

@ -48,7 +48,7 @@ void ConfigItemBuilder::AddExpression(Expression *expr)
m_Expressions.emplace_back(expr);
}
void ConfigItemBuilder::SetFilter(const std::shared_ptr<Expression>& filter)
void ConfigItemBuilder::SetFilter(const Expression::Ptr& filter)
{
m_Filter = filter;
}
@ -111,7 +111,7 @@ ConfigItem::Ptr ConfigItemBuilder::Compile()
dexpr->MakeInline();
exprs.emplace_back(dexpr);
std::shared_ptr<DictExpression> exprl = std::make_shared<DictExpression>(std::move(exprs), m_DebugInfo);
auto exprl = new DictExpression(std::move(exprs), m_DebugInfo);
exprl->MakeInline();
return new ConfigItem(m_Type, m_Name, m_Abstract, exprl, m_Filter,

View File

@ -35,7 +35,7 @@ public:
void SetIgnoreOnError(bool ignoreOnError);
void AddExpression(Expression *expr);
void SetFilter(const std::shared_ptr<Expression>& filter);
void SetFilter(const Expression::Ptr& filter);
ConfigItem::Ptr Compile();
@ -44,7 +44,7 @@ private:
String m_Name; /**< The name. */
bool m_Abstract{false}; /**< Whether the item is abstract. */
std::vector<std::unique_ptr<Expression> > m_Expressions; /**< Expressions for this item. */
std::shared_ptr<Expression> m_Filter; /**< Filter expression. */
Expression::Ptr m_Filter; /**< Filter expression. */
DebugInfo m_DebugInfo; /**< Debug information. */
Dictionary::Ptr m_Scope; /**< variable scope. */
String m_Zone; /**< The zone. */

View File

@ -100,13 +100,13 @@ const DebugInfo& DebuggableExpression::GetDebugInfo() const
return m_DebugInfo;
}
VariableExpression::VariableExpression(String variable, std::vector<std::shared_ptr<Expression> > imports, const DebugInfo& debugInfo)
VariableExpression::VariableExpression(String variable, std::vector<Expression::Ptr> imports, const DebugInfo& debugInfo)
: DebuggableExpression(debugInfo), m_Variable(std::move(variable)), m_Imports(std::move(imports))
{
m_Imports.push_back(MakeIndexer(ScopeGlobal, "System"));
m_Imports.push_back(std::unique_ptr<Expression>(new IndexerExpression(MakeIndexer(ScopeGlobal, "System"), MakeLiteral("Configuration"))));
m_Imports.push_back(MakeIndexer(ScopeGlobal, "Types"));
m_Imports.push_back(MakeIndexer(ScopeGlobal, "Icinga"));
m_Imports.push_back(MakeIndexer(ScopeGlobal, "System").release());
m_Imports.push_back(new IndexerExpression(MakeIndexer(ScopeGlobal, "System"), MakeLiteral("Configuration")));
m_Imports.push_back(MakeIndexer(ScopeGlobal, "Types").release());
m_Imports.push_back(MakeIndexer(ScopeGlobal, "Icinga").release());
}
ExpressionResult VariableExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const
@ -689,7 +689,7 @@ ExpressionResult SetConstExpression::DoEvaluate(ScriptFrame& frame, DebugHint *d
CHECK_RESULT(operandres);
Value operand = operandres.GetValue();
globals->SetAttribute(m_Name, std::make_shared<ConstEmbeddedNamespaceValue>(operand));
globals->SetAttribute(m_Name, new ConstEmbeddedNamespaceValue(operand));
return Empty;
}

View File

@ -10,6 +10,7 @@
#include "base/function.hpp"
#include "base/exception.hpp"
#include "base/scriptframe.hpp"
#include "base/shared-object.hpp"
#include "base/convert.hpp"
#include <map>
@ -178,9 +179,11 @@ private:
/**
* @ingroup config
*/
class Expression
class Expression : public SharedObject
{
public:
DECLARE_PTR_TYPEDEFS(Expression);
Expression() = default;
Expression(const Expression&) = delete;
virtual ~Expression();
@ -203,7 +206,7 @@ std::unique_ptr<Expression> MakeIndexer(ScopeSpecifier scopeSpec, const String&
class OwnedExpression final : public Expression
{
public:
OwnedExpression(std::shared_ptr<Expression> expression)
OwnedExpression(Expression::Ptr expression)
: m_Expression(std::move(expression))
{ }
@ -219,7 +222,7 @@ protected:
}
private:
std::shared_ptr<Expression> m_Expression;
Expression::Ptr m_Expression;
};
class LiteralExpression final : public Expression
@ -288,7 +291,7 @@ protected:
class VariableExpression final : public DebuggableExpression
{
public:
VariableExpression(String variable, std::vector<std::shared_ptr<Expression> > imports, const DebugInfo& debugInfo = DebugInfo());
VariableExpression(String variable, std::vector<Expression::Ptr> imports, const DebugInfo& debugInfo = DebugInfo());
String GetVariable() const
{
@ -301,7 +304,7 @@ protected:
private:
String m_Variable;
std::vector<std::shared_ptr<Expression> > m_Imports;
std::vector<Expression::Ptr> m_Imports;
friend void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
};
@ -795,7 +798,7 @@ class FunctionExpression final : public DebuggableExpression
public:
FunctionExpression(String name, std::vector<String> args,
std::map<String, std::unique_ptr<Expression> >&& closedVars, std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Name(std::move(name)), m_Args(std::move(args)), m_ClosedVars(std::move(closedVars)), m_Expression(std::move(expression))
: DebuggableExpression(debugInfo), m_Name(std::move(name)), m_Args(std::move(args)), m_ClosedVars(std::move(closedVars)), m_Expression(expression.release())
{ }
protected:
@ -805,7 +808,7 @@ private:
String m_Name;
std::vector<String> m_Args;
std::map<String, std::unique_ptr<Expression> > m_ClosedVars;
std::shared_ptr<Expression> m_Expression;
Expression::Ptr m_Expression;
};
class ApplyExpression final : public DebuggableExpression
@ -816,9 +819,9 @@ public:
std::unique_ptr<Expression> fterm, std::map<String, std::unique_ptr<Expression> >&& closedVars, bool ignoreOnError,
std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Type(std::move(type)), m_Target(std::move(target)),
m_Name(std::move(name)), m_Filter(std::move(filter)), m_Package(std::move(package)), m_FKVar(std::move(fkvar)), m_FVVar(std::move(fvvar)),
m_FTerm(std::move(fterm)), m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)),
m_Expression(std::move(expression))
m_Name(std::move(name)), m_Filter(filter.release()), m_Package(std::move(package)), m_FKVar(std::move(fkvar)), m_FVVar(std::move(fvvar)),
m_FTerm(fterm.release()), m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)),
m_Expression(expression.release())
{ }
protected:
@ -828,28 +831,28 @@ private:
String m_Type;
String m_Target;
std::unique_ptr<Expression> m_Name;
std::shared_ptr<Expression> m_Filter;
Expression::Ptr m_Filter;
String m_Package;
String m_FKVar;
String m_FVVar;
std::shared_ptr<Expression> m_FTerm;
Expression::Ptr m_FTerm;
bool m_IgnoreOnError;
std::map<String, std::unique_ptr<Expression> > m_ClosedVars;
std::shared_ptr<Expression> m_Expression;
Expression::Ptr m_Expression;
};
class NamespaceExpression final : public DebuggableExpression
{
public:
NamespaceExpression(std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Expression(std::move(expression))
: DebuggableExpression(debugInfo), m_Expression(expression.release())
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
std::shared_ptr<Expression> m_Expression;
Expression::Ptr m_Expression;
};
class ObjectExpression final : public DebuggableExpression
@ -859,8 +862,8 @@ public:
String zone, String package, std::map<String, std::unique_ptr<Expression> >&& closedVars,
bool defaultTmpl, bool ignoreOnError, std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Abstract(abstract), m_Type(std::move(type)),
m_Name(std::move(name)), m_Filter(std::move(filter)), m_Zone(std::move(zone)), m_Package(std::move(package)), m_DefaultTmpl(defaultTmpl),
m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)), m_Expression(std::move(expression))
m_Name(std::move(name)), m_Filter(filter.release()), m_Zone(std::move(zone)), m_Package(std::move(package)), m_DefaultTmpl(defaultTmpl),
m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)), m_Expression(expression.release())
{ }
protected:
@ -870,13 +873,13 @@ private:
bool m_Abstract;
std::unique_ptr<Expression> m_Type;
std::unique_ptr<Expression> m_Name;
std::shared_ptr<Expression> m_Filter;
Expression::Ptr m_Filter;
String m_Zone;
String m_Package;
bool m_DefaultTmpl;
bool m_IgnoreOnError;
std::map<String, std::unique_ptr<Expression> > m_ClosedVars;
std::shared_ptr<Expression> m_Expression;
Expression::Ptr m_Expression;
};
class ForExpression final : public DebuggableExpression

View File

@ -26,7 +26,7 @@ namespace icinga
class VMOps
{
public:
static inline bool FindVarImportRef(ScriptFrame& frame, const std::vector<std::shared_ptr<Expression> >& imports, const String& name, Value *result, const DebugInfo& debugInfo = DebugInfo())
static inline bool FindVarImportRef(ScriptFrame& frame, const std::vector<Expression::Ptr>& imports, const String& name, Value *result, const DebugInfo& debugInfo = DebugInfo())
{
for (const auto& import : imports) {
ExpressionResult res = import->Evaluate(frame);
@ -40,7 +40,7 @@ public:
return false;
}
static inline bool FindVarImport(ScriptFrame& frame, const std::vector<std::shared_ptr<Expression> >& imports, const String& name, Value *result, const DebugInfo& debugInfo = DebugInfo())
static inline bool FindVarImport(ScriptFrame& frame, const std::vector<Expression::Ptr>& imports, const String& name, Value *result, const DebugInfo& debugInfo = DebugInfo())
{
Value parent;
@ -91,7 +91,7 @@ public:
}
static inline Value NewFunction(ScriptFrame& frame, const String& name, const std::vector<String>& argNames,
const std::map<String, std::unique_ptr<Expression> >& closedVars, const std::shared_ptr<Expression>& expression)
const std::map<String, std::unique_ptr<Expression> >& closedVars, const Expression::Ptr& expression)
{
auto evaluatedClosedVars = EvaluateClosedVars(frame, closedVars);
@ -115,9 +115,9 @@ public:
return new Function(name, wrapper, argNames);
}
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const std::shared_ptr<Expression>& filter,
const String& package, const String& fkvar, const String& fvvar, const std::shared_ptr<Expression>& fterm, const std::map<String, std::unique_ptr<Expression> >& closedVars,
bool ignoreOnError, const std::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
static inline Value NewApply(ScriptFrame& frame, const String& type, const String& target, const String& name, const Expression::Ptr& filter,
const String& package, const String& fkvar, const String& fvvar, const Expression::Ptr& fterm, const std::map<String, std::unique_ptr<Expression> >& closedVars,
bool ignoreOnError, const Expression::Ptr& expression, const DebugInfo& debugInfo = DebugInfo())
{
ApplyRule::AddRule(type, target, name, expression, filter, package, fkvar,
fvvar, fterm, ignoreOnError, debugInfo, EvaluateClosedVars(frame, closedVars));
@ -125,8 +125,8 @@ public:
return Empty;
}
static inline Value NewObject(ScriptFrame& frame, bool abstract, const Type::Ptr& type, const String& name, const std::shared_ptr<Expression>& filter,
const String& zone, const String& package, bool defaultTmpl, bool ignoreOnError, const std::map<String, std::unique_ptr<Expression> >& closedVars, const std::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
static inline Value NewObject(ScriptFrame& frame, bool abstract, const Type::Ptr& type, const String& name, const Expression::Ptr& filter,
const String& zone, const String& package, bool defaultTmpl, bool ignoreOnError, const std::map<String, std::unique_ptr<Expression> >& closedVars, const Expression::Ptr& expression, const DebugInfo& debugInfo = DebugInfo())
{
ConfigItemBuilder item{debugInfo};

View File

@ -60,7 +60,7 @@ void IcingaApplication::StaticInitialize()
auto icingaNSBehavior = new ConstNamespaceBehavior();
icingaNSBehavior->Freeze();
Namespace::Ptr icingaNS = new Namespace(icingaNSBehavior);
globalNS->SetAttribute("Icinga", std::make_shared<ConstEmbeddedNamespaceValue>(icingaNS));
globalNS->SetAttribute("Icinga", new ConstEmbeddedNamespaceValue(icingaNS));
}
REGISTER_STATSFUNCTION(IcingaApplication, &IcingaApplication::StatsFunc);

View File

@ -126,7 +126,7 @@ EventQueueRegistry *EventQueueRegistry::GetInstance()
}
std::mutex EventsInbox::m_FiltersMutex;
std::map<String, EventsInbox::Filter> EventsInbox::m_Filters ({{"", EventsInbox::Filter{1, nullptr}}});
std::map<String, EventsInbox::Filter> EventsInbox::m_Filters ({{"", EventsInbox::Filter{1, Expression::Ptr()}}});
EventsRouter EventsRouter::m_Instance;
@ -146,7 +146,7 @@ EventsInbox::EventsInbox(String filter, const String& filterSource)
m_Filter = m_Filters.find(filter);
if (m_Filter == m_Filters.end()) {
m_Filter = m_Filters.emplace(std::move(filter), Filter{1, std::shared_ptr<Expression>(expr.release())}).first;
m_Filter = m_Filters.emplace(std::move(filter), Filter{1, Expression::Ptr(expr.release())}).first;
} else {
++m_Filter->second.Refs;
}
@ -164,7 +164,7 @@ EventsInbox::~EventsInbox()
}
}
const std::shared_ptr<Expression>& EventsInbox::GetFilter()
const Expression::Ptr& EventsInbox::GetFilter()
{
return m_Filter->second.Expr;
}
@ -230,7 +230,7 @@ const EventsInbox::Ptr& EventsSubscriber::GetInbox()
return m_Inbox;
}
EventsFilter::EventsFilter(std::map<std::shared_ptr<Expression>, std::set<EventsInbox::Ptr>> inboxes)
EventsFilter::EventsFilter(std::map<Expression::Ptr, std::set<EventsInbox::Ptr>> inboxes)
: m_Inboxes(std::move(inboxes))
{
}

View File

@ -94,7 +94,7 @@ public:
EventsInbox& operator=(EventsInbox&&) = delete;
~EventsInbox();
const std::shared_ptr<Expression>& GetFilter();
const Expression::Ptr& GetFilter();
void Push(Dictionary::Ptr event);
Dictionary::Ptr Shift(boost::asio::yield_context yc, double timeout = 5);
@ -103,7 +103,7 @@ private:
struct Filter
{
std::size_t Refs;
std::shared_ptr<Expression> Expr;
Expression::Ptr Expr;
};
static std::mutex m_FiltersMutex;
@ -135,14 +135,14 @@ private:
class EventsFilter
{
public:
EventsFilter(std::map<std::shared_ptr<Expression>, std::set<EventsInbox::Ptr>> inboxes);
EventsFilter(std::map<Expression::Ptr, std::set<EventsInbox::Ptr>> inboxes);
operator bool();
void Push(Dictionary::Ptr event);
private:
std::map<std::shared_ptr<Expression>, std::set<EventsInbox::Ptr>> m_Inboxes;
std::map<Expression::Ptr, std::set<EventsInbox::Ptr>> m_Inboxes;
};
class EventsRouter
@ -165,7 +165,7 @@ private:
~EventsRouter() = default;
std::mutex m_Mutex;
std::map<EventType, std::map<std::shared_ptr<Expression>, std::set<EventsInbox::Ptr>>> m_Subscribers;
std::map<EventType, std::map<Expression::Ptr, std::set<EventsInbox::Ptr>>> m_Subscribers;
};
}