From d4484c48c4f971f5d5d94e6a8f06428a22c38d9a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Nov 2023 00:41:09 +0100 Subject: [PATCH] Rename wxInitData::InitializeFromWide() to InitIfNecessary() And do nothing in this function if the arguments had been already initialized, as it will make it more convenient to call from other places. No real changes. --- include/wx/private/init.h | 11 ++++++++--- src/common/init.cpp | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/wx/private/init.h b/include/wx/private/init.h index 3437ca88f5..19fa540e05 100644 --- a/include/wx/private/init.h +++ b/include/wx/private/init.h @@ -25,9 +25,14 @@ struct WXDLLIMPEXP_BASE wxInitData // static, i.e. remain valid until the end of the program. void Initialize(int argc, char** argv); - // Initialize from wide command line arguments: here we currently make a - // copy of the arguments internally, so they don't need to be static. - void InitializeFromWide(int argc, wchar_t** argv); + // Initialize from wide command line arguments if we hadn't been + // initialized in some other way: this allows to call this function + // unconditionally, even when these wide arguments were themselves + // synthesized from ANSI ones by our own code. + // + // Note that here we currently make a copy of the arguments internally, so + // they don't need to be static. + void InitIfNecessary(int argc, wchar_t** argv); // This function is used instead of the dtor because the global object can // be initialized multiple times. diff --git a/src/common/init.cpp b/src/common/init.cpp index 9e463b412f..fa3956a289 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -204,8 +204,18 @@ void wxInitData::MSWInitialize() #endif // __WINDOWS__ -void wxInitData::InitializeFromWide(int argcIn, wchar_t** argvIn) +void wxInitData::InitIfNecessary(int argcIn, wchar_t** argvIn) { + // Usually, arguments are initialized from "char**" passed to main() + // elsewhere, but it is also possible to call a wide-char initialization + // function (wxInitialize(), wxEntryStart() or wxEntry() itself) directly, + // so we need to support this case too. + if ( argc ) + { + // Already initialized, nothing to do. + return; + } + // For simplicity, make a copy of the arguments, even though we could avoid // it -- but this would complicate the cleanup. argc = argcIn; @@ -338,9 +348,7 @@ bool wxEntryStart(int& argc, wxChar **argv) // the MSW one, using the entire (wide) string command line do it, but if // this function is called directly from the application initialization // code this wouldn't be the case, and we need to handle this too - auto& initData = wxInitData::Get(); - if ( !initData.argc ) - initData.InitializeFromWide(argc, argv); + wxInitData::Get().InitIfNecessary(argc, argv); // initialize wxRTTI if ( !DoCommonPreInit() )