From 9b8493314dd77f3e96b353187816bb7ef4dedbb5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 21 Mar 2017 22:26:09 -0700 Subject: Qt6: Fix uninitialized meta objects on Windows Windows has a problem relating to cross-DLL variable relocations: they are not supported. Since QMetaObject's link to the parent class is done via a pointer, every QMetaObject in a DLL or in the EXE that derives from a class from another DLL (such as QObject) will be dynamically initialized. This commit changes the meta object pointers in QMetaObject::d from raw pointers to a wrapper class SuperData, which is almost entirely source- compatible with the pointer itself. On all systems except for Windows with Qt 6, it's binary compatible with the current implementation. But for Windows with Qt 6, this commit will store both the raw pointer and a pointer to a function that returns the QMetaObject, with one of them non-null only. For all meta objects constructed by moc, we store the function pointer, which allows the staticMetaObject to be statically intialized. For dynamic meta objects (QMetaObjectBuilder, QtDBus, QtQml, ActiveQt), we'll store the actual raw pointer. [ChangeLog][QtCore][QMetaObject] Some internal members of the QMetaObject class have changed types. Those members are not public API and thus should not cause source incompatibilities. The macro QT_NO_DATA_RELOCATION existed in Qt 4 but was called Q_NO_DATA_RELOCATION and only applied to Symbian. It was removed in commit 24a72c4efa929648d3afd95b3c269a95ecf46e57 ("qglobal: Remove symbian specific features"). Task-number: QTBUG-38876 Fixes: QTBUG-69963 Change-Id: Id92f4a61915b49ddaee6fffd14ae1cf615525e92 Reviewed-by: Simon Hausmann --- tests/auto/tools/moc/tst_moc.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tests/auto/tools/moc/tst_moc.cpp') diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index b88d929ca9..89f563f11d 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -1053,7 +1053,7 @@ void tst_Moc::testExtraDataForEnum() const QMetaObject *mobjUser = &EnumUserClass::staticMetaObject; QCOMPARE(mobjUser->enumeratorCount(), 0); - const QMetaObject * const *objects = mobjUser->d.relatedMetaObjects; + const auto *objects = mobjUser->d.relatedMetaObjects; QVERIFY(objects); QCOMPARE(objects[0], mobjSource); QVERIFY(!objects[1]); @@ -3579,10 +3579,9 @@ namespace QTBUG32933_relatedObjectsDontIncludeItself { void tst_Moc::QTBUG32933_relatedObjectsDontIncludeItself() { const QMetaObject *mo = &QTBUG32933_relatedObjectsDontIncludeItself::NS::Obj::staticMetaObject; - const QMetaObject * const *objects = mo->d.relatedMetaObjects; + const auto *objects = mo->d.relatedMetaObjects; // the related objects should be empty because the enums is in the same object. QVERIFY(!objects); - } class UnrelatedClass : public QObject @@ -3688,7 +3687,7 @@ void tst_Moc::relatedMetaObjectsNameConflict() // load all specified metaobjects int a set QSet dependency; - const QMetaObject *const *i = dependingObject->d.relatedMetaObjects; + const auto *i = dependingObject->d.relatedMetaObjects; while (*i) { dependency.insert(*i); ++i; -- cgit v1.2.3