diff options
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 99 |
1 files changed, 74 insertions, 25 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index e849227..2630b63 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -72,6 +72,7 @@ static int DIRECT_CONNECTION_ONLY = 0; static int *queuedConnectionTypes(const QList<QByteArray> &typeNames) { int *types = new int [typeNames.count() + 1]; + Q_CHECK_PTR(types); for (int i = 0; i < typeNames.count(); ++i) { const QByteArray typeName = typeNames.at(i); if (typeName.endsWith('*')) @@ -405,6 +406,10 @@ void QMetaObject::changeGuard(QObject **ptr, QObject *o) return; } QMutexLocker locker(guardHashLock()); + if (o) { + hash->insert(o, ptr); + QObjectPrivate::get(o)->hasGuards = true; + } if (*ptr) { bool more = false; //if the QObject has more pointer attached to it. GuardHash::iterator it = hash->find(*ptr); @@ -421,10 +426,6 @@ void QMetaObject::changeGuard(QObject **ptr, QObject *o) QObjectPrivate::get(*ptr)->hasGuards = false; } *ptr = o; - if (*ptr) { - hash->insert(*ptr, ptr); - QObjectPrivate::get(*ptr)->hasGuards = true; - } } /*! \internal @@ -685,12 +686,18 @@ QObject::QObject(QObject *parent) : d_ptr(new QObjectPrivate) { Q_D(QObject); - qt_addObject(d_ptr->q_ptr = this); + d_ptr->q_ptr = this; d->threadData = (parent && !parent->thread()) ? parent->d_func()->threadData : QThreadData::current(); d->threadData->ref(); - if (!check_parent_thread(parent, parent ? parent->d_func()->threadData : 0, d->threadData)) - parent = 0; - setParent(parent); + QT_TRY { + if (!check_parent_thread(parent, parent ? parent->d_func()->threadData : 0, d->threadData)) + parent = 0; + setParent(parent); + } QT_CATCH(...) { + d->threadData->deref(); + QT_RETHROW; + } + qt_addObject(this); } #ifdef QT3_SUPPORT @@ -720,20 +727,26 @@ QObject::QObject(QObjectPrivate &dd, QObject *parent) : d_ptr(&dd) { Q_D(QObject); - qt_addObject(d_ptr->q_ptr = this); + d_ptr->q_ptr = this; d->threadData = (parent && !parent->thread()) ? parent->d_func()->threadData : QThreadData::current(); d->threadData->ref(); - if (!check_parent_thread(parent, parent ? parent->d_func()->threadData : 0, d->threadData)) - parent = 0; - if (d->isWidget) { - if (parent) { - d->parent = parent; - d->parent->d_func()->children.append(this); + QT_TRY { + if (!check_parent_thread(parent, parent ? parent->d_func()->threadData : 0, d->threadData)) + parent = 0; + if (d->isWidget) { + if (parent) { + d->parent = parent; + d->parent->d_func()->children.append(this); + } + // no events sent here, this is done at the end of the QWidget constructor + } else { + setParent(parent); } - // no events sent here, this is done at the end of the QWidget constructor - } else { - setParent(parent); + } QT_CATCH(...) { + d->threadData->deref(); + QT_RETHROW; } + qt_addObject(this); } /*! @@ -785,11 +798,26 @@ QObject::~QObject() // all the signal/slots connections are still in place - if we don't // quit now, we will crash pretty soon. qWarning("Detected an unexpected exception in ~QObject while emitting destroyed()."); +#if defined(Q_AUTOTEST_EXPORT) && !defined(QT_NO_EXCEPTIONS) + struct AutotestException : public std::exception + { + const char *what() const throw() { return "autotest swallow"; } + } autotestException; + // throw autotestException; + +#else QT_RETHROW; +#endif } { - QMutexLocker locker(signalSlotLock(this)); + QMutex *signalSlotMutex = 0; + QT_TRY { + signalSlotMutex = signalSlotLock(this); + } QT_CATCH(const std::bad_alloc &) { + // out of memory - swallow to prevent a crash + } + QMutexLocker locker(signalSlotMutex); // set ref to zero to indicate that this object has been deleted if (d->currentSender != 0) @@ -2709,8 +2737,14 @@ bool QObject::disconnect(const QObject *sender, const char *signal, QByteArray signal_name; bool signal_found = false; if (signal) { - signal_name = QMetaObject::normalizedSignature(signal); - signal = signal_name; + QT_TRY { + signal_name = QMetaObject::normalizedSignature(signal); + signal = signal_name.constData(); + } QT_CATCH (const std::bad_alloc &) { + // if the signal is already normalized, we can continue. + if (sender->metaObject()->indexOfSignal(signal + 1) == -1) + QT_RETHROW; + } if (!check_signal_macro(sender, signal, "disconnect", "unbind")) return false; @@ -2722,8 +2756,15 @@ bool QObject::disconnect(const QObject *sender, const char *signal, int membcode = -1; bool method_found = false; if (method) { - method_name = QMetaObject::normalizedSignature(method); - method = method_name; + QT_TRY { + method_name = QMetaObject::normalizedSignature(method); + method = method_name.constData(); + } QT_CATCH(const std::bad_alloc &) { + // if the method is already normalized, we can continue. + if (receiver->metaObject()->indexOfMethod(method + 1) == -1) + QT_RETHROW; + } + membcode = extract_code(method); if (!check_method_code(membcode, receiver, method, "disconnect")) return false; @@ -2882,14 +2923,20 @@ bool QMetaObject::connect(const QObject *sender, int signal_index, c->method = method_index; c->connectionType = type; c->argumentTypes = types; + + QT_TRY { + s->d_func()->addConnection(signal_index, c); + } QT_CATCH(...) { + delete c; + QT_RETHROW; + } + c->prev = &r->d_func()->senders; c->next = *c->prev; *c->prev = c; if (c->next) c->next->prev = &c->next; - s->d_func()->addConnection(signal_index, c); - if (signal_index < 0) { for (uint i = 0; i < (sizeof sender->d_func()->connectedSignals / sizeof sender->d_func()->connectedSignals[0] ); ++i) @@ -3081,7 +3128,9 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect while (c->argumentTypes[nargs-1]) ++nargs; int *types = (int *) qMalloc(nargs*sizeof(int)); + Q_CHECK_PTR(types); void **args = (void **) qMalloc(nargs*sizeof(void *)); + Q_CHECK_PTR(args); types[0] = 0; // return type args[0] = 0; // return value for (int n = 1; n < nargs; ++n) |