Skip to content

Commit 052669f

Browse files
committedJun 11, 2013
Fix #8040. Build error with sip
1 parent 6ddaa3e commit 052669f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
 

‎python/core/qgsfeature.sip

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ typedef QVector<QVariant> QgsAttributes;
2222
// Set the list elements.
2323
for (int i = 0; i < sipCpp->size(); ++i)
2424
{
25-
const QVariant& v = sipCpp->at(i);
25+
QVariant* v = new QVariant(sipCpp->at(i));

Comment on line R25

m-kuhn commented on Jun 12, 2013

@m-kuhn
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() )

Code has comments. Press enter to view.
2626
PyObject *tobj;
2727

28-
if ( v.isNull() )
28+
if ( v->isNull() )
2929
{
3030
tobj = Py_None;
3131
}
32-
else if ((tobj = sipConvertFromType(&v, sipType_QVariant,Py_None)) == NULL)
32+
else if ((tobj = sipConvertFromType(v, sipType_QVariant,Py_None)) == NULL)
3333
{
3434
return NULL;
3535
}
@@ -121,15 +121,15 @@ class QgsFeature
121121

122122
if (fieldIdx >= 0)
123123
{
124-
const QVariant& v = sipCpp->attribute(fieldIdx);
124+
QVariant& v = sipCpp->attribute(fieldIdx);
125125
if ( v.isNull() )
126126
sipRes = Py_None;
127127
else
128128
sipRes = sipConvertFromInstance( &v, sipClass_QVariant, Py_None );
129129
}
130130
else if( altfieldIdx >= 0 )
131131
{
132-
const QVariant& v = sipCpp->attribute(altfieldIdx);
132+
QVariant& v = sipCpp->attribute(altfieldIdx);
133133
if ( v.isNull() )
134134
sipRes = Py_None;
135135
else
@@ -200,11 +200,11 @@ class QgsFeature
200200
}
201201
else
202202
{
203-
const QVariant& v = attrs[a0];
204-
if ( v.isNull() )
203+
QVariant* v = new QVariant(attrs[a0]);
204+
if ( v->isNull() )
205205
sipRes = Py_None;
206206
else
207-
sipRes = sipConvertFromInstance( &v, sipClass_QVariant, Py_None );
207+
sipRes = sipConvertFromInstance( v, sipClass_QVariant, Py_None );
208208
}
209209
%End
210210

@@ -218,7 +218,7 @@ class QgsFeature
218218
}
219219
else
220220
{
221-
const QVariant& v = sipCpp->attribute(fieldIdx);
221+
QVariant& v = sipCpp->attribute(fieldIdx);
222222
if ( v.isNull() )
223223
sipRes = Py_None;
224224
else
@@ -258,7 +258,7 @@ class QgsFeature
258258
{
259259
if ( a1Wrapper == Py_None )
260260
{
261-
sipCpp->setAttribute(a0, QVariant( QVariant::Int ) );
261+
sipCpp->setAttribute(*a0, QVariant( QVariant::Int ) );
262262
}
263263
else
264264
{
@@ -422,7 +422,7 @@ class QgsFeature
422422
{
423423
if ( a1Wrapper == Py_None )
424424
{
425-
sipCpp->setAttribute(a0, QVariant( QVariant::Int ) );
425+
sipCpp->setAttribute(*a0, QVariant( QVariant::Int ) );
426426
}
427427
else
428428
{
@@ -463,7 +463,7 @@ class QgsFeature
463463
}
464464
else
465465
{
466-
const QVariant& v = sipCpp->attribute(fieldIdx);
466+
QVariant& v = sipCpp->attribute(fieldIdx);
467467
if ( v.isNull() )
468468
sipRes = Py_None;
469469
else

1 commit comments

Comments
 (1)

slarosa commented on Jun 11, 2013

@slarosa
Member

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.