$$PWD/qhashfield_p.h \
$$PWD/qdeclarativethread_p.h \
$$PWD/qfinitestack_p.h \
+ $$PWD/qrecursionwatcher_p.h \
SOURCES += \
$$PWD/qintrusivelist.cpp \
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QRECURSIONWATCHER_P_H
+#define QRECURSIONWATCHER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class QRecursionNode;
+class QRecursionNode {
+public:
+ inline QRecursionNode();
+ bool *_r;
+};
+
+template<class T, QRecursionNode T::*Node>
+class QRecursionWatcher {
+public:
+ inline QRecursionWatcher(T *);
+ inline ~QRecursionWatcher();
+ inline bool hasRecursed() const;
+private:
+ T *_t;
+ bool _r;
+};
+
+QRecursionNode::QRecursionNode()
+: _r(0)
+{
+}
+
+template<class T, QRecursionNode T::*Node>
+QRecursionWatcher<T, Node>::QRecursionWatcher(T *t)
+: _t(t), _r(false)
+{
+ if ((_t->*Node)._r) *(_t->*Node)._r = true;
+ (_t->*Node)._r = &_r;
+}
+
+template<class T, QRecursionNode T::*Node>
+QRecursionWatcher<T, Node>::~QRecursionWatcher()
+{
+ if ((_t->*Node)._r == &_r) (_t->*Node)._r = 0;
+}
+
+template<class T, QRecursionNode T::*Node>
+bool QRecursionWatcher<T, Node>::hasRecursed() const
+{
+ return _r;
+}
+
+QT_END_NAMESPACE
+
+#endif // QRECURSIONWATCHER_P_H
// XXX TODO
// - check that the Component.onCompleted behavior is the same as 4.8 in the synchronous and
// async if nested cases
-// - implement QDeclarativeIncubator::clear()
void QDeclarativeEnginePrivate::incubate(QDeclarativeIncubator &i, QDeclarativeContextData *forContext)
{
QDeclarativeIncubatorPrivate *p = i.d;
void QDeclarativeIncubatorPrivate::incubate(QDeclarativeVME::Interrupt &i)
{
+ typedef QDeclarativeIncubatorPrivate IP;
+ QRecursionWatcher<IP, &IP::recursion> watcher(this);
+
QDeclarativeEngine *engine = component->engine;
QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);
if (progress == QDeclarativeIncubatorPrivate::Execute) {
enginePriv->referenceScarceResources();
- result = vme.execute(&errors, i);
+ QObject *tresult = vme.execute(&errors, i);
enginePriv->dereferenceScarceResources();
+ if (watcher.hasRecursed())
+ return;
+
+ result = tresult;
if (errors.isEmpty() && result == 0)
goto finishIncubate;
q->setInitialState(result);
}
+ if (watcher.hasRecursed())
+ return;
+
if (errors.isEmpty())
progress = QDeclarativeIncubatorPrivate::Completing;
else
q->statusChanged(q->status());
+ if (watcher.hasRecursed())
+ return;
+
if (i.shouldInterrupt())
goto finishIncubate;
}
if (progress == QDeclarativeIncubatorPrivate::Completing) {
do {
+ if (watcher.hasRecursed())
+ return;
+
if (vme.complete(i)) {
progress = QDeclarativeIncubatorPrivate::Completed;
goto finishIncubate;
*/
void QDeclarativeIncubator::clear()
{
+ typedef QDeclarativeIncubatorPrivate IP;
+ QRecursionWatcher<IP, &IP::recursion> watcher(d);
+
Status s = status();
if (s == Null)
if (s == Loading) {
Q_ASSERT(d->component);
enginePriv = QDeclarativeEnginePrivate::get(d->component->engine);
- delete d->result;
+ if (d->result) d->result->deleteLater();
d->result = 0;
}
#include <private/qintrusivelist_p.h>
#include <private/qdeclarativevme_p.h>
+#include <private/qrecursionwatcher_p.h>
#include <private/qdeclarativeengine_p.h>
//
typedef QDeclarativeEnginePrivate::Incubator QIPBase;
QIntrusiveList<QIPBase, &QIPBase::nextWaitingFor> waitingFor;
+ QRecursionNode recursion;
+
void clear();
void incubate(QDeclarativeVME::Interrupt &i);
QML_BEGIN_INSTR_COMMON(I)
# define QML_NEXT_INSTR(I) { \
+ if (watcher.hasRecursed()) return 0; \
genericInstr = reinterpret_cast<const QDeclarativeInstruction *>(INSTRUCTIONSTREAM); \
goto *genericInstr->common.code; \
}
# define QML_END_INSTR(I) } \
+ if (watcher.hasRecursed()) return 0; \
genericInstr = reinterpret_cast<const QDeclarativeInstruction *>(INSTRUCTIONSTREAM); \
if (interrupt.shouldInterrupt()) return 0; \
goto *genericInstr->common.code;
case QDeclarativeInstruction::I: \
QML_BEGIN_INSTR_COMMON(I)
-# define QML_NEXT_INSTR(I) break;
+# define QML_NEXT_INSTR(I) \
+ if (watcher.hasRecursed()) return 0; \
+ break;
# define QML_END_INSTR(I) \
- if (interrupt.shouldInterrupt()) return 0; \
+ if (watcher.hasRecursed() || interrupt.shouldInterrupt()) return 0; \
} break;
#endif
QDeclarativePropertyPrivate::WriteFlags flags = QDeclarativePropertyPrivate::BypassInterceptor |
QDeclarativePropertyPrivate::RemoveBindingOnAliasWrite;
+ QRecursionWatcher<QDeclarativeVME, &QDeclarativeVME::recursion> watcher(this);
+
#define COMP states.top().compiledData
#define CTXT states.top().context
#define INSTRUCTIONSTREAM states.top().instructionStream
{
Q_ASSERT(!states.isEmpty() || objects.isEmpty());
+ QRecursionWatcher<QDeclarativeVME, &QDeclarativeVME::recursion> watcher(this);
+
if (!objects.isEmpty() && !(states.at(0).flags & State::Deferred))
delete objects.at(0);
return true;
ActiveVMERestorer restore(this, QDeclarativeEnginePrivate::get(engine));
+ QRecursionWatcher<QDeclarativeVME, &QDeclarativeVME::recursion> watcher(this);
while (!bindValues.isEmpty()) {
QDeclarativeAbstractBinding *b = bindValues.pop();
QDeclarativePropertyPrivate::DontRemoveBinding);
}
- if (interrupt.shouldInterrupt())
+ if (watcher.hasRecursed() || interrupt.shouldInterrupt())
return false;
}
bindValues.deallocate();
status->componentComplete();
}
- if (interrupt.shouldInterrupt())
+ if (watcher.hasRecursed() || interrupt.shouldInterrupt())
return false;
}
parserStatus.deallocate();
a->add(&d->context->componentAttached);
emit a->completed();
- if (interrupt.shouldInterrupt())
+ if (watcher.hasRecursed() || interrupt.shouldInterrupt())
return false;
}
void *args[] = { 0 };
QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, callback.second, args);
}
+ if (watcher.hasRecursed())
+ return false;
}
finalizeCallbacks.clear();
#include "qdeclarativeerror.h"
#include "private/qbitfield_p.h"
#include "private/qdeclarativeinstruction_p.h"
+#include "private/qrecursionwatcher_p.h"
#include <QtCore/QStack>
#include <QtCore/QString>
#endif
QDeclarativeEngine *engine;
+ QRecursionNode recursion;
QFiniteStack<QObject *> objects;
QFiniteStack<QDeclarativeVMETypes::List> lists;
--- /dev/null
+import QtQuick 2.0
+
+Rectangle {
+ objectName: "switchMe"
+ signal switchMe
+ width: 100; height: 100
+ color: "green"
+ Component.onCompleted: switchMe()
+}
--- /dev/null
+import QtQuick 2.0
+
+Rectangle {
+ objectName: "blue"
+ width: 100
+ height: 100
+ color: "blue"
+}
void forceCompletion();
void setInitialState();
void clearDuringCompletion();
+ void recursiveClear();
private:
QDeclarativeIncubationController controller;
QPointer<QObject> srt = SelfRegisteringType::me();
incubator.clear();
+ QCoreApplication::processEvents(QEventLoop::DeferredDeletion);
QVERIFY(incubator.isNull());
QVERIFY(srt.isNull());
}
+class Switcher : public QObject
+{
+ Q_OBJECT
+public:
+ Switcher(QDeclarativeEngine *e) : QObject(), engine(e) { }
+
+ struct MyIncubator : public QDeclarativeIncubator
+ {
+ MyIncubator(QDeclarativeIncubator::IncubationMode mode, QObject *s)
+ : QDeclarativeIncubator(mode), switcher(s) {}
+
+ virtual void setInitialState(QObject *o) {
+ if (o->objectName() == "switchMe")
+ connect(o, SIGNAL(switchMe()), switcher, SLOT(switchIt()));
+ }
+
+ QObject *switcher;
+ };
+
+ void start()
+ {
+ incubator = new MyIncubator(QDeclarativeIncubator::Synchronous, this);
+ component = new QDeclarativeComponent(engine, TEST_FILE("recursiveClear.1.qml"));
+ component->create(*incubator);
+ }
+
+ QDeclarativeEngine *engine;
+ MyIncubator *incubator;
+ QDeclarativeComponent *component;
+
+public slots:
+ void switchIt() {
+ component->deleteLater();
+ incubator->clear();
+ component = new QDeclarativeComponent(engine, TEST_FILE("recursiveClear.2.qml"));
+ component->create(*incubator);
+ }
+};
+
+void tst_qdeclarativeincubator::recursiveClear()
+{
+ Switcher switcher(&engine);
+ switcher.start();
+}
+
QTEST_MAIN(tst_qdeclarativeincubator)
#include "tst_qdeclarativeincubator.moc"