aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-05-02 14:15:13 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-05-03 01:03:58 +0000
commit48b1907da7be37566c76b15333b4172c1335e78e (patch)
tree8138e0867f2784242defcad7fd6d49268609e426
parent77e159e93188eab2b0219a82846c688c097a9ddf (diff)
shiboken6: Fix potential broken __repr__ output when a '.' occurs
Check for the '.' on the type name and not the entire string. Brush up the code a bit. Task-number: PYSIDE-1917 Change-Id: Iba7e5e04920f5ba0007b970faf2abed704d32f13 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 868d8197e326fc9228b980617116076a7af8b374) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 1f15fa9bf..6d28432db 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -6768,18 +6768,19 @@ dbg << )";
s << CPP_SELF_VAR << R"(;
buffer.close();
QByteArray str = buffer.data();
-int idx = str.indexOf('(');
+const auto idx = str.indexOf('(');
+auto *typeName = Py_TYPE(self)->tp_name;
if (idx >= 0)
)";
{
Indentation indent(s);
- s << "str.replace(0, idx, Py_TYPE(self)->tp_name);\n";
+ s << "str.replace(0, idx, typeName);\n";
}
s << "str = str.trimmed();\n"
<< "PyObject *mod = PyDict_GetItem(Py_TYPE(self)->tp_dict, Shiboken::PyMagicName::module());\n";
// PYSIDE-595: The introduction of heap types has the side effect that the module name
// is always prepended to the type name. Therefore the strchr check:
- s << "if (mod && !strchr(str, '.'))\n";
+ s << "if (mod != nullptr && std::strchr(typeName, '.') == nullptr)\n";
{
Indentation indent(s);
s << "return Shiboken::String::fromFormat(\"<%s.%s at %p>\", Shiboken::String::toCString(mod), str.constData(), self);\n";