Don't allow default copy c'tor to copy arrays of pointers.

Fixes KICAD-SJ2.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21408
This commit is contained in:
Jeff Young 2025-08-01 21:19:29 +01:00
parent ed40391bde
commit d91cce930f
4 changed files with 55 additions and 72 deletions

View File

@ -135,15 +135,6 @@ JOBSET_DESTINATION::JOBSET_DESTINATION( const wxString& id, JOBSET_DESTINATION_T
} }
JOBSET_DESTINATION::~JOBSET_DESTINATION()
{
for( auto& [name, reporter] : m_lastRunReporters )
delete reporter;
m_lastRunReporters.clear();
}
void JOBSET_DESTINATION::InitOutputHandler() void JOBSET_DESTINATION::InitOutputHandler()
{ {
if( m_type == JOBSET_DESTINATION_T::FOLDER ) if( m_type == JOBSET_DESTINATION_T::FOLDER )

View File

@ -21,15 +21,53 @@
#ifndef JOBS_FILE_H #ifndef JOBS_FILE_H
#define JOBS_FILE_H #define JOBS_FILE_H
#include <reporter.h>
#include <bitmaps/bitmaps_list.h> #include <bitmaps/bitmaps_list.h>
#include <jobs/job.h> #include <jobs/job.h>
#include <jobs/jobs_output.h> #include <jobs/jobs_output.h>
#include <settings/json_settings.h> #include <settings/json_settings.h>
#include <settings/parameters.h> #include <settings/parameters.h>
#include <widgets/wx_progress_reporters.h>
#include <ctime> #include <ctime>
#include <memory> #include <memory>
class REPORTER;
class JOBSET_OUTPUT_REPORTER : public WX_STRING_REPORTER
{
public:
JOBSET_OUTPUT_REPORTER( const wxString& aTempDirPath, PROGRESS_REPORTER* aProgressReporter ) :
m_tempDirPath( aTempDirPath ),
m_includeDebug( false ),
m_progressReporter( aProgressReporter )
{
}
REPORTER& Report( const wxString& aText, SEVERITY aSeverity ) override
{
wxString text( aText );
if( aSeverity == RPT_SEVERITY_DEBUG && !m_includeDebug )
return *this;
if( aSeverity == RPT_SEVERITY_ACTION )
text.Replace( m_tempDirPath, wxEmptyString );
if( m_progressReporter )
{
m_progressReporter->Report( text );
m_progressReporter->KeepRefreshing();
}
return WX_STRING_REPORTER::Report( text, aSeverity );
}
private:
wxString m_tempDirPath;
bool m_includeDebug;
PROGRESS_REPORTER* m_progressReporter;
};
struct KICOMMON_API JOBSET_JOB struct KICOMMON_API JOBSET_JOB
{ {
@ -79,28 +117,26 @@ struct KICOMMON_API JOBSET_DESTINATION
JOBSET_DESTINATION( const wxString& id, JOBSET_DESTINATION_T type ); JOBSET_DESTINATION( const wxString& id, JOBSET_DESTINATION_T type );
~JOBSET_DESTINATION();
void InitOutputHandler(); void InitOutputHandler();
wxString m_id;
JOBSET_DESTINATION_T m_type;
wxString m_description;
std::shared_ptr<JOBS_OUTPUT_HANDLER> m_outputHandler;
std::vector<wxString> m_only;
wxString GetDescription() const; wxString GetDescription() const;
void SetDescription( const wxString& aDescription ); void SetDescription( const wxString& aDescription );
wxString GetPathInfo() const; wxString GetPathInfo() const;
bool operator==( const JOBSET_DESTINATION& rhs ) const;
public:
wxString m_id;
JOBSET_DESTINATION_T m_type;
wxString m_description;
std::shared_ptr<JOBS_OUTPUT_HANDLER> m_outputHandler;
std::vector<wxString> m_only;
///< Transient property, not stored for now ///< Transient property, not stored for now
std::optional<bool> m_lastRunSuccess; std::optional<bool> m_lastRunSuccess;
std::unordered_map<wxString, std::optional<bool>> m_lastRunSuccessMap; std::unordered_map<wxString, std::optional<bool>> m_lastRunSuccessMap;
std::unordered_map<wxString, REPORTER*> m_lastRunReporters; std::unordered_map<wxString, std::shared_ptr<JOBSET_OUTPUT_REPORTER>> m_lastRunReporters;
bool operator==( const JOBSET_DESTINATION& rhs ) const;
}; };

View File

@ -148,16 +148,11 @@ public:
wxString jobId = jobs[itemIndex].m_id; wxString jobId = jobs[itemIndex].m_id;
if( m_destination->m_lastRunReporters.contains( jobId ) ) if( m_destination->m_lastRunReporters.contains( jobId ) )
{ m_textCtrlOutput->SetValue( m_destination->m_lastRunReporters.at( jobId )->GetMessages() );
if( auto* reporter = static_cast<WX_STRING_REPORTER*>( m_destination->m_lastRunReporters[jobId] ) )
m_textCtrlOutput->SetValue( reporter->GetMessages() );
}
else else
{
m_textCtrlOutput->SetValue( _( "No output messages" ) ); m_textCtrlOutput->SetValue( _( "No output messages" ) );
} }
} }
}
private: private:
JOBSET* m_jobsFile; JOBSET* m_jobsFile;

View File

@ -134,42 +134,6 @@ int JOBS_RUNNER::runSpecialCopyFiles( const JOBSET_JOB* aJob, PROJECT* aProject
} }
class JOBSET_OUTPUT_REPORTER : public WX_STRING_REPORTER
{
public:
JOBSET_OUTPUT_REPORTER( const wxString& aTempDirPath, PROGRESS_REPORTER* aProgressReporter ) :
m_tempDirPath( aTempDirPath ),
m_includeDebug( false ),
m_progressReporter( aProgressReporter )
{
}
REPORTER& Report( const wxString& aText, SEVERITY aSeverity ) override
{
wxString text( aText );
if( aSeverity == RPT_SEVERITY_DEBUG && !m_includeDebug )
return *this;
if( aSeverity == RPT_SEVERITY_ACTION )
text.Replace( m_tempDirPath, wxEmptyString );
if( m_progressReporter )
{
m_progressReporter->Report( text );
m_progressReporter->KeepRefreshing();
}
return WX_STRING_REPORTER::Report( text, aSeverity );
}
private:
wxString m_tempDirPath;
bool m_includeDebug;
PROGRESS_REPORTER* m_progressReporter;
};
bool JOBS_RUNNER::RunJobsForDestination( JOBSET_DESTINATION* aDestination, bool aBail ) bool JOBS_RUNNER::RunJobsForDestination( JOBSET_DESTINATION* aDestination, bool aBail )
{ {
bool genOutputs = true; bool genOutputs = true;
@ -182,10 +146,6 @@ bool JOBS_RUNNER::RunJobsForDestination( JOBSET_DESTINATION* aDestination, bool
tmp.AppendDir( KIID().AsString() ); tmp.AppendDir( KIID().AsString() );
aDestination->m_lastRunSuccessMap.clear(); aDestination->m_lastRunSuccessMap.clear();
for( auto& [name, reporter] : aDestination->m_lastRunReporters )
delete reporter;
aDestination->m_lastRunReporters.clear(); aDestination->m_lastRunReporters.clear();
wxString tempDirPath = tmp.GetFullPath(); wxString tempDirPath = tmp.GetFullPath();
@ -270,8 +230,9 @@ bool JOBS_RUNNER::RunJobsForDestination( JOBSET_DESTINATION* aDestination, bool
if( reporterToUse == &NULL_REPORTER::GetInstance() ) if( reporterToUse == &NULL_REPORTER::GetInstance() )
{ {
reporterToUse = new JOBSET_OUTPUT_REPORTER( tempDirPath, m_progressReporter ); aDestination->m_lastRunReporters[job.m_id] = std::make_shared<JOBSET_OUTPUT_REPORTER>( tempDirPath,
aDestination->m_lastRunReporters[job.m_id] = reporterToUse; m_progressReporter );
reporterToUse = aDestination->m_lastRunReporters[job.m_id].get();
} }
int result = CLI::EXIT_CODES::SUCCESS; int result = CLI::EXIT_CODES::SUCCESS;