Skip to content
Permalink
Browse files

Fix broken sip casting of nested QVectors

Old code was always forcing casting to QgsPointXY, regardless
of actual type
  • Loading branch information
nyalldawson committed Nov 14, 2017
1 parent 857bae4 commit 3ba22545037fe851644cd893df8e257f792aad28
Showing with 14 additions and 14 deletions.
  1. +14 −14 python/core/conversions.sip
@@ -41,15 +41,15 @@ template <TYPE>
if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;

const sipMappedType *qvector_qgspoint = sipFindMappedType("QVector<QgsPointXY>");
const sipMappedType *qvector_type = sipFindMappedType("QVector<TYPE>");

// Set the list elements.
for (int i = 0; i < sipCpp->size(); ++i)
{
QVector<TYPE> *t = new QVector<TYPE>(sipCpp->at(i));
PyObject *tobj;

if ((tobj = sipConvertFromMappedType(t, qvector_qgspoint, sipTransferObj)) == NULL)
if ((tobj = sipConvertFromMappedType(t, qvector_type, sipTransferObj)) == NULL)
{
Py_DECREF(l);
delete t;
@@ -62,7 +62,7 @@ template <TYPE>
%End

%ConvertToTypeCode
const sipMappedType *qvector_qgspoint = sipFindMappedType("QVector<QgsPointXY>");
const sipMappedType *qvector_type = sipFindMappedType("QVector<TYPE>");

// Check the type if that is all that is required.
if (sipIsErr == NULL)
@@ -71,7 +71,7 @@ template <TYPE>
return 0;

for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
if (!sipCanConvertToMappedType(PyList_GET_ITEM(sipPy, i), qvector_qgspoint, SIP_NOT_NONE))
if (!sipCanConvertToMappedType(PyList_GET_ITEM(sipPy, i), qvector_type, SIP_NOT_NONE))
return 0;

return 1;
@@ -84,16 +84,16 @@ template <TYPE>
{
int state;
//TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(PyList_GET_ITEM(sipPy, i), sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
QVector<TYPE> *t = reinterpret_cast< QVector<TYPE> * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qvector_qgspoint, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
QVector<TYPE> *t = reinterpret_cast< QVector<TYPE> * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qvector_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
{
sipReleaseMappedType(t, qvector_qgspoint, state);
sipReleaseMappedType(t, qvector_type, state);
delete ql;
return 0;
}
ql->append(*t);
sipReleaseMappedType(t, qvector_qgspoint, state);
sipReleaseMappedType(t, qvector_type, state);
}

*sipCppPtr = ql;
@@ -118,15 +118,15 @@ template <TYPE>
if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;

const sipMappedType *qvector_qgspoint = sipFindMappedType("QVector<QVector<QgsPointXY> >");
const sipMappedType *qvector_type = sipFindMappedType("QVector<QVector<TYPE> >");

// Set the list elements.
for (int i = 0; i < sipCpp->size(); ++i)
{
QVector<QVector<TYPE> > *t = new QVector<QVector<TYPE> >(sipCpp->at(i));
PyObject *tobj;

if ((tobj = sipConvertFromMappedType(t, qvector_qgspoint, sipTransferObj)) == NULL)
if ((tobj = sipConvertFromMappedType(t, qvector_type, sipTransferObj)) == NULL)
{
Py_DECREF(l);
delete t;
@@ -139,7 +139,7 @@ template <TYPE>

%ConvertToTypeCode

const sipMappedType *qvector_qgspoint = sipFindMappedType("QVector<QVector<QgsPointXY> >");
const sipMappedType *qvector_type = sipFindMappedType("QVector<QVector<TYPE> >");

// Check the type if that is all that is required.
if (sipIsErr == NULL)
@@ -148,7 +148,7 @@ template <TYPE>
return 0;

for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
if (!sipCanConvertToMappedType(PyList_GET_ITEM(sipPy, i), qvector_qgspoint, SIP_NOT_NONE))
if (!sipCanConvertToMappedType(PyList_GET_ITEM(sipPy, i), qvector_type, SIP_NOT_NONE))
return 0;

return 1;
@@ -161,16 +161,16 @@ template <TYPE>
{
int state;
//TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(PyList_GET_ITEM(sipPy, i), sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
QVector<QVector<TYPE> > *t = reinterpret_cast< QVector< QVector<TYPE> > * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qvector_qgspoint, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
QVector<QVector<TYPE> > *t = reinterpret_cast< QVector< QVector<TYPE> > * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qvector_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
{
sipReleaseMappedType(t, qvector_qgspoint, state);
sipReleaseMappedType(t, qvector_type, state);
delete ql;
return 0;
}
ql->append(*t);
sipReleaseMappedType(t, qvector_qgspoint, state);
sipReleaseMappedType(t, qvector_type, state);
}

*sipCppPtr = ql;

0 comments on commit 3ba2254

Please sign in to comment.
You can’t perform that action at this time.