Use QVector<int> instead of QList<int> for storing metatypes in QtDBus

Change I00020eed fixed a bug present in 64-bit machines because it
tried to access QList<int>'s internal array data, assuming it was a
vector of ints. That worked in 32-bit, but not 64-bit.

The fix involves a conversion between QList and QVector. Now fix it
properly by changing everything to be QVector. The benefit is that on
64-bit, they are real vectors, not the 50%-overhead pointer array that
QList is.

Change-Id: I989ad279d0d8b2c9ab262a1eed413ab2365b5461
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Thiago Macieira 2011-11-16 14:47:11 -02:00 committed by Qt by Nokia
parent 387ec9c2a3
commit e22a6108fd
8 changed files with 18 additions and 23 deletions

View File

@ -296,7 +296,7 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **
realObject = realObject->parent();
// break down the parameter list
QList<int> types;
QVector<int> types;
int inputCount = qDBusParametersForMethod(mm, types);
if (inputCount == -1)
// invalid signal signature

View File

@ -124,7 +124,7 @@ public:
QString service, path, signature;
QObject* obj;
int midx;
QList<int> params;
QVector<int> params;
QStringList argumentMatch;
QByteArray matchRule;
};
@ -241,7 +241,7 @@ private:
void sendError(const QDBusMessage &msg, QDBusError::ErrorType code);
void deliverCall(QObject *object, int flags, const QDBusMessage &msg,
const QList<int> &metaTypes, int slotIdx);
const QVector<int> &metaTypes, int slotIdx);
bool isServiceRegisteredByThread(const QString &serviceName) const;
@ -309,7 +309,7 @@ public:
public:
// static methods
static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<int>& params);
static int findSlot(QObject *obj, const QByteArray &normalizedName, QVector<int> &params);
static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
const QString &service,
const QString &path, const QString &interface, const QString &name,
@ -321,7 +321,7 @@ public:
int idx, const QList<int> &metaTypes,
const QDBusMessage &msg);
static QDBusCallDeliveryEvent *prepareReply(QDBusConnectionPrivate *target, QObject *object,
int idx, const QList<int> &metaTypes,
int idx, const QVector<int> &metaTypes,
const QDBusMessage &msg);
static void processFinishedCall(QDBusPendingCallPrivate *call);
@ -335,7 +335,7 @@ public:
};
// in qdbusmisc.cpp
extern int qDBusParametersForMethod(const QMetaMethod &mm, QList<int>& metaTypes);
extern int qDBusParametersForMethod(const QMetaMethod &mm, QVector<int> &metaTypes);
extern bool qDBusCheckAsyncTag(const char *tag);
extern bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name);
extern QString qDBusInterfaceFromMetaObject(const QMetaObject *mo);

View File

@ -624,7 +624,7 @@ static void huntAndEmit(DBusConnection *connection, DBusMessage *msg,
}
static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
const QString &signature_, QList<int>& metaTypes)
const QString &signature_, QVector<int> &metaTypes)
{
QByteArray msgSignature = signature_.toLatin1();
@ -724,7 +724,7 @@ static QDBusCallDeliveryEvent * const DIRECT_DELIVERY = (QDBusCallDeliveryEvent
QDBusCallDeliveryEvent* QDBusConnectionPrivate::prepareReply(QDBusConnectionPrivate *target,
QObject *object, int idx,
const QList<int> &metaTypes,
const QVector<int> &metaTypes,
const QDBusMessage &msg)
{
Q_ASSERT(object);
@ -862,7 +862,7 @@ bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBu
}
void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const QDBusMessage &msg,
const QList<int> &metaTypes, int slotIdx)
const QVector<int> &metaTypes, int slotIdx)
{
Q_ASSERT_X(!object || QThread::currentThread() == object->thread(),
"QDBusConnection: internal threading error",
@ -1238,7 +1238,7 @@ void QDBusConnectionPrivate::serviceOwnerChangedNoLock(const QString &name,
}
int QDBusConnectionPrivate::findSlot(QObject* obj, const QByteArray &normalizedName,
QList<int> &params)
QVector<int> &params)
{
int midx = obj->metaObject()->indexOfMethod(normalizedName);
if (midx == -1)

View File

@ -84,7 +84,7 @@ struct QDBusSlotCache
{
int flags;
int slotIdx;
QList<int> metaTypes;
QVector<int> metaTypes;
};
typedef QMultiHash<QString, Data> Hash;
Hash hash;
@ -94,7 +94,7 @@ class QDBusCallDeliveryEvent: public QMetaCallEvent
{
public:
QDBusCallDeliveryEvent(const QDBusConnection &c, int id, QObject *sender,
const QDBusMessage &msg, const QList<int> &types, int f = 0)
const QDBusMessage &msg, const QVector<int> &types, int f = 0)
: QMetaCallEvent(0, id, 0, sender, -1), connection(c), message(msg), metaTypes(types), flags(f)
{ }
@ -106,7 +106,7 @@ public:
private:
QDBusConnection connection; // just for refcounting
QDBusMessage message;
QList<int> metaTypes;
QVector<int> metaTypes;
int flags;
};

View File

@ -126,7 +126,7 @@ bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
// metaTypes.count() >= retval + 1 in all cases
//
// sig must be the normalised signature for the method
int qDBusParametersForMethod(const QMetaMethod &mm, QList<int>& metaTypes)
int qDBusParametersForMethod(const QMetaMethod &mm, QVector<int> &metaTypes)
{
QDBusMetaTypeId::init();

View File

@ -180,12 +180,7 @@ bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *memb
if (metaTypes.at(count) == QDBusMetaTypeId::message)
--count;
if (count == 0) {
setMetaTypes(count, 0);
} else {
QVector<int> types = QVector<int>::fromList(metaTypes);
setMetaTypes(count, types.constData() + 1);
}
setMetaTypes(count, count ? metaTypes.constData() + 1 : 0);
return true;
}

View File

@ -56,7 +56,7 @@
#include <qshareddata.h>
#include <qpointer.h>
#include <qlist.h>
#include <qvector.h>
#include <qmutex.h>
#include <qwaitcondition.h>
@ -82,7 +82,7 @@ public:
// for the callback mechanism (see setReplyCallback and QDBusConnectionPrivate::sendWithReplyAsync)
QPointer<QObject> receiver;
QList<int> metaTypes;
QVector<int> metaTypes;
int methodIdx;
bool autoDelete;

View File

@ -168,7 +168,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
continue; // wasn't a valid type
QList<QByteArray> names = mm.parameterNames();
QList<int> types;
QVector<int> types;
int inputCount = qDBusParametersForMethod(mm, types);
if (inputCount == -1)
continue; // invalid form