diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-03-26 14:21:55 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-03-27 08:48:31 +0000 |
commit | 63f55c549fd842d179ec2d37ace0e2e660aaeab1 (patch) | |
tree | a3c838ef87fa66335d31c0cfed4a09278b57733f | |
parent | 355dd5fd0b9ec42ec884f99ba0321b3985b070d0 (diff) |
Fix handling of longs exceeding long long max in float conversion
Use PyLong_AsDouble().
Pick-to: 6.5 6.2
Fixes: PYSIDE-2652
Change-Id: I97787ba9dd6cb348e45b43228cad4a87afe54a7b
Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io>
(cherry picked from commit f4f3e5f34a9444fdad1d1aebfb995f6e86b45f8a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 38d240f6f51367788c4436a4094448475332fdc3)
-rw-r--r-- | sources/shiboken6/libshiboken/sbkconverter_p.h | 2 | ||||
-rw-r--r-- | sources/shiboken6/tests/samplebinding/typeconverters_test.py | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/sources/shiboken6/libshiboken/sbkconverter_p.h b/sources/shiboken6/libshiboken/sbkconverter_p.h index fbb124803..c886c9b9f 100644 --- a/sources/shiboken6/libshiboken/sbkconverter_p.h +++ b/sources/shiboken6/libshiboken/sbkconverter_p.h @@ -327,7 +327,7 @@ struct FloatPrimitive : TwoPrimitive<FLOAT> } static void toCpp(PyObject *pyIn, void *cppOut) { - *reinterpret_cast<FLOAT *>(cppOut) = FLOAT(PyLong_AsLongLong(pyIn)); + *reinterpret_cast<FLOAT *>(cppOut) = FLOAT(PyLong_AsDouble(pyIn)); } static PythonToCppFunc isConvertible(PyObject *pyIn) { diff --git a/sources/shiboken6/tests/samplebinding/typeconverters_test.py b/sources/shiboken6/tests/samplebinding/typeconverters_test.py index db68c19bc..987ba6dfd 100644 --- a/sources/shiboken6/tests/samplebinding/typeconverters_test.py +++ b/sources/shiboken6/tests/samplebinding/typeconverters_test.py @@ -177,6 +177,14 @@ class PrimitiveConversionTest(unittest.TestCase): point.setX(large_int) self.assertEqual(round(point.x()), large_int) + def testUnsignedLongLongAsFloat(self): + """PYSIDE-2652: When passing an unsigned long long to a function taking float, + an unsigned 64bit conversion should be done.""" + point = sample.PointF(1, 2) + large_int = 2**63 + point.setX(large_int) + self.assertEqual(round(point.x()), large_int) + if __name__ == '__main__': unittest.main() |