Avoid using dynamic_cast<>

dynamic_cast<> breaks in cross-library situations. In the past
the issue was witnessed on Mac, this time on FreeBSD in
various configurations.

The workaround deployed here is to manually create unique
type ids in form of (addresses of) global variables.

Task-id: QTCREATORBUG-16462
Change-Id: Ie28fbb3d31d06c1a722a3d9ea808831191298e71
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Ralf Nolden <nolden@kde.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2016-06-21 14:06:24 +02:00
committed by Eike Ziller
parent 8c7913e0ba
commit 3f11ef9216
13 changed files with 74 additions and 6 deletions

View File

@@ -89,7 +89,8 @@ SOURCES += \
avddialog.cpp \
androidbuildapkstep.cpp \
androidbuildapkwidget.cpp \
androidqtsupport.cpp
androidqtsupport.cpp \
androidrunnable.cpp
FORMS += \
androidsettingswidget.ui \

View File

@@ -76,6 +76,7 @@ QtcPlugin {
"androidruncontrol.h",
"androidrunfactories.cpp",
"androidrunfactories.h",
"androidrunnable.cpp",
"androidrunnable.h",
"androidrunner.cpp",
"androidrunner.h",

View File

@@ -27,6 +27,8 @@
#include "androidconstants.h"
#include "androidsignaloperation.h"
#include <projectexplorer/runnables.h>
#include <QCoreApplication>
using namespace ProjectExplorer;

View File

@@ -0,0 +1,32 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "androidrunnable.h"
namespace Android {
void *AndroidRunnable::staticTypeId = &AndroidRunnable::staticTypeId;
} // namespace Android

View File

@@ -40,6 +40,8 @@ struct ANDROID_EXPORT AndroidRunnable
QVector<QStringList> beforeStartADBCommands;
QVector<QStringList> afterFinishADBCommands;
QString deviceSerialNumber;
static void *staticTypeId;
};
inline bool operator==(const AndroidRunnable &r1, const AndroidRunnable &r2)

View File

@@ -42,6 +42,8 @@ public:
QString analyzerHost;
QString analyzerSocket;
quint16 analyzerPort = 0;
static void *staticTypeId;
};
DEBUGGER_EXPORT bool operator==(const AnalyzerConnection &c1, const AnalyzerConnection &c2);

View File

@@ -3834,6 +3834,9 @@ QList<QObject *> DebuggerPlugin::createTestObjects() const
#endif // if WITH_TESTS
} // namespace Internal
void *AnalyzerConnection::staticTypeId = &AnalyzerConnection::staticTypeId;
} // namespace Debugger
#include "debuggerplugin.moc"

View File

@@ -28,8 +28,9 @@
#include "customwizardpage.h"
#include "customwizardscriptgenerator.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/baseprojectwizarddialog.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/runconfiguration.h>
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>

View File

@@ -30,6 +30,7 @@
#include "desktopdeviceconfigurationwidget.h"
#include "desktopprocesssignaloperation.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runnables.h>
#include <ssh/sshconnection.h>

View File

@@ -30,6 +30,7 @@
#include "../kit.h"
#include "../kitinformation.h"
#include "../runnables.h"
#include <ssh/sshconnection.h>
#include <utils/portlist.h>
@@ -466,4 +467,6 @@ DeviceEnvironmentFetcher::DeviceEnvironmentFetcher()
{
}
void *HostName::staticTypeId = &HostName::staticTypeId;
} // namespace ProjectExplorer

View File

@@ -159,6 +159,7 @@ public:
virtual ~ClonableConcept() = default;
virtual ClonableConcept *clone() const = 0;
virtual bool equals(const std::unique_ptr<ClonableConcept> &other) const = 0;
virtual void *typeId() const = 0;
};
template <class T>
@@ -168,11 +169,14 @@ public:
ClonableModel(const T &data) : m_data(data) { }
~ClonableModel() Q_DECL_NOEXCEPT { } // gcc 4.7.3
ClonableConcept *clone() const override { return new ClonableModel(*this); }
void *typeId() const { return T::staticTypeId; }
bool equals(const std::unique_ptr<ClonableConcept> &other) const override
{
auto that = dynamic_cast<const ClonableModel<T> *>(other.get());
return that && m_data == that->m_data;
if (other->typeId() != typeId())
return false;
auto that = static_cast<const ClonableModel<T> *>(other.get());
return m_data == that->m_data;
}
T m_data;
@@ -189,7 +193,7 @@ public:
void operator=(Runnable other) { d = std::move(other.d); }
template <class T> bool is() const {
return dynamic_cast<ClonableModel<T> *>(d.get()) != 0;
return d.get()->typeId() == T::staticTypeId;
}
template <class T> const T &as() const {
@@ -213,7 +217,7 @@ public:
void operator=(Connection other) { d = std::move(other.d); }
template <class T> bool is() const {
return dynamic_cast<ClonableModel<T> *>(d.get()) != 0;
return d.get()->typeId() == T::staticTypeId;
}
template <class T> const T &as() const {

View File

@@ -35,4 +35,6 @@ bool operator==(const StandardRunnable &r1, const StandardRunnable &r2)
&& r1.environment == r2.environment;
}
void *StandardRunnable::staticTypeId = &StandardRunnable::staticTypeId;
} // namespace ProjectExplorer

View File

@@ -43,8 +43,22 @@ public:
Utils::Environment environment;
ApplicationLauncher::Mode runMode = ApplicationLauncher::Gui;
IDevice::ConstPtr device; // Override the kit's device. Keep unset by default.
static void *staticTypeId;
};
PROJECTEXPLORER_EXPORT bool operator==(const StandardRunnable &r1, const StandardRunnable &r2);
class PROJECTEXPLORER_EXPORT HostName
{
public:
explicit HostName(const QString &host) : m_host(host) {}
QString host() const { return m_host; }
static void *staticTypeId;
private:
QString m_host;
};
} // namespace ProjectExplorer