Workaround an issue where a throw terminates (even when there's a catch for it).

You can trigger it before this fix by running Cvpcb when a .kicad_mod file is
incorrectly set as "Legacy" in your footprint table.
This commit is contained in:
Jeff Young 2019-08-31 15:18:27 +01:00
parent 315a99e0fe
commit e269b5d1b9
18 changed files with 113 additions and 103 deletions

View File

@ -259,11 +259,12 @@ long long FP_LIB_TABLE::GenerateTimestamp( const wxString* aNickname )
} }
void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname ) void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname,
bool aBestEfforts )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), aBestEfforts,
row->GetProperties() ); row->GetProperties() );
} }

View File

@ -54,7 +54,7 @@ static int guessNickname( FP_LIB_TABLE* aTbl, LIB_ID* aFootprintId )
{ {
wxArrayString fpnames; wxArrayString fpnames;
aTbl->FootprintEnumerate( fpnames, nicks[libNdx] ); aTbl->FootprintEnumerate( fpnames, nicks[libNdx], true );
for( unsigned nameNdx = 0; nameNdx<fpnames.size(); ++nameNdx ) for( unsigned nameNdx = 0; nameNdx<fpnames.size(); ++nameNdx )
{ {

View File

@ -147,10 +147,12 @@ public:
* @param aFootprintNames is the list to fill with the footprint names found in \a aNickname * @param aFootprintNames is the list to fill with the footprint names found in \a aNickname
* *
* @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW. * @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
* @param aBestEfforts if true, don't throw on errors
* *
* @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded. * @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
*/ */
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname ); void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname,
bool aBestEfforts );
/** /**
* Generate a hashed timestamp representing the last-mod-times of the library indicated * Generate a hashed timestamp representing the last-mod-times of the library indicated

View File

@ -2486,14 +2486,29 @@ void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
void EAGLE_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, void EAGLE_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties ) bool aBestEfforts, const PROPERTIES* aProperties )
{ {
wxString errorMsg;
init( aProperties ); init( aProperties );
cacheLib( aLibraryPath ); try
{
cacheLib( aLibraryPath );
}
catch( const IO_ERROR& ioe )
{
errorMsg = ioe.What();
}
// Some of the files may have been parsed correctly so we want to add the valid files to
// the library.
for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it ) for( MODULE_CITER it = m_templates.begin(); it != m_templates.end(); ++it )
aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) ); aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
if( !errorMsg.IsEmpty() && !aBestEfforts )
THROW_IO_ERROR( errorMsg );
} }

View File

@ -127,7 +127,7 @@ public:
const wxString GetFileExtension() const override; const wxString GetFileExtension() const override;
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL) override; bool aBestEfforts, const PROPERTIES* aProperties = NULL) override;
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;

View File

@ -261,7 +261,7 @@ bool FOOTPRINT_LIST_IMPL::JoinWorkers()
try try
{ {
m_lib_table->FootprintEnumerate( fpnames, nickname ); m_lib_table->FootprintEnumerate( fpnames, nickname, false );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {

View File

@ -138,34 +138,38 @@ const wxString GITHUB_PLUGIN::GetFileExtension() const
} }
void GITHUB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, void GITHUB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
const wxString& aLibraryPath, const PROPERTIES* aProperties ) bool aBestEfforts, const PROPERTIES* aProperties )
{ {
//D(printf("%s: this:%p aLibraryPath:\"%s\"\n", __func__, this, TO_UTF8(aLibraryPath) );) try
cacheLib( aLibraryPath, aProperties );
typedef std::set<wxString> MYSET;
MYSET unique;
if( m_pretty_dir.size() )
{ {
wxArrayString locals; //D(printf("%s: this:%p aLibPath:\"%s\"\n", __func__, this, TO_UTF8(aLibraryPath) );)
cacheLib( aLibPath, aProperties );
PCB_IO::FootprintEnumerate( locals, m_pretty_dir ); typedef std::set<wxString> MYSET;
for( unsigned i=0; i<locals.GetCount(); ++i ) MYSET unique;
unique.insert( locals[i] );
if( m_pretty_dir.size() )
{
wxArrayString locals;
PCB_IO::FootprintEnumerate( locals, m_pretty_dir, aBestEfforts );
for( unsigned i=0; i<locals.GetCount(); ++i )
unique.insert( locals[i] );
}
for( MODULE_ITER it = m_gh_cache->begin(); it!=m_gh_cache->end(); ++it )
unique.insert( it->first );
for( MYSET::const_iterator it = unique.begin(); it != unique.end(); ++it )
aFootprintNames.Add( *it );
} }
catch( const IO_ERROR& ioe )
for( MODULE_ITER it = m_gh_cache->begin(); it!=m_gh_cache->end(); ++it )
{ {
unique.insert( it->first ); if( !aBestEfforts )
} throw ioe;
for( MYSET::const_iterator it = unique.begin(); it != unique.end(); ++it )
{
aFootprintNames.Add( *it );
} }
} }

View File

@ -167,20 +167,20 @@ public:
const wxString GetFileExtension() const override; const wxString GetFileExtension() const override;
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
const PROPERTIES* aProperties = NULL ) override; bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override;
void PrefetchLib( const wxString& aLibraryPath, void PrefetchLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;
MODULE* FootprintLoad( const wxString& aLibraryPath, MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const wxString& aFootprintName, const PROPERTIES* aProperties ) override; const PROPERTIES* aProperties ) override;
void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;
bool IsFootprintLibWritable( const wxString& aLibraryPath ) override; bool IsFootprintLibWritable( const wxString& aLibraryPath ) override;

View File

@ -867,25 +867,26 @@ void GPCB_PLUGIN::validateCache( const wxString& aLibraryPath, bool checkModifie
} }
void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const wxString& aLibraryPath, bool aBestEfforts, const PROPERTIES* aProperties )
const PROPERTIES* aProperties )
{ {
LOCALE_IO toggle; // toggles on, then off, the C locale. LOCALE_IO toggle; // toggles on, then off, the C locale.
wxDir dir( aLibraryPath ); wxDir dir( aLibraryPath );
wxString errorMsg;
if( !dir.IsOpened() ) if( !dir.IsOpened() )
{ {
THROW_IO_ERROR( wxString::Format( _( "footprint library path \"%s\" does not exist" ), if( aBestEfforts )
GetChars( aLibraryPath ) ) ); return;
else
{
THROW_IO_ERROR( wxString::Format( _( "footprint library path \"%s\" does not exist" ),
aLibraryPath ) );
}
} }
init( aProperties ); init( aProperties );
wxString errorMsg;
// Some of the files may have been parsed correctly so we want to add the valid files to
// the library.
try try
{ {
validateCache( aLibraryPath ); validateCache( aLibraryPath );
@ -895,14 +896,13 @@ void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames,
errorMsg = ioe.What(); errorMsg = ioe.What();
} }
const MODULE_MAP& mods = m_cache->GetModules(); // Some of the files may have been parsed correctly so we want to add the valid files to
// the library.
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it ) for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it )
{
aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) ); aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
}
if( !errorMsg.IsEmpty() ) if( !errorMsg.IsEmpty() && !aBestEfforts )
THROW_IO_ERROR( errorMsg ); THROW_IO_ERROR( errorMsg );
} }

View File

@ -63,7 +63,7 @@ public:
} }
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL) override; bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override;
const MODULE* GetEnumeratedFootprint( const wxString& aLibraryPath, const MODULE* GetEnumeratedFootprint( const wxString& aLibraryPath,
const wxString& aFootprintName, const wxString& aFootprintName,

View File

@ -353,10 +353,12 @@ public:
* *
* @param aFootprintNames is the array of available footprint names inside a library. * @param aFootprintNames is the array of available footprint names inside a library.
* *
* @param aBestEfforts if true, don't throw on errors, just return an empty list.
*
* @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded. * @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded.
*/ */
virtual void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, virtual void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ); bool aBestEfforts, const PROPERTIES* aProperties = NULL );
/** /**
* Generate a timestamp representing all the files in the library (including the library * Generate a timestamp representing all the files in the library (including the library

View File

@ -2028,20 +2028,18 @@ void PCB_IO::validateCache( const wxString& aLibraryPath, bool checkModified )
} }
void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
const wxString& aLibraryPath, bool aBestEfforts, const PROPERTIES* aProperties )
const PROPERTIES* aProperties )
{ {
LOCALE_IO toggle; // toggles on, then off, the C locale. LOCALE_IO toggle; // toggles on, then off, the C locale.
wxDir dir( aLibraryPath ); wxDir dir( aLibPath );
wxString errorMsg;
init( aProperties ); init( aProperties );
wxString errorMsg;
try try
{ {
validateCache( aLibraryPath ); validateCache( aLibPath );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
@ -2051,14 +2049,10 @@ void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames,
// Some of the files may have been parsed correctly so we want to add the valid files to // Some of the files may have been parsed correctly so we want to add the valid files to
// the library. // the library.
const MODULE_MAP& mods = m_cache->GetModules(); for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it )
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
{
aFootprintNames.Add( it->first ); aFootprintNames.Add( it->first );
}
if( !errorMsg.IsEmpty() ) if( !errorMsg.IsEmpty() && !aBestEfforts )
THROW_IO_ERROR( errorMsg ); THROW_IO_ERROR( errorMsg );
} }

View File

@ -121,7 +121,7 @@ public:
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override; bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override;
const MODULE* GetEnumeratedFootprint( const wxString& aLibraryPath, const MODULE* GetEnumeratedFootprint( const wxString& aLibraryPath,
const wxString& aFootprintName, const wxString& aFootprintName,

View File

@ -3269,10 +3269,10 @@ void LP_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
char* saveptr; char* saveptr;
if( !line ) if( !line )
goto L_bad_library; THROW_IO_ERROR( wxString::Format( _( "File '%s' is empty." ), m_lib_path ) );
if( !TESTLINE( "PCBNEW-LibModule-V1" ) ) if( !TESTLINE( "PCBNEW-LibModule-V1" ) )
goto L_bad_library; THROW_IO_ERROR( wxString::Format( _( "File '%s' is not a legacy library." ), m_lib_path ) );
while( ( line = aReader->ReadLine() ) != NULL ) while( ( line = aReader->ReadLine() ) != NULL )
{ {
@ -3281,18 +3281,12 @@ void LP_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
const char* units = strtok_r( line + SZ( "Units" ), delims, &saveptr ); const char* units = strtok_r( line + SZ( "Units" ), delims, &saveptr );
if( !strcmp( units, "mm" ) ) if( !strcmp( units, "mm" ) )
{
m_owner->diskToBiu = IU_PER_MM; m_owner->diskToBiu = IU_PER_MM;
}
} }
else if( TESTLINE( "$INDEX" ) ) else if( TESTLINE( "$INDEX" ) )
return; return;
} }
L_bad_library:
THROW_IO_ERROR( wxString::Format( _( "File \"%s\" is empty or is not a legacy library" ),
m_lib_path.GetData() ) );
} }
@ -3432,22 +3426,31 @@ void LEGACY_PLUGIN::cacheLib( const wxString& aLibraryPath )
} }
void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
const wxString& aLibraryPath, bool aBestEfforts, const PROPERTIES* aProperties )
const PROPERTIES* aProperties )
{ {
LOCALE_IO toggle; // toggles on, then off, the C locale. LOCALE_IO toggle; // toggles on, then off, the C locale.
wxString errorMsg;
init( aProperties ); init( aProperties );
cacheLib( aLibraryPath ); try
const MODULE_MAP& mods = m_cache->m_modules;
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
{ {
aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) ); cacheLib( aLibPath );
} }
catch( const IO_ERROR& ioe )
{
errorMsg = ioe.What();
}
// Some of the files may have been parsed correctly so we want to add the valid files to
// the library.
for( MODULE_CITER it = m_cache->m_modules.begin(); it != m_cache->m_modules.end(); ++it )
aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) );
if( !errorMsg.IsEmpty() && !aBestEfforts )
THROW_IO_ERROR( errorMsg );
} }

View File

@ -84,7 +84,7 @@ public:
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override; bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override;
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;

View File

@ -401,7 +401,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveLibraryAs( const wxString& aLibraryPath )
wxArrayString footprints; wxArrayString footprints;
cur->FootprintEnumerate( footprints, curLibPath ); cur->FootprintEnumerate( footprints, curLibPath, false );
for( unsigned i = 0; i < footprints.size(); ++i ) for( unsigned i = 0; i < footprints.size(); ++i )
{ {

View File

@ -58,7 +58,7 @@ void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* a
void PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, void PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties ) bool aBestEfforts, const PROPERTIES* aProperties )
{ {
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface. // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
not_implemented( this, __FUNCTION__ ); not_implemented( this, __FUNCTION__ );

View File

@ -73,18 +73,7 @@
{ {
wxArrayString footprintNames; wxArrayString footprintNames;
if( aExitOnError ) self->FootprintEnumerate( footprintNames, aLibraryPath, !aExitOnError );
self->FootprintEnumerate( footprintNames, aLibraryPath );
else
{
try
{
self->FootprintEnumerate( footprintNames, aLibraryPath );
}
catch( const IO_ERROR& error )
{
}
}
return footprintNames; return footprintNames;
} }