Skip to content

Commit

Permalink
[processing] Warn on duplicate output and provider registration
Browse files Browse the repository at this point in the history
And fix associated memory leaks
  • Loading branch information
nyalldawson committed Feb 1, 2018
1 parent 6fa362b commit 216821c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
2 changes: 0 additions & 2 deletions python/plugins/processing/algs/gdal/gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFolderDestination(self.OUTPUT,
self.tr('Output directory')))

self.addOutput(QgsProcessingOutputFolder(self.OUTPUT, self.tr('Output directory')))

def name(self):
return 'gdal2tiles'

Expand Down
2 changes: 0 additions & 2 deletions python/plugins/processing/algs/gdal/retile.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFolderDestination(self.OUTPUT,
self.tr('Output directory')))

self.addOutput(QgsProcessingOutputFolder(self.OUTPUT, self.tr('Output directory')))

output_csv_param = QgsProcessingParameterFileDestination(self.OUTPUT_CSV,
self.tr('CSV file containing the tile(s) georeferencing information'),
'CSV files (*.csv)',
Expand Down
2 changes: 0 additions & 2 deletions python/plugins/processing/algs/qgis/VectorSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFolderDestination(self.OUTPUT,
self.tr('Output directory')))

self.addOutput(QgsProcessingOutputFolder(self.OUTPUT, self.tr('Output directory')))

def name(self):
return 'splitvectorlayer'

Expand Down
7 changes: 5 additions & 2 deletions python/plugins/processing/core/Processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ def initialize():
# Add the basic providers
for c in QgsProcessingProvider.__subclasses__():
p = c()
Processing.BASIC_PROVIDERS.append(p)
QgsApplication.processingRegistry().addProvider(p)
if p.id() in ('native', '3d'):
# c++ providers are already registered
continue
if QgsApplication.processingRegistry().addProvider(p):
Processing.BASIC_PROVIDERS.append(p)
# And initialize
ProcessingConfig.initialize()
ProcessingConfig.readSettings()
Expand Down
5 changes: 5 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ bool QgsProcessingAlgorithm::addParameter( QgsProcessingParameterDefinition *def
if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
{
QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
delete definition;
return false;
}

Expand Down Expand Up @@ -283,7 +284,11 @@ bool QgsProcessingAlgorithm::addOutput( QgsProcessingOutputDefinition *definitio

// check for duplicate named outputs
if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
{
QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
delete definition;
return false;
}

mOutputs << definition;
return true;
Expand Down
8 changes: 8 additions & 0 deletions src/core/processing/qgsprocessingregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ bool QgsProcessingRegistry::addProvider( QgsProcessingProvider *provider )
return false;

if ( mProviders.contains( provider->id() ) )
{
QgsLogger::warning( QStringLiteral( "Duplicate provider %1 registered" ).arg( provider->id() ) );
delete provider;
return false;
}

if ( !provider->load() )
{
QgsLogger::warning( QStringLiteral( "Provider %1 cannot load" ).arg( provider->id() ) );
delete provider;
return false;
}

provider->setParent( this );
mProviders[ provider->id()] = provider;
Expand Down

0 comments on commit 216821c

Please sign in to comment.