Skip to content

Commit

Permalink
0001031: PropertyLinkSubList causes crash
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 28, 2013
1 parent 7249ee4 commit c75903c
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/App/PropertyLinks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,31 @@ void PropertyLinkSub::setPyObject(PyObject *value)
DocumentObjectPy *pcObject = (DocumentObjectPy*)value;
setValue(pcObject->getDocumentObjectPtr());
}
else if (Py::Object(value).isTuple()) {
Py::Tuple tup(value);
if (PyObject_TypeCheck(tup[0].ptr(), &(DocumentObjectPy::Type))){
DocumentObjectPy *pcObj = (DocumentObjectPy*)tup[0].ptr();
Py::Sequence list(tup[1]);
std::vector<std::string> vals(list.size());
unsigned int i=0;
for(Py::Sequence::iterator it = list.begin();it!=list.end();++it,++i)
vals[i] = Py::String(*it);

setValue(pcObj->getDocumentObjectPtr(),vals);
else if (PyTuple_Check(value) || PyList_Check(value)) {
Py::Sequence seq(value);
if (PyObject_TypeCheck(seq[0].ptr(), &(DocumentObjectPy::Type))){
DocumentObjectPy *pcObj = (DocumentObjectPy*)seq[0].ptr();
if (seq[1].isString()) {
std::vector<std::string> vals;
vals.push_back((std::string)Py::String(seq[1]));
setValue(pcObj->getDocumentObjectPtr(),vals);
}
else if (seq[1].isSequence()) {
Py::Sequence list(seq[1]);
std::vector<std::string> vals(list.size());
unsigned int i=0;
for (Py::Sequence::iterator it = list.begin();it!=list.end();++it,++i)
vals[i] = Py::String(*it);
setValue(pcObj->getDocumentObjectPtr(),vals);
}
else {
std::string error = std::string("type of second element in tuple must be str or sequence of str");
throw Base::TypeError(error);
}
}
else {
std::string error = std::string("type of first element in tuple must be 'DocumentObject', not ");
error += tup[0].ptr()->ob_type->tp_name;
error += seq[0].ptr()->ob_type->tp_name;
throw Base::TypeError(error);
}
}
Expand Down Expand Up @@ -581,7 +591,7 @@ void PropertyLinkSubList::setPyObject(PyObject *value)
std::vector<std::string> SubNames;
SubNames.reserve(size);

for (Py::Sequence::size_type i=0; i < size; i++) {
for (Py::Sequence::size_type i=0; i<size; i++) {
Py::Object item = list[i];
if (item.isTuple()) {
Py::Tuple tup(item);
Expand Down

0 comments on commit c75903c

Please sign in to comment.