Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #8040. Build error with sip
  • Loading branch information
NathanW2 committed Jun 11, 2013
1 parent 6ddaa3e commit 052669f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions python/core/qgsfeature.sip
Expand Up @@ -22,14 +22,14 @@ typedef QVector<QVariant> QgsAttributes;
// Set the list elements. // Set the list elements.
for (int i = 0; i < sipCpp->size(); ++i) for (int i = 0; i < sipCpp->size(); ++i)
{ {
const QVariant& v = sipCpp->at(i); QVariant* v = new QVariant(sipCpp->at(i));

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Jun 12, 2013

Member

Most likely a memory leak: Use sipConvertFromNewInstance to transfer ownership to python and make sure it gets deleted properly in any other path ( like v->IsNull() )

PyObject *tobj; PyObject *tobj;


if ( v.isNull() ) if ( v->isNull() )
{ {
tobj = Py_None; tobj = Py_None;
} }
else if ((tobj = sipConvertFromType(&v, sipType_QVariant,Py_None)) == NULL) else if ((tobj = sipConvertFromType(v, sipType_QVariant,Py_None)) == NULL)
{ {
return NULL; return NULL;
} }
Expand Down Expand Up @@ -121,15 +121,15 @@ class QgsFeature


if (fieldIdx >= 0) if (fieldIdx >= 0)
{ {
const QVariant& v = sipCpp->attribute(fieldIdx); QVariant& v = sipCpp->attribute(fieldIdx);
if ( v.isNull() ) if ( v.isNull() )
sipRes = Py_None; sipRes = Py_None;
else else
sipRes = sipConvertFromInstance( &v, sipClass_QVariant, Py_None ); sipRes = sipConvertFromInstance( &v, sipClass_QVariant, Py_None );
} }
else if( altfieldIdx >= 0 ) else if( altfieldIdx >= 0 )
{ {
const QVariant& v = sipCpp->attribute(altfieldIdx); QVariant& v = sipCpp->attribute(altfieldIdx);
if ( v.isNull() ) if ( v.isNull() )
sipRes = Py_None; sipRes = Py_None;
else else
Expand Down Expand Up @@ -200,11 +200,11 @@ class QgsFeature
} }
else else
{ {
const QVariant& v = attrs[a0]; QVariant* v = new QVariant(attrs[a0]);
if ( v.isNull() ) if ( v->isNull() )
sipRes = Py_None; sipRes = Py_None;
else else
sipRes = sipConvertFromInstance( &v, sipClass_QVariant, Py_None ); sipRes = sipConvertFromInstance( v, sipClass_QVariant, Py_None );
} }
%End %End


Expand All @@ -218,7 +218,7 @@ class QgsFeature
} }
else else
{ {
const QVariant& v = sipCpp->attribute(fieldIdx); QVariant& v = sipCpp->attribute(fieldIdx);
if ( v.isNull() ) if ( v.isNull() )
sipRes = Py_None; sipRes = Py_None;
else else
Expand Down Expand Up @@ -258,7 +258,7 @@ class QgsFeature
{ {
if ( a1Wrapper == Py_None ) if ( a1Wrapper == Py_None )
{ {
sipCpp->setAttribute(a0, QVariant( QVariant::Int ) ); sipCpp->setAttribute(*a0, QVariant( QVariant::Int ) );
} }
else else
{ {
Expand Down Expand Up @@ -422,7 +422,7 @@ class QgsFeature
{ {
if ( a1Wrapper == Py_None ) if ( a1Wrapper == Py_None )
{ {
sipCpp->setAttribute(a0, QVariant( QVariant::Int ) ); sipCpp->setAttribute(*a0, QVariant( QVariant::Int ) );
} }
else else
{ {
Expand Down Expand Up @@ -463,7 +463,7 @@ class QgsFeature
} }
else else
{ {
const QVariant& v = sipCpp->attribute(fieldIdx); QVariant& v = sipCpp->attribute(fieldIdx);
if ( v.isNull() ) if ( v.isNull() )
sipRes = Py_None; sipRes = Py_None;
else else
Expand Down

1 comment on commit 052669f

@slarosa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Nathan,
just compiled under Linux I am getting:

[ 88%] Building CXX object python/CMakeFiles/python_module_qgis_core.dir/core/sipcorepart3.cpp.o
/home/sam/pacchetti_gis/Quantum-GIS/python/core/qgsfeature.sip: In function ‘PyObject* meth_QgsFeature___getattr__(PyObject*, PyObject*)’:
/home/sam/pacchetti_gis/Quantum-GIS/python/core/qgsfeature.sip:124:47: error: invalid initialization of non-const reference of type ‘QVariant&’ from an rvalue of type ‘QVariant’
/home/sam/pacchetti_gis/Quantum-GIS/python/core/qgsfeature.sip:132:50: error: invalid initialization of non-const reference of type ‘QVariant&’ from an rvalue of type ‘QVariant’
/home/sam/pacchetti_gis/Quantum-GIS/python/core/qgsfeature.sip: In function ‘PyObject* meth_QgsFeature_attribute(PyObject*, PyObject*)’:
/home/sam/pacchetti_gis/Quantum-GIS/python/core/qgsfeature.sip:466:45: error: invalid initialization of non-const reference of type ‘QVariant&’ from an rvalue of type ‘QVariant’
/home/sam/pacchetti_gis/Quantum-GIS/python/core/qgsfeature.sip: In function ‘PyObject* slot_QgsFeature___getitem__(PyObject*, PyObject*)’:
/home/sam/pacchetti_gis/Quantum-GIS/python/core/qgsfeature.sip:221:45: error: invalid initialization of non-const reference of type ‘QVariant&’ from an rvalue of type ‘QVariant’
make[2]: *** [python/CMakeFiles/python_module_qgis_core.dir/core/sipcorepart3.cpp.o] Error 1
make[1]: *** [python/CMakeFiles/python_module_qgis_core.dir/all] Error 2
make: *** [all] Error 2

Please sign in to comment.