From e0954e729dabaad5603d9970d123d6b96ed73463 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 4 Jun 2007 13:39:23 +0000 Subject: [PATCH] rename old wxAppConsole to wxAppConsoleBase and wxAppConsoleUnix to wxAppConsole for consistency with wxAppBase/wxApp and to fix the bug 1729377 (crash when using timers under Unix in console app); also #define wxApp as wxAppConsole instead of declaring it as a real class in console build to avoid problems with ODR violation git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46325 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/app.h | 86 ++++++++++++++++++------------------- include/wx/unix/app.h | 2 +- src/common/appbase.cpp | 96 +++++++++++++++++++++++------------------- src/unix/appunix.cpp | 22 +++------- 4 files changed, 101 insertions(+), 105 deletions(-) diff --git a/include/wx/app.h b/include/wx/app.h index 5dfe9a037d..b82a6efc2d 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -51,15 +51,15 @@ enum }; // ---------------------------------------------------------------------------- -// wxAppConsole: wxApp for non-GUI applications +// wxAppConsoleBase: wxApp for non-GUI applications // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_BASE wxAppConsole : public wxEvtHandler +class WXDLLIMPEXP_BASE wxAppConsoleBase : public wxEvtHandler { public: // ctor and dtor - wxAppConsole(); - virtual ~wxAppConsole(); + wxAppConsoleBase(); + virtual ~wxAppConsoleBase(); // the virtual functions which may/must be overridden in the derived class @@ -208,11 +208,7 @@ public: // return true if we're running event loop, i.e. if the events can // (already) be dispatched - static bool IsMainLoopRunning() - { - const wxAppConsole * const app = GetInstance(); - return app && app->m_mainLoop != NULL; - } + static bool IsMainLoopRunning(); // process all events in the wxPendingEvents list -- it is necessary to // call this function to process posted events. This happens during each @@ -343,9 +339,15 @@ protected: // the application object is a singleton anyhow, there is no sense in // copying it - DECLARE_NO_COPY_CLASS(wxAppConsole) + DECLARE_NO_COPY_CLASS(wxAppConsoleBase) }; +#if defined(__UNIX__) + #include "wx/unix/app.h" +#else + typedef wxAppConsoleBase wxAppConsole; +#endif + // ---------------------------------------------------------------------------- // wxAppBase: the common part of wxApp implementations for all platforms // ---------------------------------------------------------------------------- @@ -537,46 +539,40 @@ protected: inline bool wxAppBase::Initialized() { return true; } #endif // WXWIN_COMPATIBILITY_2_6 -#endif // wxUSE_GUI - // ---------------------------------------------------------------------------- // now include the declaration of the real class // ---------------------------------------------------------------------------- -#if wxUSE_GUI - #if defined(__WXPALMOS__) - #include "wx/palmos/app.h" - #elif defined(__WXMSW__) - #include "wx/msw/app.h" - #elif defined(__WXMOTIF__) - #include "wx/motif/app.h" - #elif defined(__WXMGL__) - #include "wx/mgl/app.h" - #elif defined(__WXDFB__) - #include "wx/dfb/app.h" - #elif defined(__WXGTK20__) - #include "wx/gtk/app.h" - #elif defined(__WXGTK__) - #include "wx/gtk1/app.h" - #elif defined(__WXX11__) - #include "wx/x11/app.h" - #elif defined(__WXMAC__) - #include "wx/mac/app.h" - #elif defined(__WXCOCOA__) - #include "wx/cocoa/app.h" - #elif defined(__WXPM__) - #include "wx/os2/app.h" - #endif +#if defined(__WXPALMOS__) + #include "wx/palmos/app.h" +#elif defined(__WXMSW__) + #include "wx/msw/app.h" +#elif defined(__WXMOTIF__) + #include "wx/motif/app.h" +#elif defined(__WXMGL__) + #include "wx/mgl/app.h" +#elif defined(__WXDFB__) + #include "wx/dfb/app.h" +#elif defined(__WXGTK20__) + #include "wx/gtk/app.h" +#elif defined(__WXGTK__) + #include "wx/gtk1/app.h" +#elif defined(__WXX11__) + #include "wx/x11/app.h" +#elif defined(__WXMAC__) + #include "wx/mac/app.h" +#elif defined(__WXCOCOA__) + #include "wx/cocoa/app.h" +#elif defined(__WXPM__) + #include "wx/os2/app.h" +#endif + #else // !GUI - // wxApp is defined in core and we cannot define another one in wxBase, - // so we create a different class and typedef it to wxApp instead - #if defined(__UNIX__) - #include "wx/unix/app.h" - class wxApp : public wxAppConsoleUnix { }; - #else - // allow using just wxApp (instead of wxAppConsole) in console programs - class wxApp : public wxAppConsole { }; - #endif + +// wxApp is defined in core and we cannot define another one in wxBase, +// so use the preprocessor to allow using wxApp in console programs too +#define wxApp wxAppConsole + #endif // GUI/!GUI // ---------------------------------------------------------------------------- diff --git a/include/wx/unix/app.h b/include/wx/unix/app.h index 98bbeef1af..79b336c7b7 100644 --- a/include/wx/unix/app.h +++ b/include/wx/unix/app.h @@ -12,7 +12,7 @@ #include // wxApp subclass implementing event processing for console applications -class WXDLLIMPEXP_BASE wxAppConsoleUnix : public wxAppConsole +class WXDLLIMPEXP_BASE wxAppConsole : public wxAppConsoleBase { public: // override base class initialization diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index 993d4a8d53..9f3be56cc8 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Name: src/common/appbase.cpp -// Purpose: implements wxAppConsole class +// Purpose: implements wxAppConsoleBase class // Author: Vadim Zeitlin // Modified by: // Created: 19.06.2003 (extracted from common/appcmn.cpp) @@ -110,9 +110,9 @@ // global vars // ---------------------------------------------------------------------------- -wxAppConsole *wxAppConsole::ms_appInstance = NULL; +wxAppConsole *wxAppConsoleBase::ms_appInstance = NULL; -wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL; +wxAppInitializerFunction wxAppConsoleBase::ms_appInitFn = NULL; // ---------------------------------------------------------------------------- // wxEventLoopPtr @@ -122,19 +122,19 @@ wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL; wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopBase) // ============================================================================ -// wxAppConsole implementation +// wxAppConsoleBase implementation // ============================================================================ // ---------------------------------------------------------------------------- // ctor/dtor // ---------------------------------------------------------------------------- -wxAppConsole::wxAppConsole() +wxAppConsoleBase::wxAppConsoleBase() { m_traits = NULL; m_mainLoop = NULL; - ms_appInstance = this; + ms_appInstance = wx_static_cast(wxAppConsole *, this); #ifdef __WXDEBUG__ SetTraceMasks(); @@ -148,7 +148,7 @@ wxAppConsole::wxAppConsole() #endif } -wxAppConsole::~wxAppConsole() +wxAppConsoleBase::~wxAppConsoleBase() { delete m_traits; } @@ -157,7 +157,7 @@ wxAppConsole::~wxAppConsole() // initilization/cleanup // ---------------------------------------------------------------------------- -bool wxAppConsole::Initialize(int& argcOrig, wxChar **argvOrig) +bool wxAppConsoleBase::Initialize(int& argcOrig, wxChar **argvOrig) { #if wxUSE_INTL GetTraits()->SetLocale(); @@ -182,12 +182,12 @@ bool wxAppConsole::Initialize(int& argcOrig, wxChar **argvOrig) return true; } -wxEventLoopBase *wxAppConsole::CreateMainLoop() +wxEventLoopBase *wxAppConsoleBase::CreateMainLoop() { return GetTraits()->CreateEventLoop(); } -void wxAppConsole::CleanUp() +void wxAppConsoleBase::CleanUp() { if ( m_mainLoop ) { @@ -208,7 +208,7 @@ void wxAppConsole::CleanUp() // OnXXX() callbacks // ---------------------------------------------------------------------------- -bool wxAppConsole::OnInit() +bool wxAppConsoleBase::OnInit() { #if wxUSE_CMDLINE_PARSER wxCmdLineParser parser(argc, argv); @@ -238,12 +238,12 @@ bool wxAppConsole::OnInit() return true; } -int wxAppConsole::OnRun() +int wxAppConsoleBase::OnRun() { return MainLoop(); } -int wxAppConsole::OnExit() +int wxAppConsoleBase::OnExit() { #if wxUSE_CONFIG // delete the config object if any (don't use Get() here, but Set() @@ -254,7 +254,7 @@ int wxAppConsole::OnExit() return 0; } -void wxAppConsole::Exit() +void wxAppConsoleBase::Exit() { if (m_mainLoop != NULL) ExitMainLoop(); @@ -266,12 +266,12 @@ void wxAppConsole::Exit() // traits stuff // ---------------------------------------------------------------------------- -wxAppTraits *wxAppConsole::CreateTraits() +wxAppTraits *wxAppConsoleBase::CreateTraits() { return new wxConsoleAppTraits; } -wxAppTraits *wxAppConsole::GetTraits() +wxAppTraits *wxAppConsoleBase::GetTraits() { // FIXME-MT: protect this with a CS? if ( !m_traits ) @@ -288,14 +288,14 @@ wxAppTraits *wxAppConsole::GetTraits() // event processing // ---------------------------------------------------------------------------- -int wxAppConsole::MainLoop() +int wxAppConsoleBase::MainLoop() { wxEventLoopBaseTiedPtr mainLoop(&m_mainLoop, CreateMainLoop()); return m_mainLoop ? m_mainLoop->Run() : -1; } -void wxAppConsole::ExitMainLoop() +void wxAppConsoleBase::ExitMainLoop() { // we should exit from the main event loop, not just any currently active // (e.g. modal dialog) event loop @@ -305,7 +305,7 @@ void wxAppConsole::ExitMainLoop() } } -bool wxAppConsole::Pending() +bool wxAppConsoleBase::Pending() { // use the currently active message loop here, not m_mainLoop, because if // we're showing a modal dialog (with its own event loop) currently the @@ -315,7 +315,7 @@ bool wxAppConsole::Pending() return loop && loop->Pending(); } -bool wxAppConsole::Dispatch() +bool wxAppConsoleBase::Dispatch() { // see comment in Pending() wxEventLoopBase * const loop = wxEventLoopBase::GetActive(); @@ -323,7 +323,7 @@ bool wxAppConsole::Dispatch() return loop && loop->Dispatch(); } -bool wxAppConsole::HasPendingEvents() const +bool wxAppConsoleBase::HasPendingEvents() const { // ensure that we're the only thread to modify the pending events list wxENTER_CRIT_SECT( *wxPendingEventsLocker ); @@ -337,7 +337,15 @@ bool wxAppConsole::HasPendingEvents() const return true; } -void wxAppConsole::ProcessPendingEvents() +/* static */ +bool wxAppConsoleBase::IsMainLoopRunning() +{ + const wxAppConsole * const app = GetInstance(); + + return app && app->m_mainLoop != NULL; +} + +void wxAppConsoleBase::ProcessPendingEvents() { #if wxUSE_THREADS if ( !wxPendingEventsLocker ) @@ -370,13 +378,13 @@ void wxAppConsole::ProcessPendingEvents() wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); } -void wxAppConsole::WakeUpIdle() +void wxAppConsoleBase::WakeUpIdle() { if ( m_mainLoop ) m_mainLoop->WakeUp(); } -bool wxAppConsole::ProcessIdle() +bool wxAppConsoleBase::ProcessIdle() { wxIdleEvent event; @@ -385,7 +393,7 @@ bool wxAppConsole::ProcessIdle() return event.MoreRequested(); } -int wxAppConsole::FilterEvent(wxEvent& WXUNUSED(event)) +int wxAppConsoleBase::FilterEvent(wxEvent& WXUNUSED(event)) { // process the events normally by default return -1; @@ -398,9 +406,9 @@ int wxAppConsole::FilterEvent(wxEvent& WXUNUSED(event)) #if wxUSE_EXCEPTIONS void -wxAppConsole::HandleEvent(wxEvtHandler *handler, - wxEventFunction func, - wxEvent& event) const +wxAppConsoleBase::HandleEvent(wxEvtHandler *handler, + wxEventFunction func, + wxEvent& event) const { // by default, simply call the handler (handler->*func)(event); @@ -412,7 +420,7 @@ wxAppConsole::HandleEvent(wxEvtHandler *handler, #if wxUSE_EXCEPTIONS -bool wxAppConsole::OnExceptionInMainLoop() +bool wxAppConsoleBase::OnExceptionInMainLoop() { throw; @@ -435,7 +443,7 @@ bool wxAppConsole::OnExceptionInMainLoop() #define OPTION_VERBOSE _T("verbose") -void wxAppConsole::OnInitCmdLine(wxCmdLineParser& parser) +void wxAppConsoleBase::OnInitCmdLine(wxCmdLineParser& parser) { // the standard command line options static const wxCmdLineEntryDesc cmdLineDesc[] = @@ -474,7 +482,7 @@ void wxAppConsole::OnInitCmdLine(wxCmdLineParser& parser) parser.SetDesc(cmdLineDesc); } -bool wxAppConsole::OnCmdLineParsed(wxCmdLineParser& parser) +bool wxAppConsoleBase::OnCmdLineParsed(wxCmdLineParser& parser) { #if wxUSE_LOG if ( parser.Found(OPTION_VERBOSE) ) @@ -488,14 +496,14 @@ bool wxAppConsole::OnCmdLineParsed(wxCmdLineParser& parser) return true; } -bool wxAppConsole::OnCmdLineHelp(wxCmdLineParser& parser) +bool wxAppConsoleBase::OnCmdLineHelp(wxCmdLineParser& parser) { parser.Usage(); return false; } -bool wxAppConsole::OnCmdLineError(wxCmdLineParser& parser) +bool wxAppConsoleBase::OnCmdLineError(wxCmdLineParser& parser) { parser.Usage(); @@ -509,8 +517,8 @@ bool wxAppConsole::OnCmdLineError(wxCmdLineParser& parser) // ---------------------------------------------------------------------------- /* static */ -bool wxAppConsole::CheckBuildOptions(const char *optionsSignature, - const char *componentName) +bool wxAppConsoleBase::CheckBuildOptions(const char *optionsSignature, + const char *componentName) { #if 0 // can't use wxLogTrace, not up and running yet printf("checking build options object '%s' (ptr %p) in '%s'\n", @@ -539,19 +547,19 @@ bool wxAppConsole::CheckBuildOptions(const char *optionsSignature, #ifdef __WXDEBUG__ -void wxAppConsole::OnAssertFailure(const wxChar *file, - int line, - const wxChar *func, - const wxChar *cond, - const wxChar *msg) +void wxAppConsoleBase::OnAssertFailure(const wxChar *file, + int line, + const wxChar *func, + const wxChar *cond, + const wxChar *msg) { ShowAssertDialog(file, line, func, cond, msg, GetTraits()); } -void wxAppConsole::OnAssert(const wxChar *file, - int line, - const wxChar *cond, - const wxChar *msg) +void wxAppConsoleBase::OnAssert(const wxChar *file, + int line, + const wxChar *cond, + const wxChar *msg) { OnAssertFailure(file, line, NULL, cond, msg); } diff --git a/src/unix/appunix.cpp b/src/unix/appunix.cpp index 15bff1bd77..db90d98ffe 100644 --- a/src/unix/appunix.cpp +++ b/src/unix/appunix.cpp @@ -12,19 +12,12 @@ #include "wx/log.h" #include "wx/evtloop.h" -//this code should not be compiled when GUI is defined -//(monolithic build issue) -#if !wxUSE_GUI - #include #include -bool wxAppConsoleUnix::Initialize(int& argc, wxChar** argv) +bool wxAppConsole::Initialize(int& argc, wxChar** argv) { - if ( !wxAppConsole::Initialize(argc,argv) ) - return false; - - if ( !m_mainLoop->IsOk() ) + if ( !wxAppConsoleBase::Initialize(argc,argv) ) return false; sigemptyset(&m_signalsCaught); @@ -32,9 +25,9 @@ bool wxAppConsoleUnix::Initialize(int& argc, wxChar** argv) return true; } -void wxAppConsoleUnix::HandleSignal(int signal) +void wxAppConsole::HandleSignal(int signal) { - wxAppConsoleUnix * const app = wxTheApp; + wxAppConsole * const app = wxTheApp; if ( !app ) return; @@ -42,7 +35,7 @@ void wxAppConsoleUnix::HandleSignal(int signal) app->WakeUpIdle(); } -void wxAppConsoleUnix::CheckSignal() +void wxAppConsole::CheckSignal() { for ( SignalHandlerHash::iterator it = m_signalHandlerHash.begin(); it != m_signalHandlerHash.end(); @@ -57,13 +50,13 @@ void wxAppConsoleUnix::CheckSignal() } } -bool wxAppConsoleUnix::SetSignalHandler(int signal, SignalHandler handler) +bool wxAppConsole::SetSignalHandler(int signal, SignalHandler handler) { const bool install = handler != SIG_DFL && handler != SIG_IGN; struct sigaction sa; memset(&sa, 0, sizeof(sa)); - sa.sa_handler = &wxAppConsoleUnix::HandleSignal; + sa.sa_handler = &wxAppConsole::HandleSignal; sa.sa_flags = SA_RESTART; int res = sigaction(signal, &sa, 0); if ( res != 0 ) @@ -80,4 +73,3 @@ bool wxAppConsoleUnix::SetSignalHandler(int signal, SignalHandler handler) return true; } -#endif // !wxUSE_GUI -- 2.47.2