Fix possible GIL deadlock when iterating features in python

and an exception is thrown
This commit is contained in:
Nyall Dawson 2018-01-27 21:52:55 +10:00
parent 285bb0631b
commit bcbc46b56b
2 changed files with 14 additions and 8 deletions

View File

@ -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

View File

@ -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