From 0a70c8485771ae8cc62faaa775b1db2a5dbd95ef Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Fri, 23 Nov 2018 15:17:48 +0100 Subject: Exclude reverse operations from shift hack An old fix for a QDataStream bug was performing an additional step related reverse operations, to make sure we call them if they were implemented in other classes. This was intended for shift operations. Classes like QVector*, QTransform, and others which include reverse operations like __radd__, and __rmul__ will include this patch too. When implementing a class that inherits from these types, this becomes an infinite loop, which can be solved applying this patch only for shift operations. Due to this change, a QMatrix and a shiboken test needed to be adapted. Change-Id: Ie399837b6435b2cd058648a15f4d5cdff037ac6b Fixes: PYSIDE-192 Reviewed-by: Alexandru Croitor Reviewed-by: Qt CI Bot --- sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml | 8 ++++++-- sources/pyside2/PySide2/glue/qtgui.cpp | 5 +++++ sources/pyside2/tests/QtGui/qmatrix_test.py | 2 +- sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 5 ++++- .../tests/otherbinding/extended_multiply_operator_test.py | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml index 6818612cb..e7d1fc76d 100644 --- a/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml +++ b/sources/pyside2/PySide2/QtGui/typesystem_gui_common.xml @@ -732,6 +732,12 @@ + + + + + + @@ -3100,5 +3106,3 @@ - - diff --git a/sources/pyside2/PySide2/glue/qtgui.cpp b/sources/pyside2/PySide2/glue/qtgui.cpp index 7f638e5cd..b308d7ff1 100644 --- a/sources/pyside2/PySide2/glue/qtgui.cpp +++ b/sources/pyside2/PySide2/glue/qtgui.cpp @@ -435,6 +435,11 @@ PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[%ARG1_TYPE](%1)); %END_ALLOW_THREADS // @snippet qpainter-drawpolygon +// @snippet qmatrix-map-point +QPoint p(%CPPSELF.%FUNCTION_NAME(%1)); +%PYARG_0 = %CONVERTTOPYTHON[QPoint](p); +// @snippet qmatrix-map-point + // @snippet qmatrix4x4 if (PySequence_Size(%PYARG_1) == 16) { float values[16]; diff --git a/sources/pyside2/tests/QtGui/qmatrix_test.py b/sources/pyside2/tests/QtGui/qmatrix_test.py index a917199c1..7cfe9ea60 100644 --- a/sources/pyside2/tests/QtGui/qmatrix_test.py +++ b/sources/pyside2/tests/QtGui/qmatrix_test.py @@ -42,7 +42,7 @@ class QMatrixTest(unittest.TestCase): def testMatrix(self): matrix = QMatrix(11, 12, 21, 22, 100, 200) point = QPoint(3, 3) - self.assertEqual(point * matrix, qpointTimesQMatrix(point, matrix)) + self.assertEqual(matrix.map(point), qpointTimesQMatrix(point, matrix)) def testMatrixWithWrongType(self): matrix = QMatrix(11, 12, 21, 22, 100, 200) diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 393f8a850..adec70dd7 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -1764,6 +1764,7 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction s << endl; /* + * This code is intended for shift operations only: * Make sure reverse <> operators defined in other classes (specially from other modules) * are called. A proper and generic solution would require an reengineering in the operator * system like the extended converters. @@ -1778,7 +1779,9 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction && rfunc->isOperatorOverload(); if (callExtendedReverseOperator) { QString revOpName = ShibokenGenerator::pythonOperatorFunctionName(rfunc).insert(2, QLatin1Char('r')); - if (rfunc->isBinaryOperator()) { + // For custom classes, operations like __radd__ and __rmul__ + // will enter an infinite loop. + if (rfunc->isBinaryOperator() && revOpName.contains(QLatin1String("shift"))) { s << INDENT << "if (!isReverse" << endl; { Indentation indent(INDENT); diff --git a/sources/shiboken2/tests/otherbinding/extended_multiply_operator_test.py b/sources/shiboken2/tests/otherbinding/extended_multiply_operator_test.py index 08541a1f4..0c58fbf5b 100755 --- a/sources/shiboken2/tests/otherbinding/extended_multiply_operator_test.py +++ b/sources/shiboken2/tests/otherbinding/extended_multiply_operator_test.py @@ -57,7 +57,7 @@ class PointOperationsWithNumber(unittest.TestCase): '''sample.Point * other.Number''' pt = Point(2, 7) num = Number(11) - self.assertEqual(pt * num, pt * 11) + self.assertEqual(pt * num.value(), pt * 11) if __name__ == '__main__': unittest.main() -- cgit v1.2.3