QMetaType: support manual unregistration
QtDeclarative registers types in plugins, and supports un- and reloading those plugins. Those types would leave pointers to unmapped memory in the type registry on macOs, which would later cause crashes. We therefore add private API to manually remove the types from the registry, which can then be used in declarative. Lastly, as a precaution for re-registering the types, we reset QMetaTypeInterface::typeId to 0, as the memory is most likely not reset to 0 when reloading the plugin. Change-Id: Ic3fc08759f3d4481dca44a91b33baf3ea9e7198e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
2f2d870fdd
commit
cf000d080c
@ -669,6 +669,13 @@ void QtMetaTypePrivate::derefAndDestroy(QtPrivate::QMetaTypeInterface *d_ptr)
|
||||
}
|
||||
}
|
||||
|
||||
Q_CORE_EXPORT void QtMetaTypePrivate::unsafeUnregister(QtPrivate::QMetaTypeInterface *d_ptr)
|
||||
{
|
||||
if (auto reg = customTypeRegistery())
|
||||
reg->unregisterDynamicType(d_ptr->typeId.loadRelaxed());
|
||||
d_ptr->typeId = 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QMetaType::~QMetaType()
|
||||
|
||||
@ -1768,6 +1775,12 @@ QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QT_METATYPE_DECLARE_TEMPLATE_ITER)
|
||||
QT_FOR_EACH_STATIC_CORE_CLASS(QT_METATYPE_DECLARE_TEMPLATE_ITER)
|
||||
QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_DECLARE_TEMPLATE_ITER)
|
||||
QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_DECLARE_TEMPLATE_ITER)
|
||||
|
||||
Q_CORE_EXPORT QMetaTypeInterface *QMetaTypeInterface::get(const QMetaType &metatype)
|
||||
{
|
||||
return metatype.d_ptr;
|
||||
}
|
||||
|
||||
#undef QT_METATYPE_DECLARE_TEMPLATE_ITER
|
||||
#endif
|
||||
}
|
||||
|
@ -693,6 +693,7 @@ public:
|
||||
static void unregisterConverterFunction(int from, int to);
|
||||
private:
|
||||
friend class QVariant;
|
||||
friend class QtPrivate::QMetaTypeInterface;
|
||||
QtPrivate::QMetaTypeInterface *d_ptr = nullptr;
|
||||
};
|
||||
|
||||
@ -2278,6 +2279,8 @@ public:
|
||||
|
||||
using LegacyRegisterOp = void (*)();
|
||||
LegacyRegisterOp legacyRegisterOp;
|
||||
|
||||
Q_CORE_EXPORT static QMetaTypeInterface *get(const QMetaType &metatype);
|
||||
};
|
||||
|
||||
struct QTypeNormalizer
|
||||
|
@ -218,6 +218,7 @@ static QtPrivate::QMetaTypeInterface *getInterfaceFromType()
|
||||
return true;
|
||||
|
||||
void derefAndDestroy(QtPrivate::QMetaTypeInterface *d_ptr);
|
||||
Q_CORE_EXPORT void unsafeUnregister(QtPrivate::QMetaTypeInterface *d_ptr);
|
||||
|
||||
} //namespace QtMetaTypePrivate
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user