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.

(cherry picked from commit e269b5d1b9)
This commit is contained in:
Jeff Young 2019-08-31 15:18:27 +01:00
parent 82a0eb4413
commit 1ed8912f57
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 );
wxASSERT( (PLUGIN*) row->plugin );
row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ),
row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), aBestEfforts,
row->GetProperties() );
}

View File

@ -140,7 +140,7 @@ static int guessNickname( FP_LIB_TABLE* aTbl, LIB_ID* aFootprintId )
{
wxArrayString fpnames;
aTbl->FootprintEnumerate( fpnames, nicks[libNdx] );
aTbl->FootprintEnumerate( fpnames, nicks[libNdx], true );
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 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.
*/
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

View File

@ -2469,14 +2469,29 @@ void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
void EAGLE_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
const PROPERTIES* aProperties )
bool aBestEfforts, const PROPERTIES* aProperties )
{
wxString errorMsg;
init( aProperties );
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 )
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;
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,
const PROPERTIES* aProperties = NULL ) override;

View File

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

View File

@ -138,11 +138,13 @@ const wxString GITHUB_PLUGIN::GetFileExtension() const
}
void GITHUB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames,
const wxString& aLibraryPath, const PROPERTIES* aProperties )
void GITHUB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
bool aBestEfforts, const PROPERTIES* aProperties )
{
//D(printf("%s: this:%p aLibraryPath:\"%s\"\n", __func__, this, TO_UTF8(aLibraryPath) );)
cacheLib( aLibraryPath, aProperties );
try
{
//D(printf("%s: this:%p aLibPath:\"%s\"\n", __func__, this, TO_UTF8(aLibraryPath) );)
cacheLib( aLibPath, aProperties );
typedef std::set<wxString> MYSET;
@ -152,21 +154,23 @@ void GITHUB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames,
{
wxArrayString locals;
PCB_IO::FootprintEnumerate( locals, m_pretty_dir );
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 )
{
if( !aBestEfforts )
throw ioe;
}
}

View File

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

View File

@ -867,25 +867,26 @@ void GPCB_PLUGIN::validateCache( const wxString& aLibraryPath, bool checkModifie
}
void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames,
const wxString& aLibraryPath,
const PROPERTIES* aProperties )
void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
bool aBestEfforts, const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
wxDir dir( aLibraryPath );
wxString errorMsg;
if( !dir.IsOpened() )
{
if( aBestEfforts )
return;
else
{
THROW_IO_ERROR( wxString::Format( _( "footprint library path \"%s\" does not exist" ),
GetChars( aLibraryPath ) ) );
aLibraryPath ) );
}
}
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
{
validateCache( aLibraryPath );
@ -895,14 +896,13 @@ void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames,
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() ) );
}
if( !errorMsg.IsEmpty() )
if( !errorMsg.IsEmpty() && !aBestEfforts )
THROW_IO_ERROR( errorMsg );
}

View File

@ -63,7 +63,7 @@ public:
}
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 wxString& aFootprintName,

View File

@ -353,10 +353,12 @@ public:
*
* @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.
*/
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

View File

@ -1938,20 +1938,18 @@ void PCB_IO::validateCache( const wxString& aLibraryPath, bool checkModified )
}
void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames,
const wxString& aLibraryPath,
const PROPERTIES* aProperties )
void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
bool aBestEfforts, const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
wxDir dir( aLibraryPath );
wxDir dir( aLibPath );
wxString errorMsg;
init( aProperties );
wxString errorMsg;
try
{
validateCache( aLibraryPath );
validateCache( aLibPath );
}
catch( const IO_ERROR& ioe )
{
@ -1961,14 +1959,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
// the library.
const MODULE_MAP& mods = m_cache->GetModules();
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( it->first );
}
if( !errorMsg.IsEmpty() )
if( !errorMsg.IsEmpty() && !aBestEfforts )
THROW_IO_ERROR( errorMsg );
}

View File

@ -119,7 +119,7 @@ public:
const PROPERTIES* aProperties = NULL ) override;
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 wxString& aFootprintName,

View File

@ -3246,10 +3246,10 @@ void LP_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
char* saveptr;
if( !line )
goto L_bad_library;
THROW_IO_ERROR( wxString::Format( _( "File '%s' is empty." ), m_lib_path ) );
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 )
{
@ -3258,18 +3258,12 @@ void LP_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
const char* units = strtok_r( line + SZ( "Units" ), delims, &saveptr );
if( !strcmp( units, "mm" ) )
{
m_owner->diskToBiu = IU_PER_MM;
}
}
else if( TESTLINE( "$INDEX" ) )
return;
}
L_bad_library:
THROW_IO_ERROR( wxString::Format( _( "File \"%s\" is empty or is not a legacy library" ),
m_lib_path.GetData() ) );
}
@ -3409,22 +3403,31 @@ void LEGACY_PLUGIN::cacheLib( const wxString& aLibraryPath )
}
void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames,
const wxString& aLibraryPath,
const PROPERTIES* aProperties )
void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
bool aBestEfforts, const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
wxString errorMsg;
init( aProperties );
cacheLib( aLibraryPath );
const MODULE_MAP& mods = m_cache->m_modules;
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
try
{
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

@ -85,7 +85,7 @@ public:
const PROPERTIES* aProperties = NULL ) override;
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,
const PROPERTIES* aProperties = NULL ) override;

View File

@ -411,7 +411,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveLibraryAs( const wxString& aLibraryPath )
wxArrayString footprints;
cur->FootprintEnumerate( footprints, curLibPath );
cur->FootprintEnumerate( footprints, curLibPath, false );
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,
const PROPERTIES* aProperties )
bool aBestEfforts, const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
not_implemented( this, __FUNCTION__ );

View File

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