diff options
Diffstat (limited to 'sources/shiboken6/libshiboken/basewrapper_p.h')
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper_p.h | 178 |
1 files changed, 26 insertions, 152 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper_p.h b/sources/shiboken6/libshiboken/basewrapper_p.h index a832620d6..fb9140793 100644 --- a/sources/shiboken6/libshiboken/basewrapper_p.h +++ b/sources/shiboken6/libshiboken/basewrapper_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt for Python. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 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 #ifndef BASEWRAPPER_P_H #define BASEWRAPPER_P_H @@ -47,6 +11,7 @@ #include <set> #include <string> #include <vector> +#include <iosfwd> struct SbkObject; struct SbkConverter; @@ -65,14 +30,12 @@ using ChildrenList = std::set<SbkObject *>; /// Structure used to store information about object parent and children. struct ParentInfo { - /// Default ctor. - ParentInfo() : parent(nullptr), hasWrapperRef(false) {} /// Pointer to parent object. - SbkObject *parent; + SbkObject *parent = nullptr; /// List of object children. ChildrenList children; /// has internal ref - bool hasWrapperRef; + bool hasWrapperRef = false; }; } // namespace Shiboken @@ -86,6 +49,12 @@ extern "C" */ struct SbkObjectPrivate { + SbkObjectPrivate() noexcept = default; + SbkObjectPrivate(const SbkObjectPrivate &) = delete; + SbkObjectPrivate(SbkObjectPrivate &&o) = delete; + SbkObjectPrivate &operator=(const SbkObjectPrivate &) = delete; + SbkObjectPrivate &operator=(SbkObjectPrivate &&o) = delete; + /// Pointer to the C++ class. void ** cptr; /// True when Python is responsible for freeing the used memory. @@ -132,15 +101,6 @@ struct SbkObjectTypePrivate TypeDiscoveryFuncV2 type_discovery; /// Pointer to a function responsible for deletion of the C++ instance calling the proper destructor. ObjectDestructor cpp_dtor; - /// PYSIDE-1019: Caching the current select Id - unsigned int pyside_reserved_bits : 8; // MSVC has bug with the sign bit! - /// True if this type holds two or more C++ instances, e.g.: a Python class which inherits from two C++ classes. - unsigned int is_multicpp : 1; - /// True if this type was defined by the user. - unsigned int is_user_type : 1; - /// Tells is the type is a value type or an object-type, see BEHAVIOUR_ *constants. - unsigned int type_behaviour : 2; - unsigned int delete_in_main_thread : 1; /// C++ name char *original_name; /// Type user data @@ -148,6 +108,18 @@ struct SbkObjectTypePrivate DeleteUserDataFunc d_func; void (*subtype_init)(PyTypeObject *, PyObject *, PyObject *); const char **propertyStrings; + const char **enumFlagInfo; + PyObject *enumFlagsDict; + PyObject *enumTypeDict; + + /// True if this type holds two or more C++ instances, e.g.: a Python class which inherits from two C++ classes. + unsigned int is_multicpp : 1; + /// True if this type was defined by the user (a class written in Python inheriting + /// a class provided by a Shiboken binding). + unsigned int is_user_type : 1; + /// Tells is the type is a value type or an object-type, see BEHAVIOUR_ *constants. + unsigned int type_behaviour : 2; + unsigned int delete_in_main_thread : 1; }; @@ -171,107 +143,7 @@ struct DestructorEntry **/ std::vector<SbkObject *> splitPyObject(PyObject *pyObj); -/** -* Visitor class used by walkOnClassHierarchy function. -*/ -class HierarchyVisitor -{ -public: - HierarchyVisitor(const HierarchyVisitor &) = delete; - HierarchyVisitor(HierarchyVisitor &&) = delete; - HierarchyVisitor &operator=(const HierarchyVisitor &) = delete; - HierarchyVisitor &operator=(HierarchyVisitor &&) = delete; - - HierarchyVisitor(); - virtual ~HierarchyVisitor(); - - virtual bool visit(PyTypeObject *node) = 0; // return true to terminate -}; - -class BaseCountVisitor : public HierarchyVisitor -{ -public: - bool visit(PyTypeObject *) override; - - int count() const { return m_count; } - -private: - int m_count = 0; -}; - -class BaseAccumulatorVisitor : public HierarchyVisitor -{ -public: - using Result = std::vector<PyTypeObject *>; - - bool visit(PyTypeObject *node) override; - - Result bases() const { return m_bases; } - -private: - Result m_bases; -}; - -class GetIndexVisitor : public HierarchyVisitor -{ -public: - explicit GetIndexVisitor(PyTypeObject *desiredType) : m_desiredType(desiredType) {} - - bool visit(PyTypeObject *node) override; - - int index() const { return m_index; } - -private: - int m_index = -1; - PyTypeObject *m_desiredType; -}; - -/// Collect destructors and C++ instances of each C++ object held by a Python -/// object -class DtorAccumulatorVisitor : public HierarchyVisitor -{ -public: - explicit DtorAccumulatorVisitor(SbkObject *pyObj) : m_pyObject(pyObj) {} - - bool visit(PyTypeObject *node) override; - - using DestructorEntries = std::vector<DestructorEntry>; - - const DestructorEntries &entries() const { return m_entries; } - -private: - DestructorEntries m_entries; - SbkObject *m_pyObject; -}; - -/// \internal Internal function used to walk on classes inheritance trees. -/** -* Walk on class hierarchy using a DFS algorithm. -* For each pure Shiboken type found, HiearchyVisitor::visit is called and the algorithm consider -* all children of this type as visited. -*/ -bool walkThroughClassHierarchy(PyTypeObject *currentType, HierarchyVisitor *visitor); - -inline int getTypeIndexOnHierarchy(PyTypeObject *baseType, PyTypeObject *desiredType) -{ - GetIndexVisitor visitor(desiredType); - walkThroughClassHierarchy(baseType, &visitor); - return visitor.index(); -} - -inline int getNumberOfCppBaseClasses(PyTypeObject *baseType) -{ - BaseCountVisitor visitor; - walkThroughClassHierarchy(baseType, &visitor); - return visitor.count(); -} - -inline std::vector<PyTypeObject *> getCppBaseClasses(PyTypeObject *baseType) -{ - BaseAccumulatorVisitor visitor; - walkThroughClassHierarchy(baseType, &visitor); - return visitor.bases(); -} +int getNumberOfCppBaseClasses(PyTypeObject *baseType); namespace Object { @@ -286,6 +158,8 @@ void clearReferences(SbkObject *self); **/ void deallocData(SbkObject *self, bool doCleanup); + +void _debugFormat(std::ostream &str, SbkObject *self); } // namespace Object } // namespace Shiboken |