aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-06-25 16:09:20 +0200
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-07-03 07:38:55 +0000
commitffae5fe2f3312fdad7ef5880308dae4fd31fec94 (patch)
tree638f89dd1167da526fcb2bbde304c66a3421ef8b
parentd16894f9bf9a2dfea1204469bf818a2ca7aeaa38 (diff)
Add ownership condition for finite PySequences
After the fix for PYSIDE-441, another issue appeared related to QVariants and PySequences PYSIDE-641, which was related due to the nature of this python data type. The problem had the same root cause, using PySequences assuming they are always finite, but not including the case of a class implementing the __getitem__ method without a length. The fix for PYSIDE-441 did not include the option of having incomplete PySequences, so this change add an extra condition to transfer the ownership of a incomplete PySequence element. Task-number: PYSIDE-671 Change-Id: I72ed1f5ea51c0c5b5a40ec51ab850732eea3c3b9 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken2/libshiboken/basewrapper.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp
index b46fbaef2..ae6b2a68a 100644
--- a/sources/shiboken2/libshiboken/basewrapper.cpp
+++ b/sources/shiboken2/libshiboken/basewrapper.cpp
@@ -828,7 +828,14 @@ Py_hash_t hash(PyObject* pyObj)
static void setSequenceOwnership(PyObject* pyObj, bool owner)
{
- if (PySequence_Check(pyObj)) {
+
+ bool has_length = true;
+ if (PySequence_Size(pyObj) < 0) {
+ PyErr_Clear();
+ has_length = false;
+ }
+
+ if (PySequence_Check(pyObj) && has_length) {
Py_ssize_t size = PySequence_Size(pyObj);
if (size > 0) {
std::list<SbkObject*> objs = splitPyObject(pyObj);