From c642f44448752972f89a121b125873f187e088b3 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 25 Jan 2019 17:10:14 +0100 Subject: Tooling: Use fprintf rather than qDebug() for debug warning This warning is generated from a statically called ctor. At that point the system facilities to run QMessageLogger may not be in place, yet. In addition, we actually don't want the message to go through the regular QMessageLogger redirection and possibly filtering. The message should always be shown. Fixes: QTBUG-73217 Change-Id: Ief192dae8c38d5d94996ee9285e54b5cbd714f4b Reviewed-by: Andy Shaw Reviewed-by: Simon Hausmann (cherry-picked from commit 15525d2a309a6028d548797bc777e38905f36c46) --- src/qml/debugger/qqmldebug.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qml/debugger/qqmldebug.cpp b/src/qml/debugger/qqmldebug.cpp index 6246fb4207..6532576e03 100644 --- a/src/qml/debugger/qqmldebug.cpp +++ b/src/qml/debugger/qqmldebug.cpp @@ -44,16 +44,16 @@ #include #include +#include + QT_REQUIRE_CONFIG(qml_debug); QT_BEGIN_NAMESPACE QQmlDebuggingEnabler::QQmlDebuggingEnabler(bool printWarning) { - if (!QQmlEnginePrivate::qml_debugging_enabled - && printWarning) { - qDebug("QML debugging is enabled. Only use this in a safe environment."); - } + if (!QQmlEnginePrivate::qml_debugging_enabled && printWarning) + fprintf(stderr, "QML debugging is enabled. Only use this in a safe environment.\n"); QQmlEnginePrivate::qml_debugging_enabled = true; } -- cgit v1.2.3 From 2cd99e2b69779c12309dd454584aa9546029323e Mon Sep 17 00:00:00 2001 From: Jeremy Powell Date: Thu, 18 Apr 2019 15:59:50 +1200 Subject: Fix memory leak with QQuickEventPoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Store PointVelocityData by value in the QMap to avoid leaking memory. This also appears to be slightly faster than heap allocation, with the struct being relatively small (24 or 32 bytes depending on qreal). Fixes: QTBUG-73182 Change-Id: Ibd9374746b76fd5b78c23283d278b6af42907c96 Reviewed-by: Shawn Rutledge Reviewed-by: Jan Arve Sæther --- src/quick/items/qquickevents.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp index c43eab6b8a..28b217b7b3 100644 --- a/src/quick/items/qquickevents.cpp +++ b/src/quick/items/qquickevents.cpp @@ -1135,10 +1135,10 @@ void QQuickEventTouchPoint::reset(const QTouchEvent::TouchPoint &tp, ulong times struct PointVelocityData { QVector2D velocity; QPointF pos; - ulong timestamp; + ulong timestamp = 0; }; -typedef QMap PointDataForPointIdMap; +typedef QMap PointDataForPointIdMap; Q_GLOBAL_STATIC(PointDataForPointIdMap, g_previousPointData) static const int PointVelocityAgeLimit = 500; // milliseconds @@ -1149,42 +1149,36 @@ static const int PointVelocityAgeLimit = 500; // milliseconds */ QVector2D QQuickEventPoint::estimatedVelocity() const { - PointVelocityData *prevPoint = g_previousPointData->value(m_pointId); - if (!prevPoint) { + auto prevPointIt = g_previousPointData->find(m_pointId); + auto end = g_previousPointData->end(); + if (prevPointIt == end) { // cleanup events older than PointVelocityAgeLimit - auto end = g_previousPointData->end(); for (auto it = g_previousPointData->begin(); it != end; ) { - PointVelocityData *data = it.value(); - if (m_timestamp - data->timestamp > PointVelocityAgeLimit) { + if (m_timestamp - it->timestamp > PointVelocityAgeLimit) it = g_previousPointData->erase(it); - delete data; - } else { + else ++it; - } } - // TODO optimize: stop this dynamic memory thrashing - prevPoint = new PointVelocityData; - prevPoint->velocity = QVector2D(); - prevPoint->timestamp = 0; - prevPoint->pos = QPointF(); - g_previousPointData->insert(m_pointId, prevPoint); + prevPointIt = g_previousPointData->insert(m_pointId, PointVelocityData()); } - const ulong timeElapsed = m_timestamp - prevPoint->timestamp; + + auto &prevPoint = prevPointIt.value(); + const ulong timeElapsed = m_timestamp - prevPoint.timestamp; if (timeElapsed == 0) // in case we call estimatedVelocity() twice on the same QQuickEventPoint return m_velocity; QVector2D newVelocity; - if (prevPoint->timestamp != 0) - newVelocity = QVector2D(m_scenePos - prevPoint->pos)/timeElapsed; + if (prevPoint.timestamp != 0) + newVelocity = QVector2D(m_scenePos - prevPoint.pos) / timeElapsed; // VERY simple kalman filter: does a weighted average // where the older velocities get less and less significant static const float KalmanGain = 0.7f; QVector2D filteredVelocity = newVelocity * KalmanGain + m_velocity * (1.0f - KalmanGain); - prevPoint->velocity = filteredVelocity; - prevPoint->pos = m_scenePos; - prevPoint->timestamp = m_timestamp; + prevPoint.velocity = filteredVelocity; + prevPoint.pos = m_scenePos; + prevPoint.timestamp = m_timestamp; return filteredVelocity; } -- cgit v1.2.3 From 0e039c17ccb97071fd4210ac958a5e9b999c44f9 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 24 Apr 2019 11:29:18 +0200 Subject: Use resource path for test data on Android and iOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qtbase/mkspecs/features/testcase.prf already generates a .qrc file containing the files in TESTDATA, so instead of trying to copy QML files to the device, we can just use the existing resources. This fixes the following failure, which affects all tests using util.pri: I/QTestLib( 7143): FAIL! : tst_qquickapplication::initTestCase() 'QDir::setCurrent(m_directory)' returned FALSE. (Could not chdir to :/) Change-Id: Iddfd227c402dbe80aeaa9742a52690d3d8049e46 Reviewed-by: Andy Shaw Reviewed-by: Tor Arne Vestbø Reviewed-by: Simon Hausmann --- tests/auto/shared/util.cpp | 7 +++++-- tests/auto/shared/util.pri | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/auto/shared/util.cpp b/tests/auto/shared/util.cpp index 189398f0c2..96876428f6 100644 --- a/tests/auto/shared/util.cpp +++ b/tests/auto/shared/util.cpp @@ -40,7 +40,9 @@ QQmlDataTest::QQmlDataTest() : m_dataDirectory(QTest::qFindTestData("data", QT_QMLTEST_DATADIR, 0)), #endif - m_dataDirectoryUrl(QUrl::fromLocalFile(m_dataDirectory + QLatin1Char('/'))) + m_dataDirectoryUrl(m_dataDirectory.startsWith(QLatin1Char(':')) + ? QUrl(QLatin1String("qrc") + m_dataDirectory) + : QUrl::fromLocalFile(m_dataDirectory + QLatin1Char('/'))) { m_instance = this; } @@ -54,7 +56,8 @@ void QQmlDataTest::initTestCase() { QVERIFY2(!m_dataDirectory.isEmpty(), "'data' directory not found"); m_directory = QFileInfo(m_dataDirectory).absolutePath(); - QVERIFY2(QDir::setCurrent(m_directory), qPrintable(QLatin1String("Could not chdir to ") + m_directory)); + if (m_dataDirectoryUrl.scheme() != QLatin1String("qrc")) + QVERIFY2(QDir::setCurrent(m_directory), qPrintable(QLatin1String("Could not chdir to ") + m_directory)); } QString QQmlDataTest::testFile(const QString &fileName) const diff --git a/tests/auto/shared/util.pri b/tests/auto/shared/util.pri index a05af4773d..b54897ac2c 100644 --- a/tests/auto/shared/util.pri +++ b/tests/auto/shared/util.pri @@ -3,4 +3,8 @@ INCLUDEPATH += $$PWD HEADERS += $$PWD/util.h SOURCES += $$PWD/util.cpp -DEFINES += QT_QMLTEST_DATADIR=\\\"$${_PRO_FILE_PWD_}/data\\\" +android|ios { + DEFINES += QT_QMLTEST_DATADIR=\\\":/data\\\" +} else { + DEFINES += QT_QMLTEST_DATADIR=\\\"$${_PRO_FILE_PWD_}/data\\\" +} -- cgit v1.2.3 From 138d5c82f11bdcd9c6594d1e539631b9560353ae Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 23 Apr 2019 13:13:14 +0200 Subject: Revert "Optimize some Lookups" This reverts commit 2beb77c81a1f3585c15099a09ba8b2192c6da824. To optimize lookup in case of heapObject we cast its value to Object. This unfortunately does not work well when the value type of heap object is actually a string. Task-number: QTBUG-75335 Change-Id: I55d7c9e0d41f3be617ca7141a4121de3a56f8eef Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4lookup.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp index 54bce7d7b3..f8999342d1 100644 --- a/src/qml/jsruntime/qv4lookup.cpp +++ b/src/qml/jsruntime/qv4lookup.cpp @@ -242,9 +242,6 @@ ReturnedValue Lookup::getter0Inlinegetter0Inline(Lookup *l, ExecutionEngine *eng return o->inlinePropertyDataWithOffset(l->objectLookupTwoClasses.offset)->asReturnedValue(); if (l->objectLookupTwoClasses.ic2 == o->internalClass) return o->inlinePropertyDataWithOffset(l->objectLookupTwoClasses.offset2)->asReturnedValue(); - Value obj = Value::fromHeapObject(o); - Value str = Value::fromHeapObject(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[l->nameIndex]); - return static_cast(obj).get(&static_cast(str)); } l->getter = getterFallback; return getterFallback(l, engine, object); @@ -260,9 +257,6 @@ ReturnedValue Lookup::getter0Inlinegetter0MemberData(Lookup *l, ExecutionEngine return o->inlinePropertyDataWithOffset(l->objectLookupTwoClasses.offset)->asReturnedValue(); if (l->objectLookupTwoClasses.ic2 == o->internalClass) return o->memberData->values.data()[l->objectLookupTwoClasses.offset2].asReturnedValue(); - Value obj = Value::fromHeapObject(o); - Value str = Value::fromHeapObject(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[l->nameIndex]); - return static_cast(obj).get(&static_cast(str)); } l->getter = getterFallback; return getterFallback(l, engine, object); @@ -278,9 +272,6 @@ ReturnedValue Lookup::getter0MemberDatagetter0MemberData(Lookup *l, ExecutionEng return o->memberData->values.data()[l->objectLookupTwoClasses.offset].asReturnedValue(); if (l->objectLookupTwoClasses.ic2 == o->internalClass) return o->memberData->values.data()[l->objectLookupTwoClasses.offset2].asReturnedValue(); - Value obj = Value::fromHeapObject(o); - Value str = Value::fromHeapObject(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[l->nameIndex]); - return static_cast(obj).get(&static_cast(str)); } l->getter = getterFallback; return getterFallback(l, engine, object); @@ -296,9 +287,7 @@ ReturnedValue Lookup::getterProtoTwoClasses(Lookup *l, ExecutionEngine *engine, return l->protoLookupTwoClasses.data->asReturnedValue(); if (l->protoLookupTwoClasses.protoId2 == o->internalClass->protoId) return l->protoLookupTwoClasses.data2->asReturnedValue(); - Value obj = Value::fromHeapObject(o); - Value str = Value::fromHeapObject(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[l->nameIndex]); - return static_cast(obj).get(&static_cast(str)); + return getterFallback(l, engine, object); } l->getter = getterFallback; return getterFallback(l, engine, object); -- cgit v1.2.3