From: Vadim Zeitlin Date: Tue, 7 May 2002 19:56:43 +0000 (+0000) Subject: added wxBuildOptions and check that they are the same for the program and the library... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/090a6d7af9c551cf34c3d50f3a438c6b42e51527 added wxBuildOptions and check that they are the same for the program and the library on startup git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15409 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/app.h b/include/wx/app.h index 226be5346f..801c549d64 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: app.h +// Name: wx/app.h // Purpose: wxAppBase class and macros used for declaration of wxApp // derived class in the user code // Author: Julian Smart @@ -51,6 +51,8 @@ class WXDLLEXPORT wxCmdLineParser; #include "wx/icon.h" #endif +#include "wx/build.h" + // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -321,6 +323,11 @@ public: virtual void OnAssert(const wxChar *file, int line, const wxChar *msg); #endif // __WXDEBUG__ + // check that the wxBuildOptions object (constructed in the application + // itself, usually the one from IMPLEMENT_APP() macro) matches the build + // options of the library and abort if it doesn't + static bool CheckBuildOptions(const wxBuildOptions& buildOptions); + // deprecated functions, please updae your code to not use them! // ------------------------------------------------------------- @@ -539,9 +546,19 @@ public: #define IMPLEMENT_WX_THEME_SUPPORT #endif +// define the build options object for the application which is compared to the +// one used for building the library on the program startup +#define WX_DEFINE_BUILDOPTS() \ + const wxBuildOptions& wxGetBuildOptions() \ + { \ + static wxBuildOptions s_buildOptions; \ + return s_buildOptions; \ + } + // Use this macro if you want to define your own main() or WinMain() function // and call wxEntry() from there. #define IMPLEMENT_APP_NO_MAIN(appname) \ + WX_DEFINE_BUILDOPTS() \ wxApp *wxCreateApp() { return new appname; } \ wxAppInitializer wxTheAppInitializer((wxAppInitializerFunction) wxCreateApp); \ appname& wxGetApp() { return *(appname *)wxTheApp; } diff --git a/include/wx/build.h b/include/wx/build.h new file mode 100644 index 0000000000..58e2a0dd84 --- /dev/null +++ b/include/wx/build.h @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/build.h +// Purpose: wxBuildOptions class declaration +// Author: Vadim Zeitlin +// Modified by: +// Created: 07.05.02 +// RCS-ID: $Id$ +// Copyright: (c) 2002 Vadim Zeitlin +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_BUILD_H_ +#define _WX_BUILD_H_ + +#include "wx/version.h" + +// ---------------------------------------------------------------------------- +// wxBuildOptions +// ---------------------------------------------------------------------------- + +class wxBuildOptions +{ +public: + // the ctor must be inline to get the compilation settings of the code + // which included this header + wxBuildOptions() + { + // debug/release +#ifdef __WXDEBUG__ + m_isDebug = TRUE; +#else + m_isDebug = FALSE; +#endif + + // version: we don't test the micro version as hopefully changes + // between 2 micro versions don't result in fatal compatibility + // problems + m_verMaj = wxMAJOR_VERSION; + m_verMin = wxMINOR_VERSION; + } + +private: + // the version + int m_verMaj, + m_verMin; + + // compiled with __WXDEBUG__? + bool m_isDebug; + + // actually only CheckBuildOptions() should be our friend but well... + friend class wxAppBase; +}; + +#endif // _WX_BUILD_H_ + diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index 314a7654eb..a53be00281 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -59,6 +59,11 @@ #include "wx/mac/private.h" // includes mac headers #endif +// private functions prototypes +#ifdef __WXDEBUG__ + static void LINKAGEMODE SetTraceMasks(); +#endif // __WXDEBUG__ + // =========================================================================== // implementation // =========================================================================== @@ -67,21 +72,17 @@ // initialization and termination // ---------------------------------------------------------------------------- -#ifdef __WXDEBUG__ -static void LINKAGEMODE SetTraceMasks() +wxAppBase::wxAppBase() { - wxString mask; - if ( wxGetEnv(wxT("WXTRACE"), &mask) ) + // this function is defined by IMPLEMENT_APP() macro in the user code + extern const wxBuildOptions& wxGetBuildOptions(); + + if ( !CheckBuildOptions(wxGetBuildOptions()) ) { - wxStringTokenizer tkn(mask, wxT(",")); - while ( tkn.HasMoreTokens() ) - wxLog::AddTraceMask(tkn.GetNextToken()); + wxLogFatalError(_T("Mismatch between the program and library build ") + _T("versions detected.")); } -} -#endif -wxAppBase::wxAppBase() -{ wxTheApp = (wxApp *)this; #if WXWIN_COMPATIBILITY_2_2 @@ -348,8 +349,39 @@ bool wxAppBase::OnCmdLineError(wxCmdLineParser& parser) // debugging support // ---------------------------------------------------------------------------- +/* static */ +bool wxAppBase::CheckBuildOptions(const wxBuildOptions& opts) +{ +#define wxCMP(what) (what == opts.m_ ## what) + + bool +#ifdef __WXDEBUG__ + isDebug = TRUE; +#else + isDebug = FALSE; +#endif + + int verMaj = wxMAJOR_VERSION, + verMin = wxMINOR_VERSION; + + return wxCMP(isDebug) && wxCMP(verMaj) && wxCMP(verMin); + +#undef wxCMP +} + #ifdef __WXDEBUG__ +static void LINKAGEMODE SetTraceMasks() +{ + wxString mask; + if ( wxGetEnv(wxT("WXTRACE"), &mask) ) + { + wxStringTokenizer tkn(mask, wxT(",")); + while ( tkn.HasMoreTokens() ) + wxLog::AddTraceMask(tkn.GetNextToken()); + } +} + // wxASSERT() helper bool wxAssertIsEqual(int x, int y) {