aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside2/PySide2/QtCore/typesystem_core_common.xml44
-rw-r--r--sources/shiboken2/libshiboken/sbkconverter.cpp5
2 files changed, 38 insertions, 11 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
index 47d43f2eb..488ee068b 100644
--- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
+++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
@@ -430,7 +430,8 @@
%out = ret.isValid() ? ret : QVariant::fromValue<PySide::PyObjectWrapper>(%in);
</add-conversion>
<add-conversion type="PySequence">
- %out = QVariant_convertToVariantList(%in);
+ QVariant ret = QVariant_convertToVariantList(%in);
+ %out = ret.isValid() ? ret : QVariant::fromValue&lt;PySide::PyObjectWrapper&gt;(%in);
</add-conversion>
<add-conversion type="PyObject">
// Is a shiboken type not known by Qt
@@ -480,8 +481,12 @@
}
static QVariant QVariant_convertToValueList(PyObject *list)
{
- if (PySequence_Size(list) &lt; 1)
- return QVariant();
+ if (PySequence_Size(list) &lt; 0) {
+ // clear the error if &lt; 0 which means no length at all
+ PyErr_Clear();
+ return QVariant();
+ }
+
Shiboken::AutoDecRef element(PySequence_GetItem(list, 0));
int typeId;
const char *typeName = QVariant_resolveMetaType(element.cast&lt;PyTypeObject*&gt;(), &amp;typeId);
@@ -505,14 +510,26 @@
static bool QVariant_isStringList(PyObject *list)
{
bool allString = true;
- Shiboken::AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList"));
- Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object());
- for (int i = 0; i &lt; size; ++i) {
- PyObject *item = PySequence_Fast_GET_ITEM(fast.object(), i);
- if (!%CHECKTYPE[QString](item)) {
- allString = false;
- break;
+
+ if (PySequence_Check(list)) {
+ if (PySequence_Size(list) &lt; 0) {
+ // clear the error if &lt; 0 which means no length at all
+ PyErr_Clear();
+ return false;
}
+ Shiboken::AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList"));
+ Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object());
+ for (int i = 0; i &lt; size; ++i) {
+ PyObject *item = PySequence_Fast_GET_ITEM(fast.object(), i);
+ if (!%CHECKTYPE[QString](item)) {
+ allString = false;
+ break;
+ }
+ }
+ } else {
+ // If it is not a list or a derived list class
+ // we assume that will not be a String list neither.
+ allString = false;
}
return allString;
}
@@ -541,6 +558,13 @@
QVariant valueList = QVariant_convertToValueList(list);
if (valueList.isValid())
return valueList;
+
+ if (PySequence_Size(list) &lt; 0) {
+ // clear the error if &lt; 0 which means no length at all
+ PyErr_Clear();
+ return QVariant();
+ }
+
QList&lt;QVariant&gt; lst;
Shiboken::AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList"));
Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object());
diff --git a/sources/shiboken2/libshiboken/sbkconverter.cpp b/sources/shiboken2/libshiboken/sbkconverter.cpp
index d4d3ac899..f1be99a36 100644
--- a/sources/shiboken2/libshiboken/sbkconverter.cpp
+++ b/sources/shiboken2/libshiboken/sbkconverter.cpp
@@ -391,8 +391,11 @@ bool checkSequenceTypes(PyTypeObject* type, PyObject* pyIn)
{
assert(type);
assert(pyIn);
- if (!PySequence_Check(pyIn))
+ if (PySequence_Size(pyIn) < 0) {
+ // clear the error if < 0 which means no length at all
+ PyErr_Clear();
return false;
+ }
const Py_ssize_t size = PySequence_Size(pyIn);
for (Py_ssize_t i = 0; i < size; ++i) {
if (!PyObject_TypeCheck(AutoDecRef(PySequence_GetItem(pyIn, i)), type))