← Back to team overview

kicad-developers team mailing list archive

[PATCH 10/11] 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 42c8b05..ce75214 100644
--- a/kicad/files-io.cpp
+++ b/kicad/files-io.cpp
@@ -49,7 +49,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 0e220d1..1dcffb4 100644
--- a/kicad/kicad.cpp
+++ b/kicad/kicad.cpp
@@ -89,7 +89,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 ae7c911..5de7cb2 100644
--- a/kicad/mainframe.cpp
+++ b/kicad/mainframe.cpp
@@ -123,7 +123,7 @@ KICAD_MANAGER_FRAME::~KICAD_MANAGER_FRAME()
 
 wxConfigBase* KICAD_MANAGER_FRAME::config()
 {
-    wxConfigBase* ret = Pgm().PgmSettings();
+    wxConfigBase* ret = PgmTop().PgmSettings();
     wxASSERT( ret );
     return ret;
 }
@@ -185,13 +185,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();
 }
 
 
@@ -216,7 +216,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 130b661..8cf8986 100644
--- a/kicad/menubar.cpp
+++ b/kicad/menubar.cpp
@@ -198,7 +198,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() )
@@ -217,8 +217,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 bb1069e..80b8c52 100644
--- a/kicad/pgm_kicad.h
+++ b/kicad/pgm_kicad.h
@@ -71,6 +71,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 c8ed495..b67e758 100644
--- a/kicad/prjconfig.cpp
+++ b/kicad/prjconfig.cpp
@@ -164,7 +164,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
@@ -327,7 +327,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;
 
@@ -339,7 +339,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();
 
@@ -388,7 +388,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 );
 }
 
 

Follow ups

References