From 5ddf57c150d2289701303195d089b4c1cafad87f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Mar 2021 20:37:09 +0100 Subject: [PATCH] Add wxModule::AreInitialized() This internal function will be useful to check if the modules are already initialized, i.e. if the library is in the "steady state" between the end of the initialization and the beginning of the cleanup phases. --- include/wx/module.h | 5 ++++- src/common/module.cpp | 10 ++++++++++ tests/misc/module.cpp | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/wx/module.h b/include/wx/module.h index 41ef501e7e..1f107029aa 100644 --- a/include/wx/module.h +++ b/include/wx/module.h @@ -47,7 +47,8 @@ public: static void RegisterModule(wxModule *module); static void RegisterModules(); static bool InitializeModules(); - static void CleanUpModules() { DoCleanUpModules(ms_modules); } + static void CleanUpModules(); + static bool AreInitialized() { return ms_areInitialized; } // used by wxObjectLoader when unloading shared libs's @@ -56,6 +57,8 @@ public: protected: static wxModuleList ms_modules; + static bool ms_areInitialized; + // the function to call from constructor of a deriving class add module // dependency which will be initialized before the module and unloaded // after that diff --git a/src/common/module.cpp b/src/common/module.cpp index f72956cf6d..7344cfbd96 100644 --- a/src/common/module.cpp +++ b/src/common/module.cpp @@ -25,6 +25,7 @@ wxIMPLEMENT_ABSTRACT_CLASS(wxModule, wxObject) wxModuleList wxModule::ms_modules; +bool wxModule::ms_areInitialized = false; void wxModule::RegisterModule(wxModule* module) { @@ -178,9 +179,18 @@ bool wxModule::InitializeModules() // remember the real initialisation order ms_modules = initializedModules; + ms_areInitialized = true; + return true; } +void wxModule::CleanUpModules() +{ + DoCleanUpModules(ms_modules); + + ms_areInitialized = false; +} + // Clean up all currently initialized modules void wxModule::DoCleanUpModules(const wxModuleList& modules) { diff --git a/tests/misc/module.cpp b/tests/misc/module.cpp index d05b85ec82..24ee867e28 100644 --- a/tests/misc/module.cpp +++ b/tests/misc/module.cpp @@ -15,6 +15,8 @@ #include "wx/module.h" #include "wx/wxcrt.h" // for wxStrcat() +static bool gs_wasInitialized = wxModule::AreInitialized(); + // ---------------------------------------------------------------------------- // test classes derived from wxModule // ---------------------------------------------------------------------------- @@ -89,6 +91,12 @@ ModuleD::ModuleD() // tests themselves // ---------------------------------------------------------------------------- +TEST_CASE("wxModule::Initialized", "[module]") +{ + CHECK( !gs_wasInitialized ); + CHECK( wxModule::AreInitialized() ); +} + TEST_CASE("wxModule::LoadOrder", "[module]") { // module D is the only one with no dependencies and so should load as first (and so on):