From 8c31c6529935cd9ee6f99bc38cfd182d5b3182e2 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 18 Nov 2010 08:38:34 +0100 Subject: Don't destroy Qt's internal pthread_key_t if it was not initialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The destructor function destroy_current_thread_data_key() was always called on library unload, even if the pthread_key_t was not initialized. This can cause us to destroy a key that doesn't belong to us, as pointed out in the task below. Fix this by creating a function static instance of a class whose destructor will destroy the key. Task-number: QTBUG-10861 Reviewed-by: Morten Sørvig --- src/corelib/thread/qthread_unix.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index f508c0a..75bc78a 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -136,15 +136,17 @@ static void destroy_current_thread_data(void *p) static void create_current_thread_data_key() { pthread_key_create(¤t_thread_data_key, destroy_current_thread_data); + static class destroy_current_thread_data_key + { + public: + ~destroy_current_thread_data_key() + { + pthread_key_delete(current_thread_data_key); + } + } d; + Q_UNUSED(d); } -static void destroy_current_thread_data_key() -{ - pthread_key_delete(current_thread_data_key); -} -Q_DESTRUCTOR_FUNCTION(destroy_current_thread_data_key) - - // Utility functions for getting, setting and clearing thread specific data. // In Symbian, TLS access is significantly faster than pthread_getspecific. // However Symbian does not have the thread destruction cleanup functionality -- cgit v0.12 From d372c9a34a61674a9a5bc42ef7957683b33fee63 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 18 Nov 2010 10:37:11 +0100 Subject: Compile fix Remove the Q_UNUSED(), which uses template magic for some compilers, but some compilers don't accept local types as the template argument. Reviewed-by: trustme --- src/corelib/thread/qthread_unix.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 75bc78a..c578955 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -144,7 +144,6 @@ static void create_current_thread_data_key() pthread_key_delete(current_thread_data_key); } } d; - Q_UNUSED(d); } // Utility functions for getting, setting and clearing thread specific data. -- cgit v0.12 From 8d35bba74305fcbb73230b718611957abc771f5a Mon Sep 17 00:00:00 2001 From: Jedrzej Nowacki Date: Thu, 18 Nov 2010 10:04:00 +0200 Subject: Split newQObject tests into smaller chunks. Reviewed-by: Kent Hansen --- tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 90 +++++++++++----------------- tests/auto/qscriptvalue/tst_qscriptvalue.h | 2 + 2 files changed, 36 insertions(+), 56 deletions(-) diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index de753d2..1343356 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -1341,52 +1341,53 @@ void tst_QScriptValue::toVariant() } } -// unfortunately, this is necessary in order to do qscriptvalue_cast(...) -Q_DECLARE_METATYPE(QPushButton*) - -void tst_QScriptValue::toQObject() +void tst_QScriptValue::toQObject_nonQObject_data() { - QScriptEngine eng; - - QScriptValue undefined = eng.undefinedValue(); - QCOMPARE(undefined.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(undefined), (QObject *)0); + newEngine(); + QTest::addColumn("value"); - QScriptValue null = eng.nullValue(); - QCOMPARE(null.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(null), (QObject *)0); + QTest::newRow("invalid") << QScriptValue(); + QTest::newRow("bool(false)") << QScriptValue(false); + QTest::newRow("bool(true)") << QScriptValue(true); + QTest::newRow("int") << QScriptValue(123); + QTest::newRow("string") << QScriptValue(QString::fromLatin1("ciao")); + QTest::newRow("undefined") << QScriptValue(QScriptValue::UndefinedValue); + QTest::newRow("null") << QScriptValue(QScriptValue::NullValue); - { - QScriptValue falskt = QScriptValue(&eng, false); - QCOMPARE(falskt.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(falskt), (QObject *)0); + QTest::newRow("bool bound(false)") << QScriptValue(engine, false); + QTest::newRow("bool bound(true)") << QScriptValue(engine, true); + QTest::newRow("int bound") << QScriptValue(engine, 123); + QTest::newRow("string bound") << QScriptValue(engine, QString::fromLatin1("ciao")); + QTest::newRow("undefined bound") << engine->undefinedValue(); + QTest::newRow("null bound") << engine->nullValue(); + QTest::newRow("object") << engine->newObject(); + QTest::newRow("array") << engine->newArray(); + QTest::newRow("date") << engine->newDate(124); + QTest::newRow("variant(12345)") << engine->newVariant(12345); + QTest::newRow("variant((QObject*)0)") << engine->newVariant(qVariantFromValue((QObject*)0)); + QTest::newRow("newQObject(0)") << engine->newQObject(0); +} - QScriptValue sant = QScriptValue(&eng, true); - QCOMPARE(sant.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(sant), (QObject *)0); - QScriptValue number = QScriptValue(&eng, 123.0); - QCOMPARE(number.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(number), (QObject *)0); +void tst_QScriptValue::toQObject_nonQObject() +{ + QFETCH(QScriptValue, value); + QCOMPARE(value.toQObject(), (QObject *)0); + QCOMPARE(qscriptvalue_cast(value), (QObject *)0); +} - QScriptValue str = QScriptValue(&eng, QString("ciao")); - QCOMPARE(str.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(str), (QObject *)0); - } +// unfortunately, this is necessary in order to do qscriptvalue_cast(...) +Q_DECLARE_METATYPE(QPushButton*); - QScriptValue object = eng.newObject(); - QCOMPARE(object.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(object), (QObject *)0); +void tst_QScriptValue::toQObject() +{ + QScriptEngine eng; QScriptValue qobject = eng.newQObject(this); QCOMPARE(qobject.toQObject(), (QObject *)this); QCOMPARE(qscriptvalue_cast(qobject), (QObject *)this); QCOMPARE(qscriptvalue_cast(qobject), (QWidget *)0); - QScriptValue qobject2 = eng.newQObject(0); - QCOMPARE(qobject2.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(qobject2), (QObject *)0); - QWidget widget; QScriptValue qwidget = eng.newQObject(&widget); QCOMPARE(qwidget.toQObject(), (QObject *)&widget); @@ -1400,25 +1401,6 @@ void tst_QScriptValue::toQObject() QCOMPARE(qscriptvalue_cast(qbutton), (QWidget *)&button); QCOMPARE(qscriptvalue_cast(qbutton), &button); - // V2 constructors - { - QScriptValue falskt = QScriptValue(false); - QCOMPARE(falskt.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(falskt), (QObject *)0); - - QScriptValue sant = QScriptValue(true); - QCOMPARE(sant.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(sant), (QObject *)0); - - QScriptValue number = QScriptValue(123.0); - QCOMPARE(number.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(number), (QObject *)0); - - QScriptValue str = QScriptValue(QString("ciao")); - QCOMPARE(str.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(str), (QObject *)0); - } - // wrapping a QObject* as variant QScriptValue variant = eng.newVariant(qVariantFromValue((QObject*)&button)); QCOMPARE(variant.toQObject(), (QObject*)&button); @@ -1437,10 +1419,6 @@ void tst_QScriptValue::toQObject() QCOMPARE(qscriptvalue_cast(variant3), (QObject*)0); QCOMPARE(qscriptvalue_cast(variant3), (QWidget*)0); QCOMPARE(qscriptvalue_cast(variant3), &button); - - QScriptValue inv; - QCOMPARE(inv.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(inv), (QObject *)0); } void tst_QScriptValue::toObject() diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.h b/tests/auto/qscriptvalue/tst_qscriptvalue.h index 7bf0b66..98d83e4 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.h +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.h @@ -91,6 +91,8 @@ private slots: void toUInt32(); void toUInt16(); void toVariant(); + void toQObject_nonQObject_data(); + void toQObject_nonQObject(); void toQObject(); void toDateTime(); void toRegExp(); -- cgit v0.12