From 9230189f6270e4f4ad04a2f16864b929ed0efb61 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 2 Aug 2018 23:15:01 +0100 Subject: [PATCH] Fix thread-safety issue with some global wxStrings. These cause intermittent crashes in footprint loading. See comments in code. (cherry picked from commit 5e8e2570ba141f7cf57767840c5b242ed9590041) --- common/wildcards_and_files_ext.cpp | 56 ++++++++++++------------- include/wildcards_and_files_ext.h | 66 ++++++++++++++++-------------- 2 files changed, 63 insertions(+), 59 deletions(-) diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index 084fcafe2b..a147dda47f 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -68,40 +68,40 @@ static wxString FormatWildcardExt( const wxString& aWildcard ) } -const wxString SchematicSymbolFileExtension( "sym" ); -const wxString SchematicLibraryFileExtension( "lib" ); -const wxString SchematicBackupFileExtension( "bak" ); +const std::string SchematicSymbolFileExtension( "sym" ); +const std::string SchematicLibraryFileExtension( "lib" ); +const std::string SchematicBackupFileExtension( "bak" ); -const wxString VrmlFileExtension( "wrl" ); +const std::string VrmlFileExtension( "wrl" ); -const wxString ProjectFileExtension( "pro" ); -const wxString SchematicFileExtension( "sch" ); -const wxString NetlistFileExtension( "net" ); -const wxString ComponentFileExtension( "cmp" ); -const wxString GerberFileExtension( "gbr" ); -const wxString GerberJobFileExtension( "gbrjob" ); -const wxString HtmlFileExtension( wxT( "html" ) ); +const std::string ProjectFileExtension( "pro" ); +const std::string SchematicFileExtension( "sch" ); +const std::string NetlistFileExtension( "net" ); +const std::string ComponentFileExtension( "cmp" ); +const std::string GerberFileExtension( "gbr" ); +const std::string GerberJobFileExtension( "gbrjob" ); +const std::string HtmlFileExtension( "html" ); -const wxString LegacyPcbFileExtension( "brd" ); -const wxString KiCadPcbFileExtension( "kicad_pcb" ); -const wxString PageLayoutDescrFileExtension( "kicad_wks" ); +const std::string LegacyPcbFileExtension( "brd" ); +const std::string KiCadPcbFileExtension( "kicad_pcb" ); +const std::string PageLayoutDescrFileExtension( "kicad_wks" ); -const wxString PdfFileExtension( "pdf" ); -const wxString MacrosFileExtension( "mcr" ); -const wxString DrillFileExtension( "drl" ); -const wxString SVGFileExtension( "svg" ); -const wxString ReportFileExtension( "rpt" ); -const wxString FootprintPlaceFileExtension( "pos" ); -const wxString KiCadLib3DShapesPathExtension( "3dshapes" ); ///< 3D shapes default libpath +const std::string PdfFileExtension( "pdf" ); +const std::string MacrosFileExtension( "mcr" ); +const std::string DrillFileExtension( "drl" ); +const std::string SVGFileExtension( "svg" ); +const std::string ReportFileExtension( "rpt" ); +const std::string FootprintPlaceFileExtension( "pos" ); +const std::string KiCadLib3DShapesPathExtension( "3dshapes" ); ///< 3D shapes default libpath -const wxString KiCadFootprintLibPathExtension( "pretty" ); ///< KICAD PLUGIN libpath -const wxString LegacyFootprintLibPathExtension( "mod" ); -const wxString EagleFootprintLibPathExtension( "lbr" ); +const std::string KiCadFootprintLibPathExtension( "pretty" ); ///< KICAD PLUGIN libpath +const std::string LegacyFootprintLibPathExtension( "mod" ); +const std::string EagleFootprintLibPathExtension( "lbr" ); -const wxString KiCadFootprintFileExtension( "kicad_mod" ); -const wxString GedaPcbFootprintLibFileExtension( "fp" ); -const wxString SpecctraDsnFileExtension( "dsn" ); -const wxString IpcD356FileExtension( "d356" ); +const std::string KiCadFootprintFileExtension( "kicad_mod" ); +const std::string GedaPcbFootprintLibFileExtension( "fp" ); +const std::string SpecctraDsnFileExtension( "dsn" ); +const std::string IpcD356FileExtension( "d356" ); const wxString AllFilesWildcard( _( "All files (*)|*" ) ); diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index bc3fbff5c9..5d666aef0e 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -46,42 +46,44 @@ * @{ */ -extern const wxString AllFilesWildcard; +// Do NOT use wxString for these. wxStrings are not thread-safe, even when const. (For the +// curious the UTF8 cacheing strategy puts iterators in a linked list. Insertion and removal +// from the linked list is not thread-safe.) -extern const wxString SchematicSymbolFileExtension; -extern const wxString SchematicLibraryFileExtension; -extern const wxString SchematicBackupFileExtension; +extern const std::string SchematicSymbolFileExtension; +extern const std::string SchematicLibraryFileExtension; +extern const std::string SchematicBackupFileExtension; -extern const wxString VrmlFileExtension; -extern const wxString ProjectFileExtension; -extern const wxString SchematicFileExtension; -extern const wxString NetlistFileExtension; -extern const wxString GerberFileExtension; -extern const wxString GerberJobFileExtension; -extern const wxString HtmlFileExtension; +extern const std::string VrmlFileExtension; +extern const std::string ProjectFileExtension; +extern const std::string SchematicFileExtension; +extern const std::string NetlistFileExtension; +extern const std::string GerberFileExtension; +extern const std::string GerberJobFileExtension; +extern const std::string HtmlFileExtension; -extern const wxString LegacyPcbFileExtension; -extern const wxString KiCadPcbFileExtension; +extern const std::string LegacyPcbFileExtension; +extern const std::string KiCadPcbFileExtension; #define PcbFileExtension KiCadPcbFileExtension // symlink choice -extern const wxString PageLayoutDescrFileExtension; +extern const std::string PageLayoutDescrFileExtension; -extern const wxString LegacyFootprintLibPathExtension; -extern const wxString PdfFileExtension; -extern const wxString MacrosFileExtension; -extern const wxString ComponentFileExtension; -extern const wxString DrillFileExtension; -extern const wxString SVGFileExtension; -extern const wxString ReportFileExtension; -extern const wxString FootprintPlaceFileExtension; -extern const wxString KiCadFootprintFileExtension; -extern const wxString KiCadFootprintLibPathExtension; -extern const wxString GedaPcbFootprintLibFileExtension; -extern const wxString EagleFootprintLibPathExtension; -extern const wxString ComponentFileExtension; -extern const wxString PageLayoutDescrFileExtension; -extern const wxString KiCadLib3DShapesPathExtension; -extern const wxString SpecctraDsnFileExtension; -extern const wxString IpcD356FileExtension; +extern const std::string LegacyFootprintLibPathExtension; +extern const std::string PdfFileExtension; +extern const std::string MacrosFileExtension; +extern const std::string ComponentFileExtension; +extern const std::string DrillFileExtension; +extern const std::string SVGFileExtension; +extern const std::string ReportFileExtension; +extern const std::string FootprintPlaceFileExtension; +extern const std::string KiCadFootprintFileExtension; +extern const std::string KiCadFootprintLibPathExtension; +extern const std::string GedaPcbFootprintLibFileExtension; +extern const std::string EagleFootprintLibPathExtension; +extern const std::string ComponentFileExtension; +extern const std::string PageLayoutDescrFileExtension; +extern const std::string KiCadLib3DShapesPathExtension; +extern const std::string SpecctraDsnFileExtension; +extern const std::string IpcD356FileExtension; /** * @} @@ -98,6 +100,8 @@ extern const wxString IpcD356FileExtension; * @{ */ +extern const wxString AllFilesWildcard; + extern wxString ComponentFileWildcard(); extern wxString PageLayoutDescrFileWildcard(); extern wxString SchematicSymbolFileWildcard();