From 655219636b1500e82d543914045f4cc7ba7db95f Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Thu, 11 Nov 2010 17:45:16 -0200 Subject: Fix bug#436 - "Using a custom QValidator generates a segfault" Reviewer: Marcelo Lira Luciano Wolf --- PySide/QtGui/typesystem_gui_common.xml | 57 ++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'PySide/QtGui') diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml index 7dd9aaeb4..59b8aa14b 100644 --- a/PySide/QtGui/typesystem_gui_common.xml +++ b/PySide/QtGui/typesystem_gui_common.xml @@ -1588,16 +1588,7 @@ - - - - - - - - - - + @@ -1938,16 +1929,7 @@ - - - - - - - - - - + @@ -2287,6 +2269,41 @@ + + QValidator::State %out; + + if (PySequence_Check(%PYARG_0)) { + Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_0, 0)); + int size = PySequence_Fast_GET_SIZE(seq.object()); + + if (size > 1) { + if (Shiboken::Converter<QString>::isConvertible(PySequence_Fast_GET_ITEM(seq.object(), 1))) + %1 = %CONVERTTOCPP[QString](PySequence_Fast_GET_ITEM(seq.object(), 1)); + else + qWarning("%TYPE::%FUNCTION_NAME: Second tuple element is not convertible to unicode."); + } + + if (size > 2) { + if (Shiboken::Converter<int>::isConvertible(PySequence_Fast_GET_ITEM(seq.object(), 2))) + %2 = %CONVERTTOCPP[int](PySequence_Fast_GET_ITEM(seq.object(), 2)); + else + qWarning("%TYPE::%FUNCTION_NAME: Second tuple element is not convertible to int."); + } + %PYARG_0 = PySequence_Fast_GET_ITEM(seq.object(), 0); + Py_INCREF(%PYARG_0); // we need to incref, because "%PYARG_0 = ..." will decref the tuple and the tuple will be decrefed again at the end of this scope. + } + + // check retrun value + if (Shiboken::Converter<QValidator::State>::isConvertible(%PYARG_0)) { + %out = %CONVERTTOCPP[QValidator::State](%PYARG_0); + } else { + PyErr_Format(PyExc_TypeError, "Invalid return value in function %s, expected %s, got %s.", + "QValidator.validate", + "PySide.QtGui.QValidator.State, (PySide.QtGui.QValidator.State,), (PySide.QtGui.QValidator.State, unicode) or (PySide.QtGui.QValidator.State, unicode, int)", + pyResult->ob_type->tp_name); + return QValidator::State(); + } + -- cgit v1.2.3