From 04ca634a16500b9b9e04ea6767b3ee2f752dd21f Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 8 Dec 2014 08:36:03 +0100 Subject: [PATCH] Fix typeof incorrectly returning null for arrays and dictionaries fixes #8002 --- lib/base/primitivetype.cpp | 4 +--- lib/base/primitivetype.hpp | 16 ++++++++++++---- lib/base/scriptfunction.cpp | 3 +++ lib/base/scriptfunction.hpp | 2 +- tools/mkclass/classcompiler.cpp | 5 ++++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/base/primitivetype.cpp b/lib/base/primitivetype.cpp index b47cc7f87..026cda6d5 100644 --- a/lib/base/primitivetype.cpp +++ b/lib/base/primitivetype.cpp @@ -21,9 +21,7 @@ using namespace icinga; -REGISTER_BUILTIN_TYPE(int); -REGISTER_BUILTIN_TYPE(double); -REGISTER_BUILTIN_TYPE(bool); +REGISTER_BUILTIN_TYPE(Number); PrimitiveType::PrimitiveType(const String& name) : m_Name(name) diff --git a/lib/base/primitivetype.hpp b/lib/base/primitivetype.hpp index 02e52ecbe..0a7226e7d 100644 --- a/lib/base/primitivetype.hpp +++ b/lib/base/primitivetype.hpp @@ -48,16 +48,24 @@ private: #define REGISTER_BUILTIN_TYPE(type) \ namespace { namespace UNIQUE_NAME(prt) { namespace prt ## type { \ - void RegisterPrimitiveType(void) \ + void RegisterBuiltinType(void) \ { \ icinga::Type::Ptr t = new PrimitiveType(#type); \ icinga::Type::Register(t); \ } \ - INITIALIZE_ONCE(RegisterPrimitiveType); \ + INITIALIZE_ONCE(RegisterBuiltinType); \ } } } -#define REGISTER_PRIMITIVE_TYPE(type) \ - REGISTER_BUILTIN_TYPE(type); \ +#define REGISTER_PRIMITIVE_TYPE(type) \ + namespace { namespace UNIQUE_NAME(prt) { namespace prt ## type { \ + void RegisterPrimitiveType(void) \ + { \ + icinga::Type::Ptr t = new PrimitiveType(#type); \ + icinga::Type::Register(t); \ + type::TypeInstance = t; \ + } \ + INITIALIZE_ONCE(RegisterPrimitiveType); \ + } } } \ DEFINE_TYPE_INSTANCE(type) } diff --git a/lib/base/scriptfunction.cpp b/lib/base/scriptfunction.cpp index 52a20b919..2a21add14 100644 --- a/lib/base/scriptfunction.cpp +++ b/lib/base/scriptfunction.cpp @@ -19,9 +19,12 @@ #include "base/scriptfunction.hpp" #include "base/scriptvariable.hpp" +#include "base/primitivetype.hpp" using namespace icinga; +REGISTER_PRIMITIVE_TYPE(ScriptFunction); + ScriptFunction::ScriptFunction(const Callback& function) : m_Callback(function) { } diff --git a/lib/base/scriptfunction.hpp b/lib/base/scriptfunction.hpp index 442c9790c..78ef40aa7 100644 --- a/lib/base/scriptfunction.hpp +++ b/lib/base/scriptfunction.hpp @@ -37,7 +37,7 @@ namespace icinga class I2_BASE_API ScriptFunction : public Object { public: - DECLARE_PTR_TYPEDEFS(ScriptFunction); + DECLARE_OBJECT(ScriptFunction); typedef boost::function& arguments)> Callback; diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index e86c55269..bb3e6c924 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -299,11 +299,14 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { std::string ftype = it->Type; + if (ftype == "bool" || ftype == "int" || ftype == "double") + ftype = "Number"; + if (ftype.find("::Ptr") != std::string::npos) ftype = ftype.substr(0, ftype.size() - strlen("::Ptr")); if (it->Attributes & FAEnum) - ftype = "int"; + ftype = "Number"; std::cout << "\t\t\t" << "case " << num << ":" << std::endl << "\t\t\t\t" << "return Field(" << num << ", \"" << ftype << "\", \"" << it->Name << "\", " << it->Attributes << ");" << std::endl; -- 2.40.0