diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-03-04 13:04:05 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-03-05 11:16:11 +0100 |
| commit | a7d32524b22fd8ac491d0624d91d828593936d6e (patch) | |
| tree | a3972f01f7b1bdef352342dc7fdeec4db2ae0799 | |
| parent | 6b907a8857ec89e80941a9703f1bf0e0113227b9 (diff) | |
shiboken: Extend debug helpers to output sequences
Change-Id: I9c8b3278ea2c7730d37a37107a2b45262f7416b5
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Tismer <tismer@stackless.com>
| -rw-r--r-- | sources/shiboken2/libshiboken/helper.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sources/shiboken2/libshiboken/helper.cpp b/sources/shiboken2/libshiboken/helper.cpp index c14bde15c..b0f909d39 100644 --- a/sources/shiboken2/libshiboken/helper.cpp +++ b/sources/shiboken2/libshiboken/helper.cpp @@ -47,11 +47,16 @@ #include <stdarg.h> #ifdef _WIN32 +# ifndef NOMINMAX +# define NOMINMAX +# endif # include <windows.h> #else # include <pthread.h> #endif +#include <algorithm> + static void formatPyTypeObject(const PyTypeObject *obj, std::ostream &str) { if (obj) { @@ -84,6 +89,27 @@ static void formatPyTypeObject(const PyTypeObject *obj, std::ostream &str) } } +static void formatPyObject(PyObject *obj, std::ostream &str); + +static void formatPySequence(PyObject *obj, std::ostream &str) +{ + const Py_ssize_t size = PySequence_Size(obj); + const Py_ssize_t printSize = std::min(size, Py_ssize_t(5)); + str << size << " <"; + for (Py_ssize_t i = 0; i < printSize; ++i) { + if (i) + str << ", "; + str << '('; + PyObject *item = PySequence_GetItem(obj, i); + formatPyObject(item, str); + str << ')'; + Py_XDECREF(item); + } + if (printSize < size) + str << ",..."; + str << '>'; +} + static void formatPyObject(PyObject *obj, std::ostream &str) { if (obj) { @@ -100,6 +126,8 @@ static void formatPyObject(PyObject *obj, std::ostream &str) else if (PyString_Check(obj)) str << '"' << PyString_AsString(obj) << '"'; #endif + else if (PySequence_Check(obj)) + formatPySequence(obj, str); else str << "<unknown>"; } else { |
