From c59ebcfe72d1416897f251036db34902bbb39b1a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 18 Sep 2024 10:45:48 +0200 Subject: [PATCH] Inline qcorecmdlineargs_p.h into qcoreapplication.cpp ... its only remaining user. Amends 71b54cc24431e8bc6e97f5d62132bd5261764c3a, which removed the only remaining non-qcoreapplication.cpp user of qWinCmdArgs(). In the process, rename the function to non-public-API-looking winCmdArgs(), and adjust its Q_OS_ protection to what its caller uses (Q_OS_WIN; was: Q_OS_WIN32). As a drive-by, change an old-style- to reinterpret_cast. Pick-to: 6.8 Task-number: QTBUG-126219 Change-Id: Id37e62e9df2a0c44bb1e446e409fd36e11cb77ce Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/corelib/CMakeLists.txt | 1 - src/corelib/kernel/qcoreapplication.cpp | 23 ++++++++++- src/corelib/kernel/qcorecmdlineargs_p.h | 54 ------------------------- 3 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 src/corelib/kernel/qcorecmdlineargs_p.h diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 7385b0f27e6..cb466d389b8 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -157,7 +157,6 @@ qt_internal_add_module(Core kernel/qchronotimer.cpp kernel/qchronotimer.h kernel/qcoreapplication.cpp kernel/qcoreapplication.h kernel/qcoreapplication_p.h kernel/qcoreapplication_platform.h - kernel/qcorecmdlineargs_p.h kernel/qcoreevent.cpp kernel/qcoreevent.h kernel/qcoreevent_p.h kernel/qdeadlinetimer.cpp kernel/qdeadlinetimer.h kernel/qelapsedtimer.cpp kernel/qelapsedtimer.h diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index e804e738854..cdc4b47db90 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -13,7 +13,6 @@ #endif #include "qmetaobject.h" #include -#include "qcorecmdlineargs_p.h" #include #include #include @@ -110,6 +109,10 @@ #include #include +#ifdef Q_OS_WIN +# include +#endif + QT_BEGIN_NAMESPACE #ifndef QT_NO_QOBJECT @@ -2536,6 +2539,22 @@ qint64 QCoreApplication::applicationPid() #endif } +#ifdef Q_OS_WIN +static inline QStringList winCmdArgs(const QString &cmdLine) +{ + QStringList result; + int size; + if (wchar_t **argv = CommandLineToArgvW(reinterpret_cast(cmdLine.utf16()), &size)) { + result.reserve(size); + wchar_t **argvEnd = argv + size; + for (wchar_t **a = argv; a < argvEnd; ++a) + result.append(QString::fromWCharArray(*a)); + LocalFree(argv); + } + return result; +} +#endif // Q_OS_WIN + /*! \since 4.1 @@ -2591,7 +2610,7 @@ QStringList QCoreApplication::arguments() // the Windows API instead of using argv. Note that we only // do this when argv were not modified by the user in main(). QString cmdline = QString::fromWCharArray(GetCommandLine()); - QStringList commandLineArguments = qWinCmdArgs(cmdline); + QStringList commandLineArguments = winCmdArgs(cmdline); // Even if the user didn't modify argv before passing them // on to QCoreApplication, derived QApplications might have. diff --git a/src/corelib/kernel/qcorecmdlineargs_p.h b/src/corelib/kernel/qcorecmdlineargs_p.h deleted file mode 100644 index 2b8d9763f61..00000000000 --- a/src/corelib/kernel/qcorecmdlineargs_p.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only - -#ifndef QCORECMDLINEARGS_P_H -#define QCORECMDLINEARGS_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 -#include "QtCore/qstring.h" -#include "QtCore/qstringlist.h" - -#if defined(Q_OS_WIN) -# ifdef Q_OS_WIN32 -# include // first to suppress min, max macros. -# include -# else -# include -# endif - -QT_BEGIN_NAMESPACE - -#if defined(Q_OS_WIN32) - -static inline QStringList qWinCmdArgs(const QString &cmdLine) -{ - QStringList result; - int size; - if (wchar_t **argv = CommandLineToArgvW((const wchar_t *)cmdLine.utf16(), &size)) { - result.reserve(size); - wchar_t **argvEnd = argv + size; - for (wchar_t **a = argv; a < argvEnd; ++a) - result.append(QString::fromWCharArray(*a)); - LocalFree(argv); - } - return result; -} - -#endif // Q_OS_WIN32 - -QT_END_NAMESPACE - -#endif // Q_OS_WIN - -#endif // QCORECMDLINEARGS_WIN_P_H