aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlmetatype_p.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-08-24 14:52:30 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-08-28 13:49:14 +0200
commit229987d91505203e5a1577651b65880e58239ac7 (patch)
tree4a42a347a831824d2ffc8f8dee6a90a0dd7d0859 /src/qml/qml/qqmlmetatype_p.h
parent2afed94c70913e018198422ef222c9168326d09c (diff)
Do proper memory management on the metatype interfaces we create
Those interfaces are always registered in pairs. Add an external refcount to CompositeMetaTypeIds, and do registration and de-registration through this class. Change-Id: I4f3a53ad935a43a734d6506ffc768f507b48ee1f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype_p.h')
-rw-r--r--src/qml/qml/qqmlmetatype_p.h52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h
index 58968a1c26..b1fe58af6e 100644
--- a/src/qml/qml/qqmlmetatype_p.h
+++ b/src/qml/qml/qqmlmetatype_p.h
@@ -66,6 +66,52 @@ namespace QV4 { class ExecutableCompilationUnit; }
struct CompositeMetaTypeIds
{
+private:
+ int *refCount = nullptr;
+ void deref();
+ void ref()
+ {
+ Q_ASSERT(refCount);
+ ++*refCount;
+ }
+public:
+ CompositeMetaTypeIds() = default;
+ CompositeMetaTypeIds(QMetaType id, QMetaType listId) : id(id), listId(listId) {}
+ CompositeMetaTypeIds(const CompositeMetaTypeIds &other)
+ : refCount(other.refCount), id(other.id), listId(other.listId)
+ {
+ if (refCount)
+ ref();
+ }
+ CompositeMetaTypeIds(CompositeMetaTypeIds &&other)
+ : refCount(other.refCount), id(other.id), listId(other.listId)
+ {
+ other.refCount = nullptr;
+ }
+ CompositeMetaTypeIds &operator=(const CompositeMetaTypeIds &other)
+ {
+ if (refCount)
+ deref();
+ refCount = other.refCount;
+ id = other.id;
+ listId = other.listId;
+ if (refCount)
+ ref();
+ return *this;
+ }
+ CompositeMetaTypeIds &operator=(CompositeMetaTypeIds &&other)
+ {
+ if (refCount)
+ deref();
+ refCount = other.refCount;
+ id = other.id;
+ listId = other.listId;
+ other.refCount = nullptr;
+ return *this;
+ }
+ ~CompositeMetaTypeIds();
+ static CompositeMetaTypeIds fromCompositeName(const QByteArray &name);
+public:
QMetaType id;
QMetaType listId;
bool isValid() const { return id.isValid() && listId.isValid(); }
@@ -73,6 +119,10 @@ struct CompositeMetaTypeIds
class Q_QML_PRIVATE_EXPORT QQmlMetaType
{
+ friend struct CompositeMetaTypeIds;
+ static CompositeMetaTypeIds registerInternalCompositeType(const QByteArray &className);
+ static void unregisterInternalCompositeType(const CompositeMetaTypeIds &typeIds);
+
public:
enum class RegistrationResult {
Success,
@@ -94,8 +144,6 @@ public:
static void unregisterType(int type);
- static CompositeMetaTypeIds registerInternalCompositeType(const QByteArray &className);
- static void unregisterInternalCompositeType(const CompositeMetaTypeIds &typeIds);
static void registerModule(const char *uri, QTypeRevision version);
static bool protectModule(const QString &uri, QTypeRevision version,
bool protectAllVersions = false);