Skip to content

Commit

Permalink
Fix possible GIL deadlock when iterating features in python
Browse files Browse the repository at this point in the history
and an exception is thrown
  • Loading branch information
nyalldawson committed Jan 28, 2018
1 parent 285bb06 commit bcbc46b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions python/core/qgsfeatureiterator.sip.in
Expand Up @@ -201,12 +201,15 @@ Wrapper for iterator of features from vector data provider or vector layer

SIP_PYOBJECT __next__();
%MethodCode
QgsFeature *f = new QgsFeature;
if ( sipCpp->nextFeature( *f ) )
sipRes = sipConvertFromType( f, sipType_QgsFeature, Py_None );
std::unique_ptr< QgsFeature > f = qgis::make_unique< QgsFeature >();
bool result = false;
Py_BEGIN_ALLOW_THREADS
result = ( sipCpp->nextFeature( *f ) );
Py_END_ALLOW_THREADS
if ( result )
sipRes = sipConvertFromType( f.release(), sipType_QgsFeature, Py_None );
else
{
delete f;
PyErr_SetString( PyExc_StopIteration, "" );
}
%End
Expand Down
11 changes: 7 additions & 4 deletions src/core/qgsfeatureiterator.h
Expand Up @@ -276,12 +276,15 @@ class CORE_EXPORT QgsFeatureIterator

SIP_PYOBJECT __next__();
% MethodCode
QgsFeature *f = new QgsFeature;
if ( sipCpp->nextFeature( *f ) )
sipRes = sipConvertFromType( f, sipType_QgsFeature, Py_None );
std::unique_ptr< QgsFeature > f = qgis::make_unique< QgsFeature >();
bool result = false;
Py_BEGIN_ALLOW_THREADS
result = ( sipCpp->nextFeature( *f ) );
Py_END_ALLOW_THREADS
if ( result )
sipRes = sipConvertFromType( f.release(), sipType_QgsFeature, Py_None );
else
{
delete f;
PyErr_SetString( PyExc_StopIteration, "" );
}
% End
Expand Down

0 comments on commit bcbc46b

Please sign in to comment.