Avoid conflicting declaration for Pgm()

This function has two conflicting definitions in the "kicad" executable and
the other wrapper programs. As the kifaces can be loaded from either, this
silently assumes compatible data layout for the PGM_KICAD and PGM_BASE
types when passed by reference, which is valid only when the compiler is
aware of the cast.

If the return type is encoded in the symbol name (such as when using the
MSVC compiler), this also causes an error during linking, as the symbol
names no longer match.
This commit is contained in:
Simon Richter 2016-05-28 12:57:29 -04:00 committed by Chris Pavlina
parent 92a3743590
commit b9a6c4988f
7 changed files with 22 additions and 16 deletions

View File

@ -364,9 +364,7 @@ protected:
}; };
#if !defined(PGM_KICAD_H_) // PGM_KICAD has an alternate
/// The global Program "get" accessor. /// The global Program "get" accessor.
extern PGM_BASE& Pgm(); extern PGM_BASE& Pgm();
#endif
#endif // PGM_BASE_H_ #endif // PGM_BASE_H_

View File

@ -47,7 +47,7 @@
void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
{ {
wxString fn = GetFileFromHistory( event.GetId(), wxString fn = GetFileFromHistory( event.GetId(),
_( "KiCad project file" ), &Pgm().GetFileHistory() ); _( "KiCad project file" ), &PgmTop().GetFileHistory() );
if( fn.size() ) if( fn.size() )
{ {

View File

@ -58,7 +58,14 @@ KIFACE_I& Kiface()
static PGM_KICAD program; static PGM_KICAD program;
PGM_KICAD& Pgm()
PGM_BASE& Pgm()
{
return program;
}
PGM_KICAD& PgmTop()
{ {
return program; return program;
} }

View File

@ -119,7 +119,7 @@ KICAD_MANAGER_FRAME::~KICAD_MANAGER_FRAME()
wxConfigBase* KICAD_MANAGER_FRAME::config() wxConfigBase* KICAD_MANAGER_FRAME::config()
{ {
wxConfigBase* ret = Pgm().PgmSettings(); wxConfigBase* ret = PgmTop().PgmSettings();
wxASSERT( ret ); wxASSERT( ret );
return ret; return ret;
} }
@ -181,13 +181,13 @@ void KICAD_MANAGER_FRAME::ReCreateTreePrj()
const SEARCH_STACK& KICAD_MANAGER_FRAME::sys_search() const SEARCH_STACK& KICAD_MANAGER_FRAME::sys_search()
{ {
return Pgm().SysSearch(); return PgmTop().SysSearch();
} }
wxString KICAD_MANAGER_FRAME::help_name() wxString KICAD_MANAGER_FRAME::help_name()
{ {
return Pgm().GetHelpFileName(); return PgmTop().GetHelpFileName();
} }
@ -212,7 +212,7 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
int px, py; int px, py;
UpdateFileHistory( GetProjectFileName(), &Pgm().GetFileHistory() ); UpdateFileHistory( GetProjectFileName(), &PgmTop().GetFileHistory() );
if( !IsIconized() ) // save main frame position and size if( !IsIconized() ) // save main frame position and size
{ {

View File

@ -201,7 +201,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
// Before deleting, remove the menus managed by m_fileHistory // Before deleting, remove the menus managed by m_fileHistory
// (the file history will be updated when adding/removing files in history) // (the file history will be updated when adding/removing files in history)
if( openRecentMenu ) if( openRecentMenu )
Pgm().GetFileHistory().RemoveMenu( openRecentMenu ); PgmTop().GetFileHistory().RemoveMenu( openRecentMenu );
// Delete all existing menus // Delete all existing menus
while( menuBar->GetMenuCount() ) while( menuBar->GetMenuCount() )
@ -220,8 +220,8 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
// File history // File history
openRecentMenu = new wxMenu(); openRecentMenu = new wxMenu();
Pgm().GetFileHistory().UseMenu( openRecentMenu ); PgmTop().GetFileHistory().UseMenu( openRecentMenu );
Pgm().GetFileHistory().AddFilesToMenu( ); PgmTop().GetFileHistory().AddFilesToMenu( );
AddMenuItem( fileMenu, openRecentMenu, AddMenuItem( fileMenu, openRecentMenu,
wxID_ANY, wxID_ANY,
_( "Open &Recent" ), _( "Open &Recent" ),

View File

@ -72,6 +72,7 @@ protected:
}; };
extern PGM_KICAD& Pgm(); extern PGM_KICAD& PgmTop();
#endif // PGM_KICAD_H_ #endif // PGM_KICAD_H_

View File

@ -161,7 +161,7 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString& aPrjFullFileName,
// Write settings to project file // Write settings to project file
// was: wxGetApp().WriteProjectConfig( aPrjFullFileName, GeneralGroupName, s_KicadManagerParams ); // was: wxGetApp().WriteProjectConfig( aPrjFullFileName, GeneralGroupName, s_KicadManagerParams );
Prj().ConfigSave( Pgm().SysSearch(), GeneralGroupName, s_KicadManagerParams ); Prj().ConfigSave( PgmTop().SysSearch(), GeneralGroupName, s_KicadManagerParams );
// Ensure a "stub" for a schematic root sheet and a board exist. // Ensure a "stub" for a schematic root sheet and a board exist.
// It will avoid messages from the schematic editor or the board editor to create a new file // It will avoid messages from the schematic editor or the board editor to create a new file
@ -324,7 +324,7 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
m_MessagesBox->Clear(); m_MessagesBox->Clear();
} }
Prj().ConfigLoad( Pgm().SysSearch(), GeneralGroupName, s_KicadManagerParams ); Prj().ConfigLoad( PgmTop().SysSearch(), GeneralGroupName, s_KicadManagerParams );
title = wxT( "KiCad " ) + GetBuildVersion() + wxT( ' ' ) + prj_filename; title = wxT( "KiCad " ) + GetBuildVersion() + wxT( ' ' ) + prj_filename;
@ -336,7 +336,7 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
SetTitle( title ); SetTitle( title );
if( !prj_filename.IsSameAs( nameless_prj ) ) if( !prj_filename.IsSameAs( nameless_prj ) )
UpdateFileHistory( prj_filename, &Pgm().GetFileHistory() ); UpdateFileHistory( prj_filename, &PgmTop().GetFileHistory() );
m_LeftWin->ReCreateTreePrj(); m_LeftWin->ReCreateTreePrj();
@ -385,7 +385,7 @@ void KICAD_MANAGER_FRAME::OnSaveProject( wxCommandEvent& event )
// was: wxGetApp().WriteProjectConfig( m_ProjectFileName.GetFullPath(), // was: wxGetApp().WriteProjectConfig( m_ProjectFileName.GetFullPath(),
// GeneralGroupName, s_KicadManagerParams ); // GeneralGroupName, s_KicadManagerParams );
Prj().ConfigSave( Pgm().SysSearch(), GeneralGroupName, s_KicadManagerParams ); Prj().ConfigSave( PgmTop().SysSearch(), GeneralGroupName, s_KicadManagerParams );
} }