diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2019-07-26 16:17:53 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2019-08-10 22:04:11 +0200 |
commit | b7d073e9905bf9812ba96cecdcf6871a95517d30 (patch) | |
tree | ab48181deddd93f40cff5e908f243c44efc359c5 /tests/auto/corelib | |
parent | e75aed1a96e626f079af307c5604ddf9054ecafc (diff) | |
download | qtbase-b7d073e9905bf9812ba96cecdcf6871a95517d30.tar.gz |
Refactor memory allocation for arguments of QMetaCallEvents
There are two cases:
In a BlockingQueuedConnection, QMetaCallEvent doesn't allocate memory
and instead passes already existing pointers through. A QSemaphore
is used to serialize data access between threads. So the constructor
taking a QSemaphore can be simplified to only accept an existing arg
array.
In a QueuedConnection, QMetaCallEvent needs to make deep copies of
the arguments, and memory needs to be allocated based on the number
of arguments. The previous code put the burden of memory allocation
on the code generating the event, while the memory was free'd by
~QMetaCallEvent. Instead, make it QMetaCallEvent's responsibility
to allocate and free the memory as needed, and adjust the code
generating QMetaCallEvents.
We can allocate the memory for types and pointers to arguments in a
single block, starting with the space for the array of void*, followed
by the space for the array of integers to avoid byte alignment issues.
By pre-allocating the space that's needed by three arguments, we can
avoid all mallocs for the majority of QMetaCallEvents.
Until this change has propagated through qt5.git, we need to keep the
old API that is still used by QtDeclarative around. Once QtDeclarative
has migrated to the new API, it can be removed.
Change-Id: Id7359ffc14897237ea9672dabae9ef199a821907
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 026c6a6324..60000316cc 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -507,6 +507,7 @@ public slots: { QObject::moveToThread(t); } void slotWithUnregisteredParameterType(MyUnregisteredType); + void slotWithOneUnregisteredParameterType(QString a1, MyUnregisteredType a2); CountedStruct throwingSlot(const CountedStruct &, CountedStruct s2) { #ifndef QT_NO_EXCEPTIONS @@ -604,6 +605,9 @@ void QtTestObject::testSender() void QtTestObject::slotWithUnregisteredParameterType(MyUnregisteredType) { slotResult = "slotWithUnregisteredReturnType"; } +void QtTestObject::slotWithOneUnregisteredParameterType(QString a1, MyUnregisteredType) +{ slotResult = "slotWithUnregisteredReturnType-" + a1; } + void QtTestObject::staticFunction0() { staticResult = "staticFunction0"; @@ -885,6 +889,16 @@ void tst_QMetaObject::invokeQueuedMetaMember() QVERIFY(!QMetaObject::invokeMethod(&obj, "slotWithUnregisteredParameterType", Qt::QueuedConnection, Q_ARG(MyUnregisteredType, t))); QVERIFY(obj.slotResult.isEmpty()); } + + obj.slotResult.clear(); + { + QString a1("Cannot happen"); + MyUnregisteredType t; + QTest::ignoreMessage(QtWarningMsg, "QMetaMethod::invoke: Unable to handle unregistered datatype 'MyUnregisteredType'"); + QVERIFY(!QMetaObject::invokeMethod(&obj, "slotWithOneUnregisteredParameterType", Qt::QueuedConnection, + Q_ARG(QString, a1), Q_ARG(MyUnregisteredType, t))); + QVERIFY(obj.slotResult.isEmpty()); + } } void tst_QMetaObject::invokeQueuedPointer() |