diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-03-26 14:16:58 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-03-26 21:41:12 +0000 |
commit | 355dd5fd0b9ec42ec884f99ba0321b3985b070d0 (patch) | |
tree | 40ddbfbecc8272c8456b443cc44b182d5a8948cd | |
parent | eff0cdf2cdda70135a7c0d5e00fe10f2c399b304 (diff) |
Debug operators: Fix handling of longs exceeding long long max
Use PyLong_AsUnsignedLongLong if an overflow occurs. Use hex
for those large values.
Task-number: PYSIDE-2652
Pick-to: 6.5 6.2
Change-Id: I9c3404cf8b01b1fcda20516c1105797fc512ed53
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit a0f1df9610d692b4d4ee042dcc918f792bde5792)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit e6cf34a692347ec65a32546eb8632e1a91a1ff56)
-rw-r--r-- | sources/pyside6/libpyside/pyside.cpp | 12 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/helper.cpp | 11 |
2 files changed, 18 insertions, 5 deletions
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp index 572341e85..bb71e3446 100644 --- a/sources/pyside6/libpyside/pyside.cpp +++ b/sources/pyside6/libpyside/pyside.cpp @@ -1062,9 +1062,15 @@ static void formatPyObjectValue(PyObject *obj, QDebug &debug) { if (PyType_Check(obj) != 0) debug << "type: \"" << pyTypeName(obj) << '"'; - else if (PyLong_Check(obj) != 0) - debug << PyLong_AsLongLong(obj); - else if (PyFloat_Check(obj) != 0) + else if (PyLong_Check(obj) != 0) { + const auto llv = PyLong_AsLongLong(obj); + if (PyErr_Occurred() != PyExc_OverflowError) { + debug << llv; + } else { + PyErr_Clear(); + debug << "0x" << Qt::hex << PyLong_AsUnsignedLongLong(obj) << Qt::dec; + } + } else if (PyFloat_Check(obj) != 0) debug << PyFloat_AsDouble(obj); else if (PyUnicode_Check(obj) != 0) debug << '"' << pyStringToQString(obj) << '"'; diff --git a/sources/shiboken6/libshiboken/helper.cpp b/sources/shiboken6/libshiboken/helper.cpp index 9c75c00db..56008f990 100644 --- a/sources/shiboken6/libshiboken/helper.cpp +++ b/sources/shiboken6/libshiboken/helper.cpp @@ -332,8 +332,15 @@ static void formatPyObjectHelper(PyObject *obj, std::ostream &str) } formatPyTypeObject(obj->ob_type, str, false); str << ", "; - if (PyLong_Check(obj)) - str << PyLong_AsLong(obj); + if (PyLong_Check(obj)) { + const auto llv = PyLong_AsLongLong(obj); + if (PyErr_Occurred() != PyExc_OverflowError) { + str << llv; + } else { + PyErr_Clear(); + str << "0x" << std::hex << PyLong_AsUnsignedLongLong(obj) << std::dec; + } + } else if (PyFloat_Check(obj)) str << PyFloat_AsDouble(obj); else if (PyUnicode_Check(obj)) |