From 8b6fbbac601b78f0c0413218ec5d48c60bc014ed Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Tue, 8 Jan 2019 09:50:05 +0100 Subject: Improve check when a QFlag is found For the case of the method `addAxis` in the QPolarChart class, the generated code evaluates first the inherited method: QChart::addAxis(QtCharts::QAbstractAxis*,QFlags) instead of the same class method: QPolarChart::addAxis(QtCharts::QAbstractAxis*,QtCharts::QPolarChart::PolarOrientation) The condition to check if an argument was a `QFlags`, was just `PyNumber_Check(...)`, which was too broad, and then any Enum would pass that condition. The change was to include an additional condition to check the type of the EnumType that was passed as argument. Change-Id: I2eebb6f05c097d170a6d61633698444f03f20b02 Fixes: PYSIDE-898 Reviewed-by: Friedemann Kleint --- sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 8c433ce82..f619020d5 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -1207,9 +1207,18 @@ void CppGenerator::writeEnumConverterFunctions(QTextStream& s, const TypeEntry* c << INDENT << "Shiboken::AutoDecRef pyLong(PyNumber_Long(pyIn));" << endl; c << INDENT << "*((" << cppTypeName << "*)cppOut) = " << cppTypeName; c << "(QFlag((int)PyLong_AsLong(pyLong.object())));" << endl; + + // PYSIDE-898: Include an additional condition to detect if the type of the + // enum corresponds to the object that is being evaluated. + // Using only `PyNumber_Check(...)` is too permissive, + // then we would have been unable to detect the difference between + // a PolarOrientation and Qt::AlignmentFlag, which was the main + // issue of the bug. + const QString numberCondition = QStringLiteral("PyNumber_Check(pyIn) && ") + pyTypeCheck; writePythonToCppFunction(s, code, QLatin1String("number"), flagsTypeName); - writeIsPythonConvertibleToCppFunction(s, QLatin1String("number"), flagsTypeName, - QLatin1String("PyNumber_Check(pyIn)")); + writeIsPythonConvertibleToCppFunction(s, QLatin1String("number"), flagsTypeName, numberCondition); + + } void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaClass *metaClass, -- cgit v1.2.3