Remove QInternal callbacks and internal functions

After commit 79f675a1e0, the connect and
disconnect callback API effectively becomes useless. Now that these
callbacks cannot/do not, it makes little sense to keep the backdoors
added for Qt Jambi support.

Remove them for now. Should the Qt Jambi team want/need to port to Qt 5,
we can re-add them, possibly designing a better API for doing so as
well.

Change-Id: I6209a1d647d683c979d5294b632b8c12c0f9f91c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Bradley T. Hughes 2011-11-29 10:59:48 +01:00 committed by Qt by Nokia
parent 613183ff8c
commit ad8edac53c
9 changed files with 19 additions and 304 deletions

View File

@ -2831,108 +2831,6 @@ int qrand()
with meaningful parameter names in their signatures.
*/
struct QInternal_CallBackTable {
QVector<QList<qInternalCallback> > callbacks;
};
Q_GLOBAL_STATIC(QInternal_CallBackTable, global_callback_table)
bool QInternal::registerCallback(Callback cb, qInternalCallback callback)
{
if (cb >= 0 && cb < QInternal::LastCallback) {
QInternal_CallBackTable *cbt = global_callback_table();
cbt->callbacks.resize(cb + 1);
cbt->callbacks[cb].append(callback);
return true;
}
return false;
}
bool QInternal::unregisterCallback(Callback cb, qInternalCallback callback)
{
if (cb >= 0 && cb < QInternal::LastCallback) {
QInternal_CallBackTable *cbt = global_callback_table();
return (bool) cbt->callbacks[cb].removeAll(callback);
}
return false;
}
bool QInternal::activateCallbacks(Callback cb, void **parameters)
{
Q_ASSERT_X(cb >= 0, "QInternal::activateCallback()", "Callback id must be a valid id");
QInternal_CallBackTable *cbt = global_callback_table();
if (cbt && cb < cbt->callbacks.size()) {
QList<qInternalCallback> callbacks = cbt->callbacks[cb];
bool ret = false;
for (int i=0; i<callbacks.size(); ++i)
ret |= (callbacks.at(i))(parameters);
return ret;
}
return false;
}
extern void qt_set_current_thread_to_main_thread();
bool QInternal::callFunction(InternalFunction func, void **args)
{
Q_ASSERT_X(func >= 0,
"QInternal::callFunction()", "Callback id must be a valid id");
#ifndef QT_NO_QOBJECT
switch (func) {
#ifndef QT_NO_THREAD
case QInternal::CreateThreadForAdoption:
*args = QAdoptedThread::createThreadForAdoption();
return true;
#endif
case QInternal::RefAdoptedThread:
QThreadData::get2((QThread *) *args)->ref();
return true;
case QInternal::DerefAdoptedThread:
QThreadData::get2((QThread *) *args)->deref();
return true;
case QInternal::SetCurrentThreadToMainThread:
qt_set_current_thread_to_main_thread();
return true;
case QInternal::SetQObjectSender: {
QObject *receiver = (QObject *) args[0];
QObjectPrivate::Sender *sender = new QObjectPrivate::Sender;
sender->sender = (QObject *) args[1];
sender->signal = *(int *) args[2];
sender->ref = 1;
// Store the old sender as "return value"
args[3] = QObjectPrivate::setCurrentSender(receiver, sender);
args[4] = sender;
return true;
}
case QInternal::GetQObjectSender: {
QObject *receiver = (QObject *) args[0];
QObjectPrivate *d = QObjectPrivate::get(receiver);
args[1] = d->currentSender ? d->currentSender->sender : 0;
return true;
}
case QInternal::ResetQObjectSender: {
QObject *receiver = (QObject *) args[0];
QObjectPrivate::Sender *oldSender = (QObjectPrivate::Sender *) args[1];
QObjectPrivate::Sender *sender = (QObjectPrivate::Sender *) args[2];
QObjectPrivate::resetCurrentSender(receiver, sender, oldSender);
delete sender;
return true;
}
default:
break;
}
#else
Q_UNUSED(args);
Q_UNUSED(func);
#endif
return false;
}
/*!
\macro Q_BYTE_ORDER
\relates <QtGlobal>

View File

@ -1592,26 +1592,6 @@ public:
RelayoutDropped
};
enum Callback {
ConnectCallback,
DisconnectCallback,
AdoptCurrentThread,
EventNotifyCallback,
LastCallback
};
enum InternalFunction {
CreateThreadForAdoption,
RefAdoptedThread,
DerefAdoptedThread,
SetCurrentThreadToMainThread,
SetQObjectSender,
GetQObjectSender,
ResetQObjectSender,
LastInternalFunction
};
enum DockPosition {
LeftDock,
RightDock,
@ -1619,12 +1599,6 @@ public:
BottomDock,
DockCount
};
static bool registerCallback(Callback, qInternalCallback);
static bool unregisterCallback(Callback, qInternalCallback);
static bool activateCallbacks(Callback, void **);
static bool callFunction(InternalFunction func, void **);
};
QT_END_NAMESPACE

View File

@ -298,14 +298,6 @@ Q_CORE_EXPORT uint qGlobalPostedEventsCount()
return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset;
}
void qt_set_current_thread_to_main_thread()
{
QCoreApplicationPrivate::theMainThread = QThread::currentThread();
}
QCoreApplication *QCoreApplication::self = 0;
QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = 0;
uint QCoreApplicationPrivate::attribs;
@ -795,14 +787,6 @@ bool QCoreApplication::testAttribute(Qt::ApplicationAttribute attribute)
*/
bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event)
{
// Make it possible for Qt Jambi and QSA to hook into events even
// though QApplication is subclassed...
bool result = false;
void *cbdata[] = { receiver, event, &result };
if (QInternal::activateCallbacks(QInternal::EventNotifyCallback, cbdata)) {
return result;
}
// Qt enforces the rule that events can only be sent to objects in
// the current thread, so receiver->d_func()->threadData is
// equivalent to QThreadData::current(), just without the function

View File

@ -2388,13 +2388,6 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign
const QObject *receiver, const char *method,
Qt::ConnectionType type)
{
{
void *result = 0;
const void *cbdata[] = { sender, signal, receiver, method, &type , &result};
if (QInternal::activateCallbacks(QInternal::ConnectCallback, (void **) cbdata))
return QMetaObject::Connection(result);
}
#ifndef QT_NO_DEBUG
bool warnCompat = true;
#endif
@ -2573,18 +2566,6 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho
signalSignature.append((char)(QSIGNAL_CODE + '0'));
signalSignature.append(signal.signature());
{
QByteArray methodSignature;
methodSignature.reserve(qstrlen(method.signature())+1);
methodSignature.append((char)(method.methodType() == QMetaMethod::Slot ? QSLOT_CODE
: method.methodType() == QMetaMethod::Signal ? QSIGNAL_CODE : 0 + '0'));
methodSignature.append(method.signature());
void *result = 0;
const void *cbdata[] = { sender, signalSignature.constData(), receiver, methodSignature.constData(), &type, &result };
if (QInternal::activateCallbacks(QInternal::ConnectCallback, (void **) cbdata))
return QMetaObject::Connection(result);
}
int signal_index;
int method_index;
{
@ -2714,12 +2695,6 @@ bool QObject::disconnect(const QObject *sender, const char *signal,
return false;
}
{
const void *cbdata[] = { sender, signal, receiver, method };
if (QInternal::activateCallbacks(QInternal::DisconnectCallback, (void **) cbdata))
return true;
}
const char *signal_arg = signal;
QByteArray signal_name;
bool signal_found = false;
@ -2868,20 +2843,6 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
signalSignature.append(signal.signature());
}
{
QByteArray methodSignature;
if (method.mobj) {
methodSignature.reserve(qstrlen(method.signature())+1);
methodSignature.append((char)(method.methodType() == QMetaMethod::Slot ? QSLOT_CODE
: method.methodType() == QMetaMethod::Signal ? QSIGNAL_CODE : 0 + '0'));
methodSignature.append(method.signature());
}
const void *cbdata[] = { sender, signal.mobj ? signalSignature.constData() : 0,
receiver, method.mobj ? methodSignature.constData() : 0 };
if (QInternal::activateCallbacks(QInternal::DisconnectCallback, (void **) cbdata))
return true;
}
int signal_index;
int method_index;
{

View File

@ -152,13 +152,6 @@ QAdoptedThread::~QAdoptedThread()
// fprintf(stderr, "~QAdoptedThread = %p\n", this);
}
QThread *QAdoptedThread::createThreadForAdoption()
{
QScopedPointer<QThread> t(new QAdoptedThread(0));
t->moveToThread(t.data());
return t.take();
}
void QAdoptedThread::run()
{
// this function should never be called

View File

@ -248,7 +248,6 @@ public:
~QAdoptedThread();
void init();
static QThread *createThreadForAdoption();
private:
void run();
};

View File

@ -199,28 +199,17 @@ QThreadData *QThreadData::current()
{
QThreadData *data = get_thread_data();
if (!data) {
void *a;
if (QInternal::activateCallbacks(QInternal::AdoptCurrentThread, &a)) {
QThread *adopted = static_cast<QThread*>(a);
Q_ASSERT(adopted);
data = QThreadData::get2(adopted);
data = new QThreadData;
QT_TRY {
set_thread_data(data);
adopted->d_func()->running = true;
adopted->d_func()->finished = false;
static_cast<QAdoptedThread *>(adopted)->init();
} else {
data = new QThreadData;
QT_TRY {
set_thread_data(data);
data->thread = new QAdoptedThread(data);
} QT_CATCH(...) {
clear_thread_data();
data->deref();
data = 0;
QT_RETHROW;
}
data->thread = new QAdoptedThread(data);
} QT_CATCH(...) {
clear_thread_data();
data->deref();
data = 0;
QT_RETHROW;
}
data->deref();
data->isAdopted = true;
data->threadId = (Qt::HANDLE)pthread_self();
if (!QCoreApplicationPrivate::theMainThread)

View File

@ -101,29 +101,19 @@ QThreadData *QThreadData::current()
qt_create_tls();
QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index));
if (!threadData) {
QThread *adopted = 0;
if (QInternal::activateCallbacks(QInternal::AdoptCurrentThread, (void **) &adopted)) {
Q_ASSERT(adopted);
threadData = QThreadData::get2(adopted);
TlsSetValue(qt_current_thread_data_tls_index, threadData);
adopted->d_func()->running = true;
adopted->d_func()->finished = false;
static_cast<QAdoptedThread *>(adopted)->init();
} else {
threadData = new QThreadData;
// This needs to be called prior to new AdoptedThread() to
// avoid recursion.
TlsSetValue(qt_current_thread_data_tls_index, threadData);
QT_TRY {
threadData->thread = new QAdoptedThread(threadData);
} QT_CATCH(...) {
TlsSetValue(qt_current_thread_data_tls_index, 0);
threadData->deref();
threadData = 0;
QT_RETHROW;
}
threadData = new QThreadData;
// This needs to be called prior to new AdoptedThread() to
// avoid recursion.
TlsSetValue(qt_current_thread_data_tls_index, threadData);
QT_TRY {
threadData->thread = new QAdoptedThread(threadData);
} QT_CATCH(...) {
TlsSetValue(qt_current_thread_data_tls_index, 0);
threadData->deref();
threadData = 0;
QT_RETHROW;
}
threadData->deref();
threadData->isAdopted = true;
threadData->threadId = (Qt::HANDLE)GetCurrentThreadId();

View File

@ -47,7 +47,6 @@ class tst_QGlobal: public QObject
Q_OBJECT
private slots:
void qIsNull();
void qInternalCallbacks();
void for_each();
void qassert();
void qtry();
@ -71,78 +70,6 @@ void tst_QGlobal::qIsNull()
QVERIFY(!::qIsNull(f));
}
struct ConnectInfo {
QObject *sender;
QObject *receiver;
QString signal, slot;
int type;
void reset() {
sender = receiver = 0;
signal = slot = QString();
type = -1;
}
} connect_info;
bool disconnect_callback(void **data)
{
connect_info.sender = (QObject *)(data[0]);
connect_info.receiver = (QObject *)(data[2]);
connect_info.signal = QString::fromLatin1((const char *) data[1]);
connect_info.slot = QString::fromLatin1((const char *) data[3]);
return true;
}
bool connect_callback(void **data)
{
disconnect_callback(data);
connect_info.type = *(int *) data[4];
return true;
}
void tst_QGlobal::qInternalCallbacks()
{
QInternal::registerCallback(QInternal::ConnectCallback, connect_callback);
QInternal::registerCallback(QInternal::DisconnectCallback, disconnect_callback);
QObject a, b;
QString signal = QLatin1String("2mysignal(x)");
QString slot = QLatin1String("1myslot(x)");
// Test that connect works as expected...
connect_info.reset();
bool ok = QObject::connect(&a, signal.toLatin1(), &b, slot.toLatin1(), Qt::AutoConnection);
QVERIFY(!ok); // our dummy callback do not return a valid QMetaObject::Connection
QCOMPARE(&a, connect_info.sender);
QCOMPARE(&b, connect_info.receiver);
QCOMPARE(signal, connect_info.signal);
QCOMPARE(slot, connect_info.slot);
QCOMPARE((int) Qt::AutoConnection, connect_info.type);
// Test that disconnect works as expected
connect_info.reset();
ok = QObject::disconnect(&a, signal.toLatin1(), &b, slot.toLatin1());
QVERIFY(ok);
QCOMPARE(&a, connect_info.sender);
QCOMPARE(&b, connect_info.receiver);
QCOMPARE(signal, connect_info.signal);
QCOMPARE(slot, connect_info.slot);
// Unregister callbacks and verify that they are not triggered...
QInternal::unregisterCallback(QInternal::ConnectCallback, connect_callback);
QInternal::unregisterCallback(QInternal::DisconnectCallback, disconnect_callback);
connect_info.reset();
QTest::ignoreMessage(QtWarningMsg, "Object::connect: No such signal QObject::mysignal(x)");
ok = QObject::connect(&a, signal.toLatin1(), &b, slot.toLatin1(), Qt::AutoConnection);
QVERIFY(!ok);
QCOMPARE(connect_info.sender, (QObject *) 0);
QTest::ignoreMessage(QtWarningMsg, "Object::disconnect: No such signal QObject::mysignal(x)");
ok = QObject::disconnect(&a, signal.toLatin1(), &b, slot.toLatin1());
QVERIFY(!ok);
QCOMPARE(connect_info.sender, (QObject *) 0);
}
void tst_QGlobal::for_each()
{
QList<int> list;