]> granicus.if.org Git - icinga2/commitdiff
Fix typeof incorrectly returning null for arrays and dictionaries
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 8 Dec 2014 07:36:03 +0000 (08:36 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 8 Dec 2014 07:36:03 +0000 (08:36 +0100)
fixes #8002

lib/base/primitivetype.cpp
lib/base/primitivetype.hpp
lib/base/scriptfunction.cpp
lib/base/scriptfunction.hpp
tools/mkclass/classcompiler.cpp

index b47cc7f87377876373c1d4ef4b78a031bbd45491..026cda6d5a21553b3f981e050225b8fe16fd3828 100644 (file)
@@ -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)
index 02e52ecbeffe6d7feb0596b6c80a43957bf98711..0a7226e7dec95da1ba7b180252cd10e158f087aa 100644 (file)
@@ -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)
 
 }
index 52a20b9195709e6f694c22ccaccd88dbdaf4f09e..2a21add14e06b3afcf35571184820834505cd955 100644 (file)
 
 #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)
 { }
index 442c9790ca3f44e1ae6ebabec67097cd8e929245..78ef40aa7b0e7905ae63c077ec229a75241b4de4 100644 (file)
@@ -37,7 +37,7 @@ namespace icinga
 class I2_BASE_API ScriptFunction : public Object
 {
 public:
-       DECLARE_PTR_TYPEDEFS(ScriptFunction);
+       DECLARE_OBJECT(ScriptFunction);
 
        typedef boost::function<Value (const std::vector<Value>& arguments)> Callback;
 
index e86c55269e2fbf94b75bbcbb18d7b4323a7a54e8..bb3e6c924d3b7ac7eaf03eb2828519522fd9731c 100644 (file)
@@ -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;