From b64d720b2870c9b7bbf051328b4914172f46dee6 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 20 Sep 2021 16:06:27 -0700 Subject: [PATCH] QPluginLoader: use constexpr variables for detecting debug plugins For MSVC it's clear that the plugin and Qt must match, since they would be linking to different runtime assemblies otherwise. For all other systems, including MinGW on Windows, there's no such thing. But we insist on MinGW debug-and-release builds matching. Change-Id: I3eb1bd30e0124f89a052fffd16a6aa52c7f8b9c0 Reviewed-by: Lars Knoll --- src/corelib/plugin/qlibrary.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index e18a5080f5..432b232d27 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #ifdef Q_OS_MAC @@ -65,17 +66,22 @@ QT_BEGIN_NAMESPACE +// On Unix systema and on Windows with MinGW, we can mix and match debug and +// release plugins without problems. (unless compiled in debug-and-release mode +// - why?) +static constexpr bool PluginMustMatchQtDebug = + QOperatingSystemVersion::currentType() == QOperatingSystemVersion::Windows +#if defined(Q_CC_MINGW) + && QT_CONFIG(debug_and_release) +#endif + ; + #ifdef QT_NO_DEBUG -# define QLIBRARY_AS_DEBUG false +static constexpr bool QtBuildIsDebug = false; #else -# define QLIBRARY_AS_DEBUG true +static constexpr bool QtBuildIsDebug = true; #endif -#if defined(Q_OS_UNIX) || (defined(Q_CC_MINGW) && !QT_CONFIG(debug_and_release)) -// We don't use separate debug and release libs on UNIX, so we want -// to allow loading plugins, regardless of how they were built. -# define QT_NO_DEBUG_PLUGIN_CHECK -#endif /*! \class QLibrary @@ -783,12 +789,10 @@ void QLibraryPrivate::updatePluginState() .arg((qt_version&0xff00) >> 8) .arg(qt_version&0xff) .arg(debug ? QLatin1String("debug") : QLatin1String("release")); -#ifndef QT_NO_DEBUG_PLUGIN_CHECK - } else if (debug != QLIBRARY_AS_DEBUG) { + } else if (PluginMustMatchQtDebug && debug != QtBuildIsDebug) { //don't issue a qWarning since we will hopefully find a non-debug? --Sam errorString = QLibrary::tr("The plugin '%1' uses incompatible Qt library." " (Cannot mix debug and release libraries.)").arg(fileName); -#endif } else { pluginState = IsAPlugin; }