← Back to team overview

kicad-developers team mailing list archive

[PATCH 8/8] 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.
---
 include/pgm_base.h  | 2 --
 kicad/files-io.cpp  | 2 +-
 kicad/kicad.cpp     | 9 ++++++++-
 kicad/mainframe.cpp | 8 ++++----
 kicad/menubar.cpp   | 6 +++---
 kicad/pgm_kicad.h   | 3 ++-
 kicad/prjconfig.cpp | 8 ++++----
 7 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/include/pgm_base.h b/include/pgm_base.h
index e8cc98d..be63634 100644
--- a/include/pgm_base.h
+++ b/include/pgm_base.h
@@ -349,9 +349,7 @@ protected:
 };
 
 
-#if !defined(PGM_KICAD_H_)                  // PGM_KICAD has an alternate
 /// The global Program "get" accessor.
 extern PGM_BASE& Pgm();
-#endif
 
 #endif  // PGM_BASE_H_
diff --git a/kicad/files-io.cpp b/kicad/files-io.cpp
index 40f85b8..1ec505c 100644
--- a/kicad/files-io.cpp
+++ b/kicad/files-io.cpp
@@ -47,7 +47,7 @@
 void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
 {
     wxString fn = GetFileFromHistory( event.GetId(),
-                    _( "KiCad project file" ), &Pgm().GetFileHistory() );
+                    _( "KiCad project file" ), &PgmTop().GetFileHistory() );
 
     if( fn.size() )
     {
diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp
index 6dd3677..180bfb8 100644
--- a/kicad/kicad.cpp
+++ b/kicad/kicad.cpp
@@ -91,7 +91,14 @@ KIFACE_I& Kiface()
 
 static PGM_KICAD program;
 
-PGM_KICAD& Pgm()
+
+PGM_BASE& Pgm()
+{
+    return program;
+}
+
+
+PGM_KICAD& PgmTop()
 {
     return program;
 }
diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp
index 8170396..d4391af 100644
--- a/kicad/mainframe.cpp
+++ b/kicad/mainframe.cpp
@@ -119,7 +119,7 @@ KICAD_MANAGER_FRAME::~KICAD_MANAGER_FRAME()
 
 wxConfigBase* KICAD_MANAGER_FRAME::config()
 {
-    wxConfigBase* ret = Pgm().PgmSettings();
+    wxConfigBase* ret = PgmTop().PgmSettings();
     wxASSERT( ret );
     return ret;
 }
@@ -181,13 +181,13 @@ void KICAD_MANAGER_FRAME::ReCreateTreePrj()
 
 const SEARCH_STACK& KICAD_MANAGER_FRAME::sys_search()
 {
-    return Pgm().SysSearch();
+    return PgmTop().SysSearch();
 }
 
 
 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;
 
-        UpdateFileHistory( GetProjectFileName(), &Pgm().GetFileHistory() );
+        UpdateFileHistory( GetProjectFileName(), &PgmTop().GetFileHistory() );
 
         if( !IsIconized() )   // save main frame position and size
         {
diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp
index e6a8980..57bacf0 100644
--- a/kicad/menubar.cpp
+++ b/kicad/menubar.cpp
@@ -201,7 +201,7 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
     // Before deleting, remove the menus managed by m_fileHistory
     // (the file history will be updated when adding/removing files in history)
     if( openRecentMenu )
-        Pgm().GetFileHistory().RemoveMenu( openRecentMenu );
+        PgmTop().GetFileHistory().RemoveMenu( openRecentMenu );
 
     // Delete all existing menus
     while( menuBar->GetMenuCount() )
@@ -220,8 +220,8 @@ void KICAD_MANAGER_FRAME::ReCreateMenuBar()
 
     // File history
     openRecentMenu = new wxMenu();
-    Pgm().GetFileHistory().UseMenu( openRecentMenu );
-    Pgm().GetFileHistory().AddFilesToMenu( );
+    PgmTop().GetFileHistory().UseMenu( openRecentMenu );
+    PgmTop().GetFileHistory().AddFilesToMenu( );
     AddMenuItem( fileMenu, openRecentMenu,
                  wxID_ANY,
                  _( "Open &Recent" ),
diff --git a/kicad/pgm_kicad.h b/kicad/pgm_kicad.h
index e7ff040..61990d9 100644
--- a/kicad/pgm_kicad.h
+++ b/kicad/pgm_kicad.h
@@ -72,6 +72,7 @@ protected:
 };
 
 
-extern PGM_KICAD&  Pgm();
+extern PGM_KICAD& PgmTop();
+
 
 #endif  // PGM_KICAD_H_
diff --git a/kicad/prjconfig.cpp b/kicad/prjconfig.cpp
index 5e1f3bc..aec2ec5 100644
--- a/kicad/prjconfig.cpp
+++ b/kicad/prjconfig.cpp
@@ -161,7 +161,7 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString& aPrjFullFileName,
 
     // Write settings to project file
     // 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.
     // 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();
     }
 
-    Prj().ConfigLoad( Pgm().SysSearch(), GeneralGroupName, s_KicadManagerParams );
+    Prj().ConfigLoad( PgmTop().SysSearch(), GeneralGroupName, s_KicadManagerParams );
 
     title = wxT( "KiCad " ) + GetBuildVersion() +  wxT( ' ' ) + prj_filename;
 
@@ -336,7 +336,7 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
     SetTitle( title );
 
     if( !prj_filename.IsSameAs( nameless_prj ) )
-        UpdateFileHistory( prj_filename, &Pgm().GetFileHistory() );
+        UpdateFileHistory( prj_filename, &PgmTop().GetFileHistory() );
 
     m_LeftWin->ReCreateTreePrj();
 
@@ -385,7 +385,7 @@ void KICAD_MANAGER_FRAME::OnSaveProject( wxCommandEvent& event )
 
     // was: wxGetApp().WriteProjectConfig( m_ProjectFileName.GetFullPath(),
     //          GeneralGroupName, s_KicadManagerParams );
-    Prj().ConfigSave( Pgm().SysSearch(), GeneralGroupName, s_KicadManagerParams );
+    Prj().ConfigSave( PgmTop().SysSearch(), GeneralGroupName, s_KicadManagerParams );
 }
 
 

References