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
This commit is contained in:
Vadim Zeitlin
2002-05-07 19:56:43 +00:00
parent c924182a96
commit 090a6d7af9
3 changed files with 118 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: app.h // Name: wx/app.h
// Purpose: wxAppBase class and macros used for declaration of wxApp // Purpose: wxAppBase class and macros used for declaration of wxApp
// derived class in the user code // derived class in the user code
// Author: Julian Smart // Author: Julian Smart
@@ -51,6 +51,8 @@ class WXDLLEXPORT wxCmdLineParser;
#include "wx/icon.h" #include "wx/icon.h"
#endif #endif
#include "wx/build.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constants // constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -321,6 +323,11 @@ public:
virtual void OnAssert(const wxChar *file, int line, const wxChar *msg); virtual void OnAssert(const wxChar *file, int line, const wxChar *msg);
#endif // __WXDEBUG__ #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! // deprecated functions, please updae your code to not use them!
// ------------------------------------------------------------- // -------------------------------------------------------------
@@ -539,9 +546,19 @@ public:
#define IMPLEMENT_WX_THEME_SUPPORT #define IMPLEMENT_WX_THEME_SUPPORT
#endif #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 // Use this macro if you want to define your own main() or WinMain() function
// and call wxEntry() from there. // and call wxEntry() from there.
#define IMPLEMENT_APP_NO_MAIN(appname) \ #define IMPLEMENT_APP_NO_MAIN(appname) \
WX_DEFINE_BUILDOPTS() \
wxApp *wxCreateApp() { return new appname; } \ wxApp *wxCreateApp() { return new appname; } \
wxAppInitializer wxTheAppInitializer((wxAppInitializerFunction) wxCreateApp); \ wxAppInitializer wxTheAppInitializer((wxAppInitializerFunction) wxCreateApp); \
appname& wxGetApp() { return *(appname *)wxTheApp; } appname& wxGetApp() { return *(appname *)wxTheApp; }

55
include/wx/build.h Normal file
View File

@@ -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 <vadim@wxwindows.org>
// 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_

View File

@@ -59,6 +59,11 @@
#include "wx/mac/private.h" // includes mac headers #include "wx/mac/private.h" // includes mac headers
#endif #endif
// private functions prototypes
#ifdef __WXDEBUG__
static void LINKAGEMODE SetTraceMasks();
#endif // __WXDEBUG__
// =========================================================================== // ===========================================================================
// implementation // implementation
// =========================================================================== // ===========================================================================
@@ -67,21 +72,17 @@
// initialization and termination // initialization and termination
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#ifdef __WXDEBUG__
static void LINKAGEMODE SetTraceMasks()
{
wxString mask;
if ( wxGetEnv(wxT("WXTRACE"), &mask) )
{
wxStringTokenizer tkn(mask, wxT(","));
while ( tkn.HasMoreTokens() )
wxLog::AddTraceMask(tkn.GetNextToken());
}
}
#endif
wxAppBase::wxAppBase() wxAppBase::wxAppBase()
{ {
// this function is defined by IMPLEMENT_APP() macro in the user code
extern const wxBuildOptions& wxGetBuildOptions();
if ( !CheckBuildOptions(wxGetBuildOptions()) )
{
wxLogFatalError(_T("Mismatch between the program and library build ")
_T("versions detected."));
}
wxTheApp = (wxApp *)this; wxTheApp = (wxApp *)this;
#if WXWIN_COMPATIBILITY_2_2 #if WXWIN_COMPATIBILITY_2_2
@@ -348,8 +349,39 @@ bool wxAppBase::OnCmdLineError(wxCmdLineParser& parser)
// debugging support // 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__ #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 // wxASSERT() helper
bool wxAssertIsEqual(int x, int y) bool wxAssertIsEqual(int x, int y)
{ {