diff options
-rw-r--r-- | libshiboken/basewrapper.cpp | 8 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 9 |
2 files changed, 10 insertions, 7 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp index 2eaff65cb..d36e00493 100644 --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -57,8 +57,14 @@ void setParent(PyObject* parent, PyObject* child) if (!child || child == Py_None || child == parent) return; - bool parentIsNull = !parent || parent == Py_None; + //Recursive for sequence protocol + if (PySequence_Check(child)) { + for (int i = 0, max = PySequence_Size(child); i < max; ++i) + setParent(parent, PySequence_Fast_GET_ITEM(child, i)); + return; + } + bool parentIsNull = !parent || parent == Py_None; SbkBaseWrapper* parent_ = reinterpret_cast<SbkBaseWrapper*>(parent); SbkBaseWrapper* child_ = reinterpret_cast<SbkBaseWrapper*>(child); if (!child_->parentInfo) diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 32e29742d..75a8e47fe 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -125,12 +125,9 @@ </modify-argument> </modify-function> <modify-function signature="children()const"> - <inject-code class="target" position="end"> - Py_ssize_t max = PyList_GET_SIZE(%PYARG_0); - for (int i = 0; i < max; ++i) { - Shiboken::setParent(%PYSELF, PyList_GET_ITEM(%PYARG_0, i)); - } - </inject-code> + <modify-argument index="return"> + <parent index="this" action="add"/> + </modify-argument> </modify-function> </object-type> <object-type name="ObjectTypeLayout"> |