From 01ce9e24cc5953f44a7dd9a3d93347835e26030d Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 21 Dec 2014 23:52:51 +0100 Subject: fixed crash bug in TestDomain -- if a class has an Owned handle the owner must point to the managed object directly responsible for the lifetime of this handle. Fixed this by making AttributeDescriptor a managed class (though this is not an optimal solution) and using a ManagedVector --- src/core/model/Domain.hpp | 4 ++-- src/core/model/Typesystem.hpp | 31 +++++++++++++++++-------------- test/core/model/TestDomain.hpp | 3 ++- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 99ac6e1..31786c1 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -400,9 +400,9 @@ public: */ StructuredClass(Manager &mgr, std::string name, Handle domain, const Cardinality &cardinality, - Handle attributesDescriptor = {nullptr}, + Handle attributesDescriptor = nullptr, // TODO: What would be a wise default value for isa? - Handle isa = {nullptr}, + Handle isa = nullptr, bool transparent = false, bool root = false) : Descriptor(mgr, std::move(name), domain, attributesDescriptor), diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index c9793e2..3832a0f 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -306,18 +306,21 @@ public: class StructType : public Type { public: - struct AttributeDescriptor { + class AttributeDescriptor : public Managed { + public: const std::string name; const Variant defaultValue; const bool optional; const Owned type; - AttributeDescriptor(std::string name, Variant defaultValue, - bool optional, Owned type) - : name(name), + AttributeDescriptor(Manager &mgr, std::string name, + Variant defaultValue, bool optional, + Handle type) + : Managed(mgr), + name(name), defaultValue(defaultValue), optional(optional), - type(type) + type(acquire(type)) { } }; @@ -332,7 +335,7 @@ protected: if (var.isArray()) { auto arr = var.asArray(); for (size_t a = 0; a < attrs.size(); a++) { - if (!attrs[a].type->build(arr[a], logger)) { + if (!attrs[a]->type->build(arr[a], logger)) { return false; } } @@ -345,13 +348,13 @@ protected: auto &map = var.asMap(); // We transform the map into an array with the correct values at the // correct places. - std::vector vec; + Variant::arrayType vec; for (auto &a : attrs) { - auto it = map.find(a.name); + auto it = map.find(a->name); // we use the default if nothing is set. - if (it == map.end() || !a.type->build(it->second, logger)) { - logger.note(std::string("Using default value for ") + a.name); - vec.push_back(a.defaultValue); + if (it == map.end() || !a->type->build(it->second, logger)) { + logger.note(std::string("Using default value for ") + a->name); + vec.push_back(a->defaultValue); } else { vec.push_back(it->second); } @@ -361,11 +364,11 @@ protected: } public: - std::vector attrs; + const ManagedVector attrs; StructType(Manager &mgr, std::string name, Handle system, - std::vector attrs) - : Type(mgr, std::move(name), system, false), attrs(std::move(attrs)) + ManagedVector attrs) + : Type(mgr, std::move(name), system, false), attrs(this, std::move(attrs)) { } // TODO diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp index dd58524..d4421a4 100644 --- a/test/core/model/TestDomain.hpp +++ b/test/core/model/TestDomain.hpp @@ -36,7 +36,8 @@ static Rooted constructTypeSystem(Manager &mgr) Rooted string{new StringType(mgr, sys)}; sys->addType(string); Rooted string_struct{new StructType( - mgr, "text", sys, {{"content", "", false, sys->acquire(string)}})}; + mgr, "text", sys, {new StructType::AttributeDescriptor( + mgr, "content", "", false, string)})}; sys->addType(string_struct); return sys; -- cgit v1.2.3