summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <[email protected]>2021-09-29 18:07:23 -0700
committerThiago Macieira <[email protected]>2021-10-29 20:26:13 -0700
commita887b7750cc8cb7fcc12e782eb046111f4a78902 (patch)
tree6dedb317ad30f975af90849b0be4c8e13d2593a8
parent388136e860c51f0d00026b8be831d562f8193704 (diff)
qconfig.cpp: use qOffsetStringArray
It's been there for ages, we may as well use it and remove unnecessary complexity from CMake. Pick-to: 6.2 Change-Id: I2bbf422288924c198645fffd16a9742567a7e4af Reviewed-by: Thiago Macieira <[email protected]> Reviewed-by: Alexey Edelev <[email protected]>
-rw-r--r--cmake/QtQmakeHelpers.cmake37
-rw-r--r--src/corelib/global/qconfig.cpp.in15
-rw-r--r--src/corelib/global/qlibraryinfo.cpp20
-rw-r--r--src/corelib/tools/qoffsetstringarray_p.h7
4 files changed, 35 insertions, 44 deletions
diff --git a/cmake/QtQmakeHelpers.cmake b/cmake/QtQmakeHelpers.cmake
index 7c5d21ce78c..9ad84da5ee3 100644
--- a/cmake/QtQmakeHelpers.cmake
+++ b/cmake/QtQmakeHelpers.cmake
@@ -13,35 +13,22 @@ function(qt_to_qmake_path_list out_var)
set("${out_var}" "${result}" PARENT_SCOPE)
endfunction()
-macro(qt_add_string_to_qconfig_cpp str)
- string(LENGTH "${str}" length)
- string(APPEND QT_CONFIG_STRS " \"${str}\\0\"\n")
- string(APPEND QT_CONFIG_STR_OFFSETS " ${QT_CONFIG_STR_OFFSET},\n")
- math(EXPR QT_CONFIG_STR_OFFSET "${QT_CONFIG_STR_OFFSET}+${length}+1")
-endmacro()
function(qt_generate_qconfig_cpp in_file out_file)
- set(QT_CONFIG_STR_OFFSET "0")
- set(QT_CONFIG_STR_OFFSETS "")
set(QT_CONFIG_STRS "")
- # Start first part.
- qt_add_string_to_qconfig_cpp("${INSTALL_DOCDIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_INCLUDEDIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_LIBDIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_LIBEXECDIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_BINDIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_PLUGINSDIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_QMLDIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_ARCHDATADIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_DATADIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_TRANSLATIONSDIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_EXAMPLESDIR}")
- qt_add_string_to_qconfig_cpp("${INSTALL_TESTSDIR}")
-
- # Save first part.
- set(QT_CONFIG_STR_OFFSETS_FIRST "${QT_CONFIG_STR_OFFSETS}")
- set(QT_CONFIG_STRS_FIRST "${QT_CONFIG_STRS}")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_DOCDIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_INCLUDEDIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_LIBDIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_LIBEXECDIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_BINDIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_PLUGINSDIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_QMLDIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_ARCHDATADIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_DATADIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_TRANSLATIONSDIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_EXAMPLESDIR}\",\n")
+ string(APPEND QT_CONFIG_STRS " \"${INSTALL_TESTSDIR}\"")
# Settings path / sysconf dir.
set(QT_SYS_CONF_DIR "${INSTALL_SYSCONFDIR}")
diff --git a/src/corelib/global/qconfig.cpp.in b/src/corelib/global/qconfig.cpp.in
index f6ce3355997..7c79d9073dd 100644
--- a/src/corelib/global/qconfig.cpp.in
+++ b/src/corelib/global/qconfig.cpp.in
@@ -5,19 +5,16 @@
*
* - QLibraryInfo::LibraryPath enum in qtbase/src/corelib/global/qlibraryinfo.h
* - qtConfEntries in qtbase/src/corelib/global/qlibraryinfo.cpp
- *
- * The reason for this is pointer mathematics in the QLibraryInfo implementation when iterating
- * qt_configure_strs. Also qtConfEntries are strongly bound to QLibraryInfo::LibraryPath.
*/
+#include "private/qoffsetstringarray_p.h"
/* Installation Info */
static const char qt_configure_prefix_path_str [12+256] = "qt_prfxpath=@QT_CONFIGURE_PREFIX_PATH_STR@";
-static const short qt_configure_str_offsets[] = {
-@QT_CONFIG_STR_OFFSETS_FIRST@
-};
-static const char qt_configure_strs[] =
-@QT_CONFIG_STRS_FIRST@
-;
+
+static constexpr auto qt_configure_strs = QT_PREPEND_NAMESPACE(qOffsetStringArray)(
+@QT_CONFIG_STRS@
+);
+
#define QT_CONFIGURE_SETTINGS_PATH "@QT_SYS_CONF_DIR@"
#define QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH "@QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH@"
#define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index 18a429fb6dc..a2bf7599fed 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
+** Copyright (C) 2021 The Qt Company Ltd.
+** Copyright (C) 2021 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -51,14 +51,13 @@
#include "qcoreapplication.h"
#include "private/qglobal_p.h"
+#include "archdetect.cpp"
#include "qconfig.cpp"
#ifdef Q_OS_DARWIN
# include "private/qcore_mac_p.h"
#endif // Q_OS_DARWIN
-#include "archdetect.cpp"
-
#if QT_CONFIG(relocatable) && QT_CONFIG(dlopen) && !QT_CONFIG(framework)
# include <dlfcn.h>
#endif
@@ -454,7 +453,7 @@ static QString getRelocatablePrefix()
// executable within the QT_HOST_BIN directory. We're detecting the latter case by checking
// whether there's an import library corresponding to our QtCore DLL in PREFIX/lib.
const QString libdir = QString::fromLocal8Bit(
- qt_configure_strs + qt_configure_str_offsets[QLibraryInfo::LibrariesPath - 1]);
+ qt_configure_strs[QLibraryInfo::LibrariesPath - 1]);
const QLatin1Char slash('/');
#if defined(Q_CC_MINGW)
const QString implibPrefix = QStringLiteral("lib");
@@ -486,7 +485,7 @@ static QString getRelocatablePrefix()
// See "Hardware capabilities" in the ld.so documentation and the Qt 5.3.0
// changelog regarding SSE2 support.
const QString libdir = QString::fromLocal8Bit(
- qt_configure_strs + qt_configure_str_offsets[QLibraryInfo::LibrariesPath - 1]);
+ qt_configure_strs[QLibraryInfo::LibrariesPath - 1]);
QDir prefixDir(prefixPath);
while (!prefixDir.exists(libdir)) {
prefixDir.cdUp();
@@ -596,8 +595,8 @@ QString QLibraryInfo::path(LibraryPath p)
const char * volatile path = nullptr;
if (loc == PrefixPath) {
ret = getPrefix();
- } else if (unsigned(loc) <= sizeof(qt_configure_str_offsets)/sizeof(qt_configure_str_offsets[0])) {
- path = qt_configure_strs + qt_configure_str_offsets[loc - 1];
+ } else if (int(loc) <= qt_configure_strs.count()) {
+ path = qt_configure_strs[loc - 1];
#ifndef Q_OS_WIN // On Windows we use the registry
} else if (loc == SettingsPath) {
path = QT_CONFIGURE_SETTINGS_PATH;
@@ -691,6 +690,7 @@ QT_END_NAMESPACE
#include "private/qcoreapplication_p.h"
+QT_WARNING_DISABLE_GCC("-Wformat-overflow")
QT_WARNING_DISABLE_GCC("-Wattributes")
QT_WARNING_DISABLE_CLANG("-Wattributes")
QT_WARNING_DISABLE_INTEL(2621)
@@ -738,8 +738,8 @@ void qt_core_boilerplate()
"Library path: %s\n"
"Plugin path: %s\n",
qt_configure_prefix_path_str + 12,
- qt_configure_strs + qt_configure_str_offsets[QT_PREPEND_NAMESPACE(QLibraryInfo)::LibrariesPath - 1],
- qt_configure_strs + qt_configure_str_offsets[QT_PREPEND_NAMESPACE(QLibraryInfo)::PluginsPath - 1]);
+ qt_configure_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::LibrariesPath - 1],
+ qt_configure_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::PluginsPath - 1]);
QT_PREPEND_NAMESPACE(qDumpCPUFeatures)();
diff --git a/src/corelib/tools/qoffsetstringarray_p.h b/src/corelib/tools/qoffsetstringarray_p.h
index 6e0cb1f30bd..607f13d6623 100644
--- a/src/corelib/tools/qoffsetstringarray_p.h
+++ b/src/corelib/tools/qoffsetstringarray_p.h
@@ -63,6 +63,12 @@ class tst_QOffsetStringArray;
QT_BEGIN_NAMESPACE
+QT_WARNING_PUSH
+#if defined(Q_CC_GNU) && Q_CC_GNU >= 1100
+// we usually don't overread, but GCC has a false positive
+QT_WARNING_DISABLE_GCC("-Wstringop-overread")
+#endif
+
template <typename StaticString, typename OffsetList>
class QOffsetStringArray
@@ -172,6 +178,7 @@ constexpr auto qOffsetStringArray(const char (&...strings)[Nx]) noexcept
return QtPrivate::qOffsetStringArray(extractString, QtPrivate::StaticString(strings)...);
}
+QT_WARNING_POP
QT_END_NAMESPACE
#endif // QOFFSETSTRINGARRAY_P_H