diff options
Diffstat (limited to 'sources/shiboken2/libshiboken/basewrapper.cpp')
-rw-r--r-- | sources/shiboken2/libshiboken/basewrapper.cpp | 322 |
1 files changed, 161 insertions, 161 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index f38b55b56..a12d95982 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt for Python. @@ -58,7 +58,7 @@ #include "voidptr.h" namespace { - void _destroyParentInfo(SbkObject* obj, bool keepReference); + void _destroyParentInfo(SbkObject *obj, bool keepReference); } static void callDestructor(const Shiboken::DtorAccumulatorVisitor::DestructorEntries &dts) @@ -73,15 +73,15 @@ static void callDestructor(const Shiboken::DtorAccumulatorVisitor::DestructorEnt extern "C" { -static void SbkObjectTypeDealloc(PyObject* pyObj); -static PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds); +static void SbkObjectTypeDealloc(PyObject *pyObj); +static PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds); // PYSIDE-908: The function PyType_Modified does not work in PySide, so we need to // explicitly pass __doc__. For __signature__ it _did_ actually work, because // it was not existing before. We add them both for clarity. static PyGetSetDef SbkObjectType_Type_getsetlist[] = { - {const_cast<char*>("__signature__"), (getter)Sbk_TypeGet___signature__}, - {const_cast<char*>("__doc__"), (getter)Sbk_TypeGet___doc__}, + {const_cast<char *>("__signature__"), (getter)Sbk_TypeGet___signature__}, + {const_cast<char *>("__doc__"), (getter)Sbk_TypeGet___doc__}, {nullptr} // Sentinel }; @@ -205,7 +205,7 @@ PyTypeObject *SbkObjectType_TypeF(void) return type; } -static PyObject *SbkObjectGetDict(PyObject* pObj, void *) +static PyObject *SbkObjectGetDict(PyObject *pObj, void *) { SbkObject *obj = reinterpret_cast<SbkObject *>(pObj); if (!obj->ob_dict) @@ -217,23 +217,23 @@ static PyObject *SbkObjectGetDict(PyObject* pObj, void *) } static PyGetSetDef SbkObjectGetSetList[] = { - {const_cast<char*>("__dict__"), SbkObjectGetDict, 0, 0, 0}, + {const_cast<char *>("__dict__"), SbkObjectGetDict, 0, 0, 0}, {0, 0, 0, 0, 0} // Sentinel }; -static int SbkObject_traverse(PyObject* self, visitproc visit, void* arg) +static int SbkObject_traverse(PyObject *self, visitproc visit, void *arg) { - SbkObject* sbkSelf = reinterpret_cast<SbkObject*>(self); + SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self); //Visit children - Shiboken::ParentInfo* pInfo = sbkSelf->d->parentInfo; + Shiboken::ParentInfo *pInfo = sbkSelf->d->parentInfo; if (pInfo) { for (SbkObject *c : pInfo->children) Py_VISIT(c); } //Visit refs - Shiboken::RefCountMap* rInfo = sbkSelf->d->referredObjects; + Shiboken::RefCountMap *rInfo = sbkSelf->d->referredObjects; if (rInfo) { for (auto it = rInfo->begin(), end = rInfo->end(); it != end; ++it) Py_VISIT(it->second); @@ -244,9 +244,9 @@ static int SbkObject_traverse(PyObject* self, visitproc visit, void* arg) return 0; } -static int SbkObject_clear(PyObject* self) +static int SbkObject_clear(PyObject *self) { - SbkObject* sbkSelf = reinterpret_cast<SbkObject*>(self); + SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self); Shiboken::Object::removeParent(sbkSelf); @@ -298,10 +298,10 @@ static int mainThreadDeletionHandler(void *) return 0; } -static void SbkDeallocWrapperCommon(PyObject* pyObj, bool canDelete) +static void SbkDeallocWrapperCommon(PyObject *pyObj, bool canDelete) { - SbkObject* sbkObj = reinterpret_cast<SbkObject*>(pyObj); - PyTypeObject* pyType = Py_TYPE(pyObj); + SbkObject *sbkObj = reinterpret_cast<SbkObject *>(pyObj); + PyTypeObject *pyType = Py_TYPE(pyObj); // Need to decref the type if this is the dealloc func; if type // is subclassed, that dealloc func will decref (see subtype_dealloc @@ -352,7 +352,7 @@ static void SbkDeallocWrapperCommon(PyObject* pyObj, bool canDelete) Shiboken::Object::deallocData(sbkObj, true); callDestructor(visitor.entries()); } else { - void* cptr = sbkObj->d->cptr[0]; + void *cptr = sbkObj->d->cptr[0]; Shiboken::Object::deallocData(sbkObj, true); Shiboken::ThreadStateSaver threadSaver; @@ -368,27 +368,27 @@ static void SbkDeallocWrapperCommon(PyObject* pyObj, bool canDelete) Py_DECREF(pyType); } -void SbkDeallocWrapper(PyObject* pyObj) +void SbkDeallocWrapper(PyObject *pyObj) { SbkDeallocWrapperCommon(pyObj, true); } -void SbkDeallocQAppWrapper(PyObject* pyObj) +void SbkDeallocQAppWrapper(PyObject *pyObj) { SbkDeallocWrapper(pyObj); // PYSIDE-571: make sure to create a singleton deleted qApp. MakeSingletonQAppWrapper(NULL); } -void SbkDeallocWrapperWithPrivateDtor(PyObject* self) +void SbkDeallocWrapperWithPrivateDtor(PyObject *self) { SbkDeallocWrapperCommon(self, false); } -void SbkObjectTypeDealloc(PyObject* pyObj) +void SbkObjectTypeDealloc(PyObject *pyObj) { SbkObjectTypePrivate *sotp = PepType_SOTP(pyObj); - PyTypeObject *type = reinterpret_cast<PyTypeObject*>(pyObj); + auto type = reinterpret_cast<PyTypeObject *>(pyObj); PyObject_GC_UnTrack(pyObj); #ifndef Py_LIMITED_API @@ -411,7 +411,7 @@ void SbkObjectTypeDealloc(PyObject* pyObj) #endif } -PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds) +PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds) { // Check if all bases are new style before calling type.tp_new // Was causing gc assert errors in test_bug704.py when @@ -422,19 +422,19 @@ PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* k // Before we changed to heap types, it was sufficient to remove the // Py_TPFLAGS_BASETYPE flag. That does not work, because PySide does // not respect this flag itself! - PyObject* name; - PyObject* pyBases; - PyObject* dict; - static const char* kwlist[] = { "name", "bases", "dict", 0}; + PyObject *name; + PyObject *pyBases; + PyObject *dict; + static const char *kwlist[] = { "name", "bases", "dict", nullptr}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO!O!:sbktype", (char**)kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO!O!:sbktype", (char **)kwlist, &name, &PyTuple_Type, &pyBases, &PyDict_Type, &dict)) return NULL; for (int i=0, i_max=PyTuple_GET_SIZE(pyBases); i < i_max; i++) { - PyObject* baseType = PyTuple_GET_ITEM(pyBases, i); + PyObject *baseType = PyTuple_GET_ITEM(pyBases, i); #ifndef IS_PY3K if (PyClass_Check(baseType)) { PyErr_Format(PyExc_TypeError, "Invalid base class used in type %s. " @@ -450,14 +450,14 @@ PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* k // The meta type creates a new type when the Python programmer extends a wrapped C++ class. newfunc type_new = reinterpret_cast<newfunc>(PyType_Type.tp_new); - SbkObjectType *newType = reinterpret_cast<SbkObjectType*>(type_new(metatype, args, kwds)); + SbkObjectType *newType = reinterpret_cast<SbkObjectType *>(type_new(metatype, args, kwds)); if (!newType) return 0; Shiboken::ObjectType::initPrivateData(newType); SbkObjectTypePrivate *sotp = PepType_SOTP(newType); - const auto bases = Shiboken::getCppBaseClasses(reinterpret_cast<PyTypeObject*>(newType)); + const auto bases = Shiboken::getCppBaseClasses(reinterpret_cast<PyTypeObject *>(newType)); if (bases.size() == 1) { SbkObjectTypePrivate *parentType = PepType_SOTP(bases.front()); sotp->mi_offsets = parentType->mi_offsets; @@ -489,19 +489,19 @@ PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* k PepType_SOTP(base)->subtype_init(newType, args, kwds); } - return reinterpret_cast<PyObject*>(newType); + return reinterpret_cast<PyObject *>(newType); } static PyObject *_setupNew(SbkObject *self, PyTypeObject *subtype) { - Py_INCREF(reinterpret_cast<PyObject*>(subtype)); - SbkObjectPrivate* d = new SbkObjectPrivate; + Py_INCREF(reinterpret_cast<PyObject *>(subtype)); + auto d = new SbkObjectPrivate; - SbkObjectTypePrivate * sotp = PepType_SOTP(subtype); + SbkObjectTypePrivate *sotp = PepType_SOTP(subtype); int numBases = ((sotp && sotp->is_multicpp) ? Shiboken::getNumberOfCppBaseClasses(subtype) : 1); - d->cptr = new void*[numBases]; - std::memset(d->cptr, 0, sizeof(void*) * size_t(numBases)); + d->cptr = new void *[numBases]; + std::memset(d->cptr, 0, sizeof(void *) *size_t(numBases)); d->hasOwnership = 1; d->containsCppWrapper = 0; d->validCppObject = 0; @@ -511,18 +511,18 @@ static PyObject *_setupNew(SbkObject *self, PyTypeObject *subtype) self->ob_dict = nullptr; self->weakreflist = nullptr; self->d = d; - return reinterpret_cast<PyObject*>(self); + return reinterpret_cast<PyObject *>(self); } -PyObject* SbkObjectTpNew(PyTypeObject *subtype, PyObject *, PyObject *) +PyObject *SbkObjectTpNew(PyTypeObject *subtype, PyObject *, PyObject *) { SbkObject *self = PyObject_GC_New(SbkObject, subtype); PyObject *res = _setupNew(self, subtype); - PyObject_GC_Track(reinterpret_cast<PyObject*>(self)); + PyObject_GC_Track(reinterpret_cast<PyObject *>(self)); return res; } -PyObject* SbkQAppTpNew(PyTypeObject* subtype, PyObject *, PyObject *) +PyObject *SbkQAppTpNew(PyTypeObject *subtype, PyObject *, PyObject *) { // PYSIDE-571: // For qApp, we need to create a singleton Python object. @@ -542,7 +542,7 @@ PyObject* SbkQAppTpNew(PyTypeObject* subtype, PyObject *, PyObject *) subtype->tp_free = PyObject_Del; } #endif - SbkObject* self = reinterpret_cast<SbkObject*>(MakeSingletonQAppWrapper(subtype)); + auto self = reinterpret_cast<SbkObject *>(MakeSingletonQAppWrapper(subtype)); return self == 0 ? 0 : _setupNew(self, subtype); } @@ -553,7 +553,7 @@ object_dealloc(PyObject *self) } PyObject * -SbkDummyNew(PyTypeObject *type, PyObject*, PyObject*) +SbkDummyNew(PyTypeObject *type, PyObject *, PyObject *) { // PYSIDE-595: Give the same error as type_call does when tp_new is NULL. PyErr_Format(PyExc_TypeError, @@ -568,12 +568,12 @@ SbkDummyNew(PyTypeObject *type, PyObject*, PyObject*) namespace { -void _destroyParentInfo(SbkObject* obj, bool keepReference) +void _destroyParentInfo(SbkObject *obj, bool keepReference) { - Shiboken::ParentInfo* pInfo = obj->d->parentInfo; + Shiboken::ParentInfo *pInfo = obj->d->parentInfo; if (pInfo) { while(!pInfo->children.empty()) { - SbkObject* first = *pInfo->children.begin(); + SbkObject *first = *pInfo->children.begin(); // Mark child as invalid Shiboken::Object::invalidate(first); Shiboken::Object::removeParent(first, false, keepReference); @@ -588,13 +588,13 @@ namespace Shiboken { bool walkThroughClassHierarchy(PyTypeObject *currentType, HierarchyVisitor *visitor) { - PyObject* bases = currentType->tp_bases; + PyObject *bases = currentType->tp_bases; Py_ssize_t numBases = PyTuple_GET_SIZE(bases); bool result = false; for (int i = 0; !result && i < numBases; ++i) { - PyTypeObject* type = reinterpret_cast<PyTypeObject*>(PyTuple_GET_ITEM(bases, i)); - if (PyType_IsSubtype(type, reinterpret_cast<PyTypeObject*>(SbkObject_TypeF()))) { - SbkObjectType* sbkType = reinterpret_cast<SbkObjectType*>(type); + auto type = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(bases, i)); + if (PyType_IsSubtype(type, reinterpret_cast<PyTypeObject *>(SbkObject_TypeF()))) { + auto sbkType = reinterpret_cast<SbkObjectType *>(type); result = PepType_SOTP(sbkType)->is_user_type ? walkThroughClassHierarchy(type, visitor) : visitor->visit(sbkType); } @@ -602,10 +602,10 @@ bool walkThroughClassHierarchy(PyTypeObject *currentType, HierarchyVisitor *visi return result; } -bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr) +bool importModule(const char *moduleName, PyTypeObject *** cppApiPtr) { - PyObject* sysModules = PyImport_GetModuleDict(); - PyObject* module = PyDict_GetItemString(sysModules, moduleName); + PyObject *sysModules = PyImport_GetModuleDict(); + PyObject *module = PyDict_GetItemString(sysModules, moduleName); if (!module) { module = PyImport_ImportModule(moduleName); if (!module) @@ -622,11 +622,11 @@ bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr) #ifdef IS_PY3K if (PyCapsule_CheckExact(cppApi)) - *cppApiPtr = reinterpret_cast<PyTypeObject**>(PyCapsule_GetPointer(cppApi, 0)); + *cppApiPtr = reinterpret_cast<PyTypeObject **>(PyCapsule_GetPointer(cppApi, 0)); #else // Python 2.6 doesn't have PyCapsule API, so let's keep usign PyCObject on all Python 2.x if (PyCObject_Check(cppApi)) - *cppApiPtr = reinterpret_cast<PyTypeObject**>(PyCObject_AsVoidPtr(cppApi)); + *cppApiPtr = reinterpret_cast<PyTypeObject **>(PyCObject_AsVoidPtr(cppApi)); #endif return true; } @@ -651,7 +651,7 @@ bool BaseAccumulatorVisitor::visit(SbkObjectType *node) bool GetIndexVisitor::visit(SbkObjectType *node) { m_index++; - return PyType_IsSubtype(reinterpret_cast<PyTypeObject*>(node), m_desiredType); + return PyType_IsSubtype(reinterpret_cast<PyTypeObject *>(node), m_desiredType); } bool DtorAccumulatorVisitor::visit(SbkObjectType *node) @@ -709,27 +709,27 @@ public: bool visit(SbkObjectType *node) override { - return reinterpret_cast<PyTypeObject*>(node) == m_typeToFind; + return reinterpret_cast<PyTypeObject *>(node) == m_typeToFind; } private: PyTypeObject *m_typeToFind; }; -std::vector<SbkObject *> splitPyObject(PyObject* pyObj) +std::vector<SbkObject *> splitPyObject(PyObject *pyObj) { std::vector<SbkObject *> result; if (PySequence_Check(pyObj)) { AutoDecRef lst(PySequence_Fast(pyObj, "Invalid keep reference object.")); if (!lst.isNull()) { for (Py_ssize_t i = 0, i_max = PySequence_Fast_GET_SIZE(lst.object()); i < i_max; ++i) { - PyObject* item = PySequence_Fast_GET_ITEM(lst.object(), i); + PyObject *item = PySequence_Fast_GET_ITEM(lst.object(), i); if (Object::checkType(item)) - result.push_back(reinterpret_cast<SbkObject*>(item)); + result.push_back(reinterpret_cast<SbkObject *>(item)); } } } else { - result.push_back(reinterpret_cast<SbkObject*>(pyObj)); + result.push_back(reinterpret_cast<SbkObject *>(pyObj)); } return result; } @@ -744,17 +744,17 @@ inline void decRefPyObjectList(Iterator i1, Iterator i2) namespace ObjectType { -bool checkType(PyTypeObject* type) +bool checkType(PyTypeObject *type) { - return PyType_IsSubtype(type, reinterpret_cast<PyTypeObject*>(SbkObject_TypeF())) != 0; + return PyType_IsSubtype(type, reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())) != 0; } -bool isUserType(PyTypeObject* type) +bool isUserType(PyTypeObject *type) { return checkType(type) && PepType_SOTP(type)->is_user_type; } -bool canCallConstructor(PyTypeObject* myType, PyTypeObject* ctorType) +bool canCallConstructor(PyTypeObject *myType, PyTypeObject *ctorType) { FindBaseTypeVisitor visitor(ctorType); if (!walkThroughClassHierarchy(myType, &visitor)) { @@ -764,23 +764,23 @@ bool canCallConstructor(PyTypeObject* myType, PyTypeObject* ctorType) return true; } -bool hasCast(SbkObjectType* type) +bool hasCast(SbkObjectType *type) { return PepType_SOTP(type)->mi_specialcast != 0; } -void* cast(SbkObjectType* sourceType, SbkObject* obj, PyTypeObject* targetType) +void *cast(SbkObjectType *sourceType, SbkObject *obj, PyTypeObject *targetType) { return PepType_SOTP(sourceType)->mi_specialcast(Object::cppPointer(obj, targetType), - reinterpret_cast<SbkObjectType*>(targetType)); + reinterpret_cast<SbkObjectType *>(targetType)); } -void setCastFunction(SbkObjectType* type, SpecialCastFunction func) +void setCastFunction(SbkObjectType *type, SpecialCastFunction func) { PepType_SOTP(type)->mi_specialcast = func; } -void setOriginalName(SbkObjectType* type, const char* name) +void setOriginalName(SbkObjectType *type, const char *name) { SbkObjectTypePrivate *sotp = PepType_SOTP(type); if (sotp->original_name) @@ -788,12 +788,12 @@ void setOriginalName(SbkObjectType* type, const char* name) sotp->original_name = strdup(name); } -const char* getOriginalName(SbkObjectType* type) +const char *getOriginalName(SbkObjectType *type) { return PepType_SOTP(type)->original_name; } -void setTypeDiscoveryFunctionV2(SbkObjectType* type, TypeDiscoveryFuncV2 func) +void setTypeDiscoveryFunctionV2(SbkObjectType *type, TypeDiscoveryFuncV2 func) { PepType_SOTP(type)->type_discovery = func; } @@ -805,7 +805,7 @@ void copyMultipleInheritance(SbkObjectType *type, SbkObjectType *other) PepType_SOTP(type)->mi_specialcast = PepType_SOTP(other)->mi_specialcast; } -void setMultipleInheritanceFunction(SbkObjectType* type, MultipleInheritanceInitFunction function) +void setMultipleInheritanceFunction(SbkObjectType *type, MultipleInheritanceInitFunction function) { PepType_SOTP(type)->mi_init = function; } @@ -815,12 +815,12 @@ MultipleInheritanceInitFunction getMultipleInheritanceFunction(SbkObjectType *ty return PepType_SOTP(type)->mi_init; } -void setDestructorFunction(SbkObjectType* type, ObjectDestructor func) +void setDestructorFunction(SbkObjectType *type, ObjectDestructor func) { PepType_SOTP(type)->cpp_dtor = func; } -void initPrivateData(SbkObjectType* type) +void initPrivateData(SbkObjectType *type) { PepType_SOTP(type) = new SbkObjectTypePrivate; memset(PepType_SOTP(type), 0, sizeof(SbkObjectTypePrivate)); @@ -872,17 +872,17 @@ introduceWrapperType(PyObject *enclosingObject, return PyModule_AddObject(enclosingObject, typeName, ob_type) == 0 ? type : nullptr; } -void setSubTypeInitHook(SbkObjectType* type, SubTypeInitHook func) +void setSubTypeInitHook(SbkObjectType *type, SubTypeInitHook func) { PepType_SOTP(type)->subtype_init = func; } -void* getTypeUserData(SbkObjectType* type) +void *getTypeUserData(SbkObjectType *type) { return PepType_SOTP(type)->user_data; } -void setTypeUserData(SbkObjectType* type, void* userData, DeleteUserDataFunc d_func) +void setTypeUserData(SbkObjectType *type, void *userData, DeleteUserDataFunc d_func) { SbkObjectTypePrivate *sotp = PepType_SOTP(type); sotp->user_data = userData; @@ -895,7 +895,7 @@ SbkObjectType *typeForTypeName(const char *typeName) SbkObjectType *result{}; if (typeName) { if (PyTypeObject *pyType = Shiboken::Conversions::getPythonTypeObject(typeName)) - result = reinterpret_cast<SbkObjectType*>(pyType); + result = reinterpret_cast<SbkObjectType *>(pyType); } return result; } @@ -912,25 +912,25 @@ bool hasSpecialCastFunction(SbkObjectType *sbkType) namespace Object { -static void recursive_invalidate(SbkObject* self, std::set<SbkObject*>& seen); +static void recursive_invalidate(SbkObject *self, std::set<SbkObject *>& seen); -bool checkType(PyObject* pyObj) +bool checkType(PyObject *pyObj) { return ObjectType::checkType(Py_TYPE(pyObj)); } -bool isUserType(PyObject* pyObj) +bool isUserType(PyObject *pyObj) { return ObjectType::isUserType(Py_TYPE(pyObj)); } -Py_hash_t hash(PyObject* pyObj) +Py_hash_t hash(PyObject *pyObj) { assert(Shiboken::Object::checkType(pyObj)); return reinterpret_cast<Py_hash_t>(pyObj); } -static void setSequenceOwnership(PyObject* pyObj, bool owner) +static void setSequenceOwnership(PyObject *pyObj, bool owner) { bool has_length = true; @@ -957,36 +957,36 @@ static void setSequenceOwnership(PyObject* pyObj, bool owner) } } else if (Object::checkType(pyObj)) { if (owner) - getOwnership(reinterpret_cast<SbkObject*>(pyObj)); + getOwnership(reinterpret_cast<SbkObject *>(pyObj)); else - releaseOwnership(reinterpret_cast<SbkObject*>(pyObj)); + releaseOwnership(reinterpret_cast<SbkObject *>(pyObj)); } } -void setValidCpp(SbkObject* pyObj, bool value) +void setValidCpp(SbkObject *pyObj, bool value) { pyObj->d->validCppObject = value; } -void setHasCppWrapper(SbkObject* pyObj, bool value) +void setHasCppWrapper(SbkObject *pyObj, bool value) { pyObj->d->containsCppWrapper = value; } -bool hasCppWrapper(SbkObject* pyObj) +bool hasCppWrapper(SbkObject *pyObj) { return pyObj->d->containsCppWrapper; } -bool wasCreatedByPython(SbkObject* pyObj) +bool wasCreatedByPython(SbkObject *pyObj) { return pyObj->d->cppObjectCreated; } -void callCppDestructors(SbkObject* pyObj) +void callCppDestructors(SbkObject *pyObj) { PyTypeObject *type = Py_TYPE(pyObj); - SbkObjectTypePrivate * sotp = PepType_SOTP(type); + SbkObjectTypePrivate *sotp = PepType_SOTP(type); if (sotp->is_multicpp) { Shiboken::DtorAccumulatorVisitor visitor(pyObj); Shiboken::walkThroughClassHierarchy(type, &visitor); @@ -1011,12 +1011,12 @@ void callCppDestructors(SbkObject* pyObj) pyObj->d->validCppObject = false; } -bool hasOwnership(SbkObject* pyObj) +bool hasOwnership(SbkObject *pyObj) { return pyObj->d->hasOwnership; } -void getOwnership(SbkObject* self) +void getOwnership(SbkObject *self) { // skip if already have the ownership if (self->d->hasOwnership) @@ -1035,16 +1035,16 @@ void getOwnership(SbkObject* self) makeValid(self); // Make the object valid again } -void getOwnership(PyObject* pyObj) +void getOwnership(PyObject *pyObj) { if (pyObj) setSequenceOwnership(pyObj, true); } -void releaseOwnership(SbkObject* self) +void releaseOwnership(SbkObject *self) { // skip if the ownership have already moved to c++ - SbkObjectType* selfType = reinterpret_cast<SbkObjectType*>(Py_TYPE(self)); + SbkObjectType *selfType = reinterpret_cast<SbkObjectType *>(Py_TYPE(self)); if (!self->d->hasOwnership || Shiboken::Conversions::pythonTypeIsValueType(PepType_SOTP(selfType)->converter)) return; @@ -1058,35 +1058,35 @@ void releaseOwnership(SbkObject* self) invalidate(self); // If I do not know when this object will die We need to invalidate this to avoid use after } -void releaseOwnership(PyObject* self) +void releaseOwnership(PyObject *self) { setSequenceOwnership(self, false); } /* Needed forward declarations */ -static void recursive_invalidate(PyObject* pyobj, std::set<SbkObject*>& seen); -static void recursive_invalidate(SbkObject* self, std::set<SbkObject*>& seen); +static void recursive_invalidate(PyObject *pyobj, std::set<SbkObject *>& seen); +static void recursive_invalidate(SbkObject *self, std::set<SbkObject *> &seen); -void invalidate(PyObject* pyobj) +void invalidate(PyObject *pyobj) { - std::set<SbkObject*> seen; + std::set<SbkObject *> seen; recursive_invalidate(pyobj, seen); } -void invalidate(SbkObject* self) +void invalidate(SbkObject *self) { - std::set<SbkObject*> seen; + std::set<SbkObject *> seen; recursive_invalidate(self, seen); } -static void recursive_invalidate(PyObject* pyobj, std::set<SbkObject*>& seen) +static void recursive_invalidate(PyObject *pyobj, std::set<SbkObject *> &seen) { const auto objs = splitPyObject(pyobj); for (SbkObject *o : objs) recursive_invalidate(o, seen); } -static void recursive_invalidate(SbkObject* self, std::set<SbkObject*>& seen) +static void recursive_invalidate(SbkObject *self, std::set<SbkObject *> &seen) { // Skip if this object not is a valid object or if it's already been seen if (!self || reinterpret_cast<PyObject *>(self) == Py_None || seen.find(self) != seen.end()) @@ -1115,13 +1115,13 @@ static void recursive_invalidate(SbkObject* self, std::set<SbkObject*>& seen) // If has ref to other objects invalidate all if (self->d->referredObjects) { - RefCountMap& refCountMap = *(self->d->referredObjects); + RefCountMap &refCountMap = *(self->d->referredObjects); for (auto it = refCountMap.begin(), end = refCountMap.end(); it != end; ++it) recursive_invalidate(it->second, seen); } } -void makeValid(SbkObject* self) +void makeValid(SbkObject *self) { // Skip if this object not is a valid object if (!self || reinterpret_cast<PyObject *>(self) == Py_None || self->d->validCppObject) @@ -1138,7 +1138,7 @@ void makeValid(SbkObject* self) // If has ref to other objects make all valid again if (self->d->referredObjects) { - RefCountMap& refCountMap = *(self->d->referredObjects); + RefCountMap &refCountMap = *(self->d->referredObjects); RefCountMap::iterator iter; for (auto it = refCountMap.begin(), end = refCountMap.end(); it != end; ++it) { if (Shiboken::Object::checkType(it->second)) @@ -1147,28 +1147,28 @@ void makeValid(SbkObject* self) } } -void* cppPointer(SbkObject* pyObj, PyTypeObject* desiredType) +void *cppPointer(SbkObject *pyObj, PyTypeObject *desiredType) { - PyTypeObject* type = Py_TYPE(pyObj); + PyTypeObject *type = Py_TYPE(pyObj); int idx = 0; - if (PepType_SOTP(reinterpret_cast<SbkObjectType*>(type))->is_multicpp) + if (PepType_SOTP(reinterpret_cast<SbkObjectType *>(type))->is_multicpp) idx = getTypeIndexOnHierarchy(type, desiredType); if (pyObj->d->cptr) return pyObj->d->cptr[idx]; return 0; } -std::vector<void*> cppPointers(SbkObject* pyObj) +std::vector<void *> cppPointers(SbkObject *pyObj) { int n = getNumberOfCppBaseClasses(Py_TYPE(pyObj)); - std::vector<void*> ptrs(n); + std::vector<void *> ptrs(n); for (int i = 0; i < n; ++i) ptrs[i] = pyObj->d->cptr[i]; return ptrs; } -bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr) +bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr) { int idx = 0; PyTypeObject *type = Py_TYPE(sbkObj); @@ -1185,14 +1185,14 @@ bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr) return !alreadyInitialized; } -bool isValid(PyObject* pyObj) +bool isValid(PyObject *pyObj) { if (!pyObj || pyObj == Py_None || Py_TYPE(Py_TYPE(pyObj)) != SbkObjectType_TypeF()) { return true; } - SbkObjectPrivate* priv = reinterpret_cast<SbkObject*>(pyObj)->d; + auto priv = reinterpret_cast<SbkObject *>(pyObj)->d; if (!priv->cppObjectCreated && isUserType(pyObj)) { PyErr_Format(PyExc_RuntimeError, "'__init__' method of object's base class (%s) not called.", @@ -1209,13 +1209,13 @@ bool isValid(PyObject* pyObj) return true; } -bool isValid(SbkObject* pyObj, bool throwPyError) +bool isValid(SbkObject *pyObj, bool throwPyError) { if (!pyObj) return false; - SbkObjectPrivate* priv = pyObj->d; - if (!priv->cppObjectCreated && isUserType(reinterpret_cast<PyObject*>(pyObj))) { + SbkObjectPrivate *priv = pyObj->d; + if (!priv->cppObjectCreated && isUserType(reinterpret_cast<PyObject *>(pyObj))) { if (throwPyError) PyErr_Format(PyExc_RuntimeError, "Base constructor of the object (%s) not called.", Py_TYPE(pyObj)->tp_name); @@ -1232,13 +1232,13 @@ bool isValid(SbkObject* pyObj, bool throwPyError) return true; } -bool isValid(PyObject* pyObj, bool throwPyError) +bool isValid(PyObject *pyObj, bool throwPyError) { if (!pyObj || pyObj == Py_None || - !PyType_IsSubtype(Py_TYPE(pyObj), reinterpret_cast<PyTypeObject*>(SbkObject_TypeF()))) { + !PyType_IsSubtype(Py_TYPE(pyObj), reinterpret_cast<PyTypeObject *>(SbkObject_TypeF()))) { return true; } - return isValid(reinterpret_cast<SbkObject*>(pyObj), throwPyError); + return isValid(reinterpret_cast<SbkObject *>(pyObj), throwPyError); } SbkObject *findColocatedChild(SbkObject *wrapper, @@ -1251,11 +1251,11 @@ SbkObject *findColocatedChild(SbkObject *wrapper, if (!(wrapper->d && wrapper->d->cptr)) return 0; - ParentInfo* pInfo = wrapper->d->parentInfo; + ParentInfo *pInfo = wrapper->d->parentInfo; if (!pInfo) return 0; - ChildrenList& children = pInfo->children; + ChildrenList &children = pInfo->children; for (SbkObject *child : children) { if (!(child->d && child->d->cptr)) @@ -1270,11 +1270,11 @@ SbkObject *findColocatedChild(SbkObject *wrapper, return 0; } -PyObject *newObject(SbkObjectType* instanceType, - void* cptr, +PyObject *newObject(SbkObjectType *instanceType, + void *cptr, bool hasOwnership, bool isExactType, - const char* typeName) + const char *typeName) { // Try to find the exact type of cptr. if (!isExactType) { @@ -1286,11 +1286,11 @@ PyObject *newObject(SbkObjectType* instanceType, bool shouldCreate = true; bool shouldRegister = true; - SbkObject* self = 0; + SbkObject *self = 0; // Some logic to ensure that colocated child field does not overwrite the parent if (BindingManager::instance().hasWrapper(cptr)) { - SbkObject* existingWrapper = BindingManager::instance().retrieveWrapper(cptr); + SbkObject *existingWrapper = BindingManager::instance().retrieveWrapper(cptr); self = findColocatedChild(existingWrapper, instanceType); if (self) { @@ -1313,7 +1313,7 @@ PyObject *newObject(SbkObjectType* instanceType, } if (shouldCreate) { - self = reinterpret_cast<SbkObject*>(SbkObjectTpNew(reinterpret_cast<PyTypeObject*>(instanceType), 0, 0)); + self = reinterpret_cast<SbkObject *>(SbkObjectTpNew(reinterpret_cast<PyTypeObject *>(instanceType), 0, 0)); self->d->cptr[0] = cptr; self->d->hasOwnership = hasOwnership; self->d->validCppObject = 1; @@ -1321,17 +1321,17 @@ PyObject *newObject(SbkObjectType* instanceType, BindingManager::instance().registerWrapper(self, cptr); } } else { - Py_IncRef(reinterpret_cast<PyObject*>(self)); + Py_IncRef(reinterpret_cast<PyObject *>(self)); } - return reinterpret_cast<PyObject*>(self); + return reinterpret_cast<PyObject *>(self); } -void destroy(SbkObject* self) +void destroy(SbkObject *self) { destroy(self, 0); } -void destroy(SbkObject* self, void* cppData) +void destroy(SbkObject *self, void *cppData) { // Skip if this is called with NULL pointer this can happen in derived classes if (!self) @@ -1375,9 +1375,9 @@ void destroy(SbkObject* self, void* cppData) // After this point the object can be death do not use the self pointer bellow } -void removeParent(SbkObject* child, bool giveOwnershipBack, bool keepReference) +void removeParent(SbkObject *child, bool giveOwnershipBack, bool keepReference) { - ParentInfo* pInfo = child->d->parentInfo; + ParentInfo *pInfo = child->d->parentInfo; if (!pInfo || !pInfo->parent) { if (pInfo && pInfo->hasWrapperRef) { pInfo->hasWrapperRef = false; @@ -1385,7 +1385,7 @@ void removeParent(SbkObject* child, bool giveOwnershipBack, bool keepReference) return; } - ChildrenList& oldBrothers = pInfo->parent->d->parentInfo->children; + ChildrenList &oldBrothers = pInfo->parent->d->parentInfo->children; // Verify if this child is part of parent list auto iChild = oldBrothers.find(child); if (iChild == oldBrothers.end()) @@ -1413,18 +1413,18 @@ void removeParent(SbkObject* child, bool giveOwnershipBack, bool keepReference) Py_DECREF(child); } -void setParent(PyObject* parent, PyObject* child) +void setParent(PyObject *parent, PyObject *child) { if (!child || child == Py_None || child == parent) return; /* - * setParent is recursive when the child is a native Python sequence, i.e. objects not binded by Shiboken - * like tuple and list. + * setParent is recursive when the child is a native Python sequence, i.e. objects not binded by Shiboken + * like tuple and list. * - * This "limitation" exists to fix the following problem: A class multiple inherits QObject and QString, - * so if you pass this class to someone that takes the ownership, we CAN'T enter in this if, but hey! QString - * follows the sequence protocol. + * This "limitation" exists to fix the following problem: A class multiple inherits QObject and QString, + * so if you pass this class to someone that takes the ownership, we CAN'T enter in this if, but hey! QString + * follows the sequence protocol. */ if (PySequence_Check(child) && !Object::checkType(child)) { Shiboken::AutoDecRef seq(PySequence_Fast(child, 0)); @@ -1434,8 +1434,8 @@ void setParent(PyObject* parent, PyObject* child) } bool parentIsNull = !parent || parent == Py_None; - SbkObject* parent_ = reinterpret_cast<SbkObject*>(parent); - SbkObject* child_ = reinterpret_cast<SbkObject*>(child); + auto parent_ = reinterpret_cast<SbkObject *>(parent); + auto child_ = reinterpret_cast<SbkObject *>(child); if (!parentIsNull) { if (!parent_->d->parentInfo) @@ -1446,7 +1446,7 @@ void setParent(PyObject* parent, PyObject* child) return; } - ParentInfo* pInfo = child_->d->parentInfo; + ParentInfo *pInfo = child_->d->parentInfo; bool hasAnotherParent = pInfo && pInfo->parent && pInfo->parent != parent_; //Avoid destroy child during reparent operation @@ -1476,7 +1476,7 @@ void setParent(PyObject* parent, PyObject* child) Py_DECREF(child); } -void deallocData(SbkObject* self, bool cleanup) +void deallocData(SbkObject *self, bool cleanup) { // Make cleanup if this is not a wrapper otherwise this will be done on wrapper destructor if(cleanup) { @@ -1499,11 +1499,11 @@ void deallocData(SbkObject* self, bool cleanup) Py_XDECREF(self->ob_dict); // PYSIDE-571: qApp is no longer allocated. - if (PyObject_IS_GC(reinterpret_cast<PyObject*>(self))) + if (PyObject_IS_GC(reinterpret_cast<PyObject *>(self))) Py_TYPE(self)->tp_free(self); } -void setTypeUserData(SbkObject* wrapper, void* userData, DeleteUserDataFunc d_func) +void setTypeUserData(SbkObject *wrapper, void *userData, DeleteUserDataFunc d_func) { SbkObjectTypePrivate *sotp = PepType_SOTP(Py_TYPE(wrapper)); if (sotp->user_data) @@ -1513,7 +1513,7 @@ void setTypeUserData(SbkObject* wrapper, void* userData, DeleteUserDataFunc d_fu sotp->user_data = userData; } -void* getTypeUserData(SbkObject* wrapper) +void *getTypeUserData(SbkObject *wrapper) { return PepType_SOTP(Py_TYPE(wrapper))->user_data; } @@ -1523,7 +1523,7 @@ static inline bool isNone(const PyObject *o) return o == nullptr || o == Py_None; } -static void removeRefCountKey(SbkObject* self, const char *key) +static void removeRefCountKey(SbkObject *self, const char *key) { if (self->d->referredObjects) { const auto iterPair = self->d->referredObjects->equal_range(key); @@ -1534,7 +1534,7 @@ static void removeRefCountKey(SbkObject* self, const char *key) } } -void keepReference(SbkObject* self, const char* key, PyObject* referredObject, bool append) +void keepReference(SbkObject *self, const char *key, PyObject *referredObject, bool append) { if (isNone(referredObject)) { removeRefCountKey(self, key); @@ -1548,7 +1548,7 @@ void keepReference(SbkObject* self, const char* key, PyObject* referredObject, b return; } - RefCountMap& refCountMap = *(self->d->referredObjects); + RefCountMap &refCountMap = *(self->d->referredObjects); const auto iterPair = refCountMap.equal_range(key); if (std::any_of(iterPair.first, iterPair.second, [referredObject](const RefCountMap::value_type &v) { return v.second == referredObject; })) { @@ -1564,24 +1564,24 @@ void keepReference(SbkObject* self, const char* key, PyObject* referredObject, b Py_INCREF(referredObject); } -void removeReference(SbkObject* self, const char* key, PyObject* referredObject) +void removeReference(SbkObject *self, const char *key, PyObject *referredObject) { if (!isNone(referredObject)) removeRefCountKey(self, key); } -void clearReferences(SbkObject* self) +void clearReferences(SbkObject *self) { if (!self->d->referredObjects) return; - RefCountMap& refCountMap = *(self->d->referredObjects); + RefCountMap &refCountMap = *(self->d->referredObjects); for (auto it = refCountMap.begin(), end = refCountMap.end(); it != end; ++it) Py_DECREF(it->second); self->d->referredObjects->clear(); } -std::string info(SbkObject* self) +std::string info(SbkObject *self) { std::ostringstream s; @@ -1590,7 +1590,7 @@ std::string info(SbkObject* self) if (ObjectType::isUserType(Py_TYPE(self))) bases = getCppBaseClasses(Py_TYPE(self)); else - bases.push_back(reinterpret_cast<SbkObjectType*>(Py_TYPE(self))); + bases.push_back(reinterpret_cast<SbkObjectType *>(Py_TYPE(self))); s << "C++ address....... "; for (size_t i = 0, size = bases.size(); i < size; ++i) { @@ -1625,7 +1625,7 @@ std::string info(SbkObject* self) } if (self->d->referredObjects && !self->d->referredObjects->empty()) { - Shiboken::RefCountMap& map = *self->d->referredObjects; + Shiboken::RefCountMap &map = *self->d->referredObjects; s << "referred objects.. "; std::string lastKey; for (auto it = map.begin(), end = map.end(); it != end; ++it) { |