diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2026-09-16 13:43:11 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2026-09-17 15:24:42 +0000 |
| commit | 3fc44d9c906d1491a56661ceefe9c8967bfbdd23 (patch) | |
| tree | 49d70d278a44d8454dd505cc9bbae1ba22975876 | |
| parent | 06b7c13cc539653093c537d705be23c1a7b462bb (diff) | |
libshiboken: Split out info/debug helper functions from basewrapper.cpp
Task-number: PYSIDE-3308
Change-Id: I0a74c8d5e1588d8a397245da4dc86653d44eb3ff
Reviewed-by: Ece Cinucen <ece.cinucen@qt.io>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
| -rw-r--r-- | sources/shiboken6/libshiboken/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.cpp | 113 | ||||
| -rw-r--r-- | sources/shiboken6/libshiboken/basewrapper_info.cpp | 125 | ||||
| -rw-r--r-- | sources/shiboken6/libshiboken/basewrapper_p.h | 2 |
4 files changed, 128 insertions, 113 deletions
diff --git a/sources/shiboken6/libshiboken/CMakeLists.txt b/sources/shiboken6/libshiboken/CMakeLists.txt index e31b19b03..95ccf0ea3 100644 --- a/sources/shiboken6/libshiboken/CMakeLists.txt +++ b/sources/shiboken6/libshiboken/CMakeLists.txt @@ -58,6 +58,7 @@ set(libshiboken_SOVERSION "${shiboken6_library_so_version}") set(libshiboken_SRC autodecref.h basewrapper.cpp basewrapper.h basewrapper_p.h +basewrapper_info.cpp bindingmanager.cpp bindingmanager.h bufferprocs_py37.cpp bufferprocs_py37.h debugfreehook.cpp debugfreehook.h diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index b90a67547..2387ca110 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -1993,119 +1993,6 @@ SbkConverter *getConverter(PyTypeObject *type) return PepType_SOTP(type)->converter; } -// Helpers for debug / info formatting - -static std::vector<PyTypeObject *> getBases(SbkObject *self) -{ - auto *type = Shiboken::pyType(self); - return ObjectType::isUserType(type) - ? getCppBaseClasses(type) - : std::vector<PyTypeObject *>(1, type); -} - -static bool isValueType(SbkObject *self) -{ - return PepType_SOTP(Shiboken::pyType(self))->type_behaviour == BEHAVIOUR_VALUETYPE; -} - -void _debugFormat(std::ostream &s, SbkObject *self) -{ - assert(self); - auto *d = self->d; - if (!d) { - s << "[Invalid]"; - return; - } - if (d->cptr) { - const std::vector<PyTypeObject *> bases = getBases(self); - for (size_t i = 0, size = bases.size(); i < size; ++i) - s << ", C++: " << bases[i]->tp_name << '/' << self->d->cptr[i]; - } else { - s << " [Deleted]"; - } - if (d->hasOwnership) - s << " [hasOwnership]"; - if (d->containsCppWrapper) - s << " [containsCppWrapper]"; - if (d->validCppObject) - s << " [validCppObject]"; - if (d->cppObjectCreated) - s << " [wasCreatedByPython]"; - s << (isValueType(self) ? " [value]" : " [object]"); - - if (d->parentInfo) { - if (auto *parent = d->parentInfo->parent) - s << ", parent=" << reinterpret_cast<PyObject *>(parent)->ob_type->tp_name - << '/' << parent; - if (!d->parentInfo->children.empty()) - s << ", " << d->parentInfo->children.size() << " child(ren)"; - } - if (d->referredObjects && !d->referredObjects->empty()) - s << ", " << d->referredObjects->size() << " referred object(s)"; -} - -std::string info(SbkObject *self) -{ - std::ostringstream s; - - s << "id................ " << self << '\n'; - if (self->d && self->d->cptr) { - const std::vector<PyTypeObject *> bases = getBases(self); - - s << "C++ address....... "; - for (size_t i = 0, size = bases.size(); i < size; ++i) - s << bases[i]->tp_name << '/' << self->d->cptr[i] << ' '; - s << "\n"; - } - else { - s << "C++ address....... <<Deleted>>\n"; - } - - s << "hasOwnership...... " << bool(self->d->hasOwnership) << "\n" - "containsCppWrapper " << self->d->containsCppWrapper << "\n" - "validCppObject.... " << self->d->validCppObject << "\n" - "wasCreatedByPython " << self->d->cppObjectCreated << "\n" - "value...... " << isValueType(self) << "\n" - "reference count... " << Py_REFCNT(reinterpret_cast<PyObject *>(self)) << '\n'; - - if (self->d->parentInfo && self->d->parentInfo->parent) { - auto *obParent = reinterpret_cast<PyObject *>(self->d->parentInfo->parent); - s << "parent............ <" << Py_TYPE(obParent)->tp_name << " at " << obParent << ">\n"; - } - - if (self->d->parentInfo && !self->d->parentInfo->children.empty()) { - const auto &children = self->d->parentInfo->children; - s << "children.......... [" << children.size() << "] "; - int n = 0; - for (SbkObject *sbkChild : children) { - auto *obChild = reinterpret_cast<PyObject *>(sbkChild); - if (n++ > 5) { - s << "..."; - break; - } - s << '<' << Py_TYPE(obChild)->tp_name << " at " << obChild << "> "; - } - s << '\n'; - } - - if (self->d->referredObjects && !self->d->referredObjects->empty()) { - const Shiboken::RefCountMap &map = *self->d->referredObjects; - s << "referred objects.. "; - std::string lastKey; - for (const auto &p : map) { - if (p.first != lastKey) { - if (!lastKey.empty()) - s << " "; - s << '"' << p.first << "\" => "; - lastKey = p.first; - } - s << '<' << Py_TYPE(p.second)->tp_name << " at " << p.second << "> "; - } - s << '\n'; - } - return s.str(); -} - } // namespace Object } // namespace Shiboken diff --git a/sources/shiboken6/libshiboken/basewrapper_info.cpp b/sources/shiboken6/libshiboken/basewrapper_info.cpp new file mode 100644 index 000000000..c86931059 --- /dev/null +++ b/sources/shiboken6/libshiboken/basewrapper_info.cpp @@ -0,0 +1,125 @@ +// Copyright (C) 2026 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// Qt-Security score:significant reason:default + +#include "basewrapper.h" +#include "basewrapper_p.h" +#include "pep384impl.h" + +#include <iostream> +#include <sstream> + +namespace Shiboken::Object { + +static std::vector<PyTypeObject *> getBases(SbkObject *self) +{ + auto *type = Shiboken::pyType(self); + return ObjectType::isUserType(type) + ? getCppBaseClasses(type) + : std::vector<PyTypeObject *>(1, type); +} + +static bool isValueType(SbkObject *self) +{ + return PepType_SOTP(Shiboken::pyType(self))->type_behaviour == BEHAVIOUR_VALUETYPE; +} + +void _debugFormat(std::ostream &s, SbkObject *self) +{ + assert(self); + auto *d = self->d; + if (!d) { + s << "[Invalid]"; + return; + } + if (d->cptr) { + const std::vector<PyTypeObject *> bases = getBases(self); + for (size_t i = 0, size = bases.size(); i < size; ++i) + s << ", C++: " << bases[i]->tp_name << '/' << self->d->cptr[i]; + } else { + s << " [Deleted]"; + } + if (d->hasOwnership) + s << " [hasOwnership]"; + if (d->containsCppWrapper) + s << " [containsCppWrapper]"; + if (d->validCppObject) + s << " [validCppObject]"; + if (d->cppObjectCreated) + s << " [wasCreatedByPython]"; + s << (isValueType(self) ? " [value]" : " [object]"); + + if (d->parentInfo) { + if (auto *parent = d->parentInfo->parent) + s << ", parent=" << reinterpret_cast<PyObject *>(parent)->ob_type->tp_name + << '/' << parent; + if (!d->parentInfo->children.empty()) + s << ", " << d->parentInfo->children.size() << " child(ren)"; + } + if (d->referredObjects && !d->referredObjects->empty()) + s << ", " << d->referredObjects->size() << " referred object(s)"; +} + +std::string info(SbkObject *self) +{ + std::ostringstream s; + + s << "id................ " << self << '\n'; + if (self->d && self->d->cptr) { + const std::vector<PyTypeObject *> bases = getBases(self); + + s << "C++ address....... "; + for (size_t i = 0, size = bases.size(); i < size; ++i) + s << bases[i]->tp_name << '/' << self->d->cptr[i] << ' '; + s << "\n"; + } + else { + s << "C++ address....... <<Deleted>>\n"; + } + + s << "hasOwnership...... " << bool(self->d->hasOwnership) << "\n" + "containsCppWrapper " << self->d->containsCppWrapper << "\n" + "validCppObject.... " << self->d->validCppObject << "\n" + "wasCreatedByPython " << self->d->cppObjectCreated << "\n" + "value...... " << isValueType(self) << "\n" + "reference count... " << Py_REFCNT(reinterpret_cast<PyObject *>(self)) << '\n'; + + if (self->d->parentInfo && self->d->parentInfo->parent) { + auto *obParent = reinterpret_cast<PyObject *>(self->d->parentInfo->parent); + s << "parent............ <" << Py_TYPE(obParent)->tp_name << " at " << obParent << ">\n"; + } + + if (self->d->parentInfo && !self->d->parentInfo->children.empty()) { + const auto &children = self->d->parentInfo->children; + s << "children.......... [" << children.size() << "] "; + int n = 0; + for (SbkObject *sbkChild : children) { + auto *obChild = reinterpret_cast<PyObject *>(sbkChild); + if (n++ > 5) { + s << "..."; + break; + } + s << '<' << Py_TYPE(obChild)->tp_name << " at " << obChild << "> "; + } + s << '\n'; + } + + if (self->d->referredObjects && !self->d->referredObjects->empty()) { + const Shiboken::RefCountMap &map = *self->d->referredObjects; + s << "referred objects.. "; + std::string lastKey; + for (const auto &p : map) { + if (p.first != lastKey) { + if (!lastKey.empty()) + s << " "; + s << '"' << p.first << "\" => "; + lastKey = p.first; + } + s << '<' << Py_TYPE(p.second)->tp_name << " at " << p.second << "> "; + } + s << '\n'; + } + return s.str(); +} + +} // namespace Shiboken::Object diff --git a/sources/shiboken6/libshiboken/basewrapper_p.h b/sources/shiboken6/libshiboken/basewrapper_p.h index 37327c20f..28ab84325 100644 --- a/sources/shiboken6/libshiboken/basewrapper_p.h +++ b/sources/shiboken6/libshiboken/basewrapper_p.h @@ -135,6 +135,8 @@ std::vector<SbkObject *> splitPyObject(PyObject *pyObj); int getNumberOfCppBaseClasses(PyTypeObject *baseType); +std::vector<PyTypeObject *> getCppBaseClasses(PyTypeObject *baseType); + namespace Object { /** |
