aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-08-21 08:24:44 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-08-21 10:12:55 +0000
commit4d9d4ea8396049a840f960f084cb72a82e101099 (patch)
tree0e7460054ca859c73bc843450eecbfe160079964
parent5290e7c04413f5c3426a6d807c9f69122a0d929b (diff)
Fix overflows when passing int to functions taking floats
As a drive-by, introduce a new test class for primitive types. Fixes: PYSIDE-2417 Change-Id: I22d4f04e4d0f95c9220aa9241195bc1747f83d9e Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> (cherry picked from commit f275908ec27214fe7b907c2c4ddbea0024c5490a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/libshiboken/sbkconverter_p.h2
-rw-r--r--sources/shiboken6/tests/samplebinding/typeconverters_test.py11
2 files changed, 12 insertions, 1 deletions
diff --git a/sources/shiboken6/libshiboken/sbkconverter_p.h b/sources/shiboken6/libshiboken/sbkconverter_p.h
index 27126fbb1..dfce57755 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_AsLong(pyIn));
+ *reinterpret_cast<FLOAT *>(cppOut) = FLOAT(PyLong_AsLongLong(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 10b7491b1..14caf9f49 100644
--- a/sources/shiboken6/tests/samplebinding/typeconverters_test.py
+++ b/sources/shiboken6/tests/samplebinding/typeconverters_test.py
@@ -159,12 +159,23 @@ class StringBasedConversionTest(unittest.TestCase):
self.assertTrue(len(result), 1)
self.assertTrue(lst, result[0])
+
+class PrimitiveConversionTest(unittest.TestCase):
+
def testCppPrimitiveType(self):
integers = (12, 34)
result = sample.convertIntegersToCppAndThenToPython(integers[0], integers[1])
for orig, new in zip(integers, result):
self.assertEqual(orig, new)
+ def testLargeIntAsFloat(self):
+ """PYSIDE-2417: When passing an int to a function taking float,
+ a 64bit conversion should be done."""
+ point = sample.PointF(1, 2)
+ large_int = 2**31 + 2
+ point.setX(large_int)
+ self.assertEqual(round(point.x()), large_int)
+
if __name__ == '__main__':
unittest.main()