diff options
author | Christian Tismer <tismer@stackless.com> | 2019-06-16 12:05:39 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-24 11:25:31 +0200 |
commit | 380c65e62de0e60da667dc0d87935171b91b9c6c (patch) | |
tree | 480c872f247316a66e446ba196a5bd1a339a0bcd /sources/shiboken2/libshiboken | |
parent | 992ff1f7925009b7ead6d6f005cafcf2e57ed44e (diff) |
Cleanup pointer whitespace everywhere
Among other files to fix, basewrapper.(cpp|h) was full of uncommon
pointer whitespace. After fixing that, I could not resist and fixed
also libshiboken, generators, and after acceptance also PySide.
Most of the time, this regex worked fine
(\w\w+)([*&]+)[ ]*(?![&*]*[/=])
replaced with
\1 \2
but everything was checked by hand.
I did not touch the shiboken tests which are quite hairy.
It turned out that inserting a space between a variable and asterisk
causes a crash of shiboken, if the same line contains "CONVERTTOCPP".
This was temporarily fixed by adding another space after it.
Example..
sources/pyside2/PySide2/glue/qtcore.cpp line 977
QByteArray * cppSelf = %CONVERTTOCPP[QByteArray *](obj);
//XXX /|\ omitting this space crashes shiboken!
cppgenerator.cpp was special, since it was modified to _generate_
correct pointer whitespace. This caused a few testcases to fail,
which had to be adjusted, again. This was difficult since some
internal names must end on "*" and generated code normally not.
Removing the last errors involved binary search on path sets...
Apply C++ 11 fixits to the changed code, where applicable.
Done-with: Friedemann.Kleint@qt.io
Task-number: PYSIDE-1037
Change-Id: I4ac070f52c5efb296c05d581c9d46e6f397a6c81
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/libshiboken')
35 files changed, 805 insertions, 804 deletions
diff --git a/sources/shiboken2/libshiboken/autodecref.h b/sources/shiboken2/libshiboken/autodecref.h index 72fd236de..b2f5a6325 100644 --- a/sources/shiboken2/libshiboken/autodecref.h +++ b/sources/shiboken2/libshiboken/autodecref.h @@ -53,21 +53,21 @@ namespace Shiboken struct LIBSHIBOKEN_API AutoDecRef { public: - AutoDecRef(const AutoDecRef&) = delete; - AutoDecRef(AutoDecRef&&) = delete; - AutoDecRef& operator=(const AutoDecRef&) = delete; - AutoDecRef& operator=(AutoDecRef&&) = delete; + AutoDecRef(const AutoDecRef &) = delete; + AutoDecRef(AutoDecRef &&) = delete; + AutoDecRef &operator=(const AutoDecRef &) = delete; + AutoDecRef &operator=(AutoDecRef &&) = delete; /** * AutoDecRef constructor. * \param pyobj A borrowed reference to a Python object */ - explicit AutoDecRef(PyObject* pyObj) : m_pyObj(pyObj) {} + explicit AutoDecRef(PyObject *pyObj) : m_pyObj(pyObj) {} /** * AutoDecRef constructor. * \param pyobj A borrowed reference to a Python object */ - explicit AutoDecRef(SbkObject* pyObj) : m_pyObj(reinterpret_cast<PyObject*>(pyObj)) {} + explicit AutoDecRef(SbkObject *pyObj) : m_pyObj(reinterpret_cast<PyObject *>(pyObj)) {} /// Decref the borrowed python reference ~AutoDecRef() @@ -77,13 +77,13 @@ public: inline bool isNull() const { return m_pyObj == 0; } /// Returns the pointer of the Python object being held. - inline PyObject* object() { return m_pyObj; } - inline operator PyObject*() { return m_pyObj; } + inline PyObject *object() { return m_pyObj; } + inline operator PyObject *() { return m_pyObj; } #ifndef Py_LIMITED_API - inline operator PyTupleObject*() { return reinterpret_cast<PyTupleObject*>(m_pyObj); } + inline operator PyTupleObject *() { return reinterpret_cast<PyTupleObject *>(m_pyObj); } #endif inline operator bool() const { return m_pyObj != 0; } - inline PyObject* operator->() { return m_pyObj; } + inline PyObject *operator->() { return m_pyObj; } template<typename T> T cast() @@ -94,13 +94,13 @@ public: /** * Decref the current borrowed python reference and borrow \p other. */ - void reset(PyObject* other) + void reset(PyObject *other) { Py_XDECREF(m_pyObj); m_pyObj = other; } private: - PyObject* m_pyObj; + PyObject *m_pyObj; }; } // namespace Shiboken 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) { diff --git a/sources/shiboken2/libshiboken/basewrapper.h b/sources/shiboken2/libshiboken/basewrapper.h index 55445b026..7faf223bd 100644 --- a/sources/shiboken2/libshiboken/basewrapper.h +++ b/sources/shiboken2/libshiboken/basewrapper.h @@ -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. @@ -57,41 +57,41 @@ struct LIBSHIBOKEN_API SbkObject { PyObject_HEAD /// Instance dictionary. - PyObject* ob_dict; + PyObject *ob_dict; /// List of weak references - PyObject* weakreflist; - SbkObjectPrivate* d; + PyObject *weakreflist; + SbkObjectPrivate *d; }; /// Dealloc the python object \p pyObj and the C++ object represented by it. -LIBSHIBOKEN_API void SbkDeallocWrapper(PyObject* pyObj); -LIBSHIBOKEN_API void SbkDeallocQAppWrapper(PyObject* pyObj); -LIBSHIBOKEN_API void SbkDeallocWrapperWithPrivateDtor(PyObject* self); +LIBSHIBOKEN_API void SbkDeallocWrapper(PyObject *pyObj); +LIBSHIBOKEN_API void SbkDeallocQAppWrapper(PyObject *pyObj); +LIBSHIBOKEN_API void SbkDeallocWrapperWithPrivateDtor(PyObject *self); struct SbkObjectType; /// Function signature for the multiple inheritance information initializers that should be provided by classes with multiple inheritance. -typedef int* (*MultipleInheritanceInitFunction)(const void*); +typedef int *(*MultipleInheritanceInitFunction)(const void *); /** * Special cast function is used to correctly cast an object when it's * part of a multiple inheritance hierarchy. * The implementation of this function is auto generated by the generator and you don't need to care about it. */ -typedef void* (*SpecialCastFunction)(void*, SbkObjectType*); -typedef SbkObjectType* (*TypeDiscoveryFunc)(void*, SbkObjectType*); -typedef void* (*TypeDiscoveryFuncV2)(void*, SbkObjectType*); +typedef void *(*SpecialCastFunction)(void *, SbkObjectType *); +typedef SbkObjectType *(*TypeDiscoveryFunc)(void *, SbkObjectType *); +typedef void *(*TypeDiscoveryFuncV2)(void *, SbkObjectType *); -typedef void* (*ExtendedToCppFunc)(PyObject*); // DEPRECATED. -typedef bool (*ExtendedIsConvertibleFunc)(PyObject*); // DEPRECATED. +typedef void *(*ExtendedToCppFunc)(PyObject *); // DEPRECATED. +typedef bool (*ExtendedIsConvertibleFunc)(PyObject *); // DEPRECATED. // Used in userdata dealloc function -typedef void (*DeleteUserDataFunc)(void*); +typedef void (*DeleteUserDataFunc)(void *); -typedef void (*ObjectDestructor)(void*); +typedef void (*ObjectDestructor)(void *); -typedef void (*SubTypeInitHook)(SbkObjectType*, PyObject*, PyObject*); +typedef void (*SubTypeInitHook)(SbkObjectType *, PyObject *, PyObject *); extern LIBSHIBOKEN_API PyTypeObject *SbkObjectType_TypeF(void); extern LIBSHIBOKEN_API SbkObjectType *SbkObject_TypeF(void); @@ -104,9 +104,9 @@ struct LIBSHIBOKEN_API SbkObjectType PyTypeObject type; }; -LIBSHIBOKEN_API PyObject* SbkObjectTpNew(PyTypeObject* subtype, PyObject*, PyObject*); +LIBSHIBOKEN_API PyObject *SbkObjectTpNew(PyTypeObject *subtype, PyObject *, PyObject *); // the special case of a switchable singleton -LIBSHIBOKEN_API PyObject* SbkQAppTpNew(PyTypeObject *subtype, PyObject *args, PyObject *kwds); +LIBSHIBOKEN_API PyObject *SbkQAppTpNew(PyTypeObject *subtype, PyObject *args, PyObject *kwds); /** * PYSIDE-832: Use object_dealloc instead of nullptr. @@ -132,36 +132,36 @@ LIBSHIBOKEN_API void init(); /// Delete the class T allocated on \p cptr. template<typename T> -void callCppDestructor(void* cptr) +void callCppDestructor(void *cptr) { - delete reinterpret_cast<T*>(cptr); + delete reinterpret_cast<T *>(cptr); } /** * Shiboken::importModule is DEPRECATED. Use Shiboken::Module::import() instead. */ -SBK_DEPRECATED(LIBSHIBOKEN_API bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr)); +SBK_DEPRECATED(LIBSHIBOKEN_API bool importModule(const char *moduleName, PyTypeObject *** cppApiPtr)); // setErrorAboutWrongArguments now gets overload info from the signature module. -LIBSHIBOKEN_API void setErrorAboutWrongArguments(PyObject* args, const char* funcName); +LIBSHIBOKEN_API void setErrorAboutWrongArguments(PyObject *args, const char *funcName); namespace ObjectType { /** * Returns true if the object is an instance of a type created by the Shiboken generator. */ -LIBSHIBOKEN_API bool checkType(PyTypeObject* pyObj); +LIBSHIBOKEN_API bool checkType(PyTypeObject *pyObj); /** * Returns true if this object is an instance of an user defined type derived from an Shiboken type. */ -LIBSHIBOKEN_API bool isUserType(PyTypeObject* pyObj); +LIBSHIBOKEN_API bool isUserType(PyTypeObject *pyObj); /** * Returns true if the constructor of \p ctorType can be called for a instance of type \p myType. * \note This function set a python error when returning false. */ -LIBSHIBOKEN_API bool canCallConstructor(PyTypeObject* myType, PyTypeObject* ctorType); +LIBSHIBOKEN_API bool canCallConstructor(PyTypeObject *myType, PyTypeObject *ctorType); /** * Tells if the \p type represents an object of a class with multiple inheritance in C++. @@ -170,27 +170,27 @@ LIBSHIBOKEN_API bool canCallConstructor(PyTypeObject* myType, PyTypeObjec * \returns true if a call to ObjectType::cast() is needed to obtain the correct * C++ pointer for Python objects of type \p type. */ -LIBSHIBOKEN_API bool hasCast(SbkObjectType* type); +LIBSHIBOKEN_API bool hasCast(SbkObjectType *type); /** * Cast the C++ pointer held by a Python object \p obj of type \p sourceType, * to a C++ pointer of a C++ class indicated by type \p targetType. * \returns The cast C++ pointer. */ -LIBSHIBOKEN_API void* cast(SbkObjectType* sourceType, SbkObject* obj, PyTypeObject* targetType); +LIBSHIBOKEN_API void *cast(SbkObjectType *sourceType, SbkObject *obj, PyTypeObject *targetType); /// Set the C++ cast function for \p type. -LIBSHIBOKEN_API void setCastFunction(SbkObjectType* type, SpecialCastFunction func); +LIBSHIBOKEN_API void setCastFunction(SbkObjectType *type, SpecialCastFunction func); -LIBSHIBOKEN_API void setOriginalName(SbkObjectType* self, const char* name); -LIBSHIBOKEN_API const char* getOriginalName(SbkObjectType* self); +LIBSHIBOKEN_API void setOriginalName(SbkObjectType *self, const char *name); +LIBSHIBOKEN_API const char *getOriginalName(SbkObjectType *self); -LIBSHIBOKEN_API void setTypeDiscoveryFunctionV2(SbkObjectType* self, TypeDiscoveryFuncV2 func); -LIBSHIBOKEN_API void copyMultipleInheritance(SbkObjectType *self, SbkObjectType *other); -LIBSHIBOKEN_API void setMultipleInheritanceFunction(SbkObjectType* self, MultipleInheritanceInitFunction func); +LIBSHIBOKEN_API void setTypeDiscoveryFunctionV2(SbkObjectType *self, TypeDiscoveryFuncV2 func); +LIBSHIBOKEN_API void copyMultipleInheritance(SbkObjectType *self, SbkObjectType *other); +LIBSHIBOKEN_API void setMultipleInheritanceFunction(SbkObjectType *self, MultipleInheritanceInitFunction func); LIBSHIBOKEN_API MultipleInheritanceInitFunction getMultipleInheritanceFunction(SbkObjectType *self); -LIBSHIBOKEN_API void setDestructorFunction(SbkObjectType* self, ObjectDestructor func); +LIBSHIBOKEN_API void setDestructorFunction(SbkObjectType *self, ObjectDestructor func); -LIBSHIBOKEN_API void initPrivateData(SbkObjectType* self); +LIBSHIBOKEN_API void initPrivateData(SbkObjectType *self); enum WrapperFlags { @@ -232,13 +232,13 @@ LIBSHIBOKEN_API SbkObjectType *introduceWrapperType(PyObject *enclosingObject, * The hook gets 3 params, they are: The new type being created, args and kwds. The last two are the very * same got from tp_new. */ -LIBSHIBOKEN_API void setSubTypeInitHook(SbkObjectType* self, SubTypeInitHook func); +LIBSHIBOKEN_API void setSubTypeInitHook(SbkObjectType *self, SubTypeInitHook func); /** * Get the user data previously set by Shiboken::Object::setTypeUserData */ -LIBSHIBOKEN_API void* getTypeUserData(SbkObjectType* self); -LIBSHIBOKEN_API void setTypeUserData(SbkObjectType* self, void* userData, DeleteUserDataFunc d_func); +LIBSHIBOKEN_API void *getTypeUserData(SbkObjectType *self); +LIBSHIBOKEN_API void setTypeUserData(SbkObjectType *self, void *userData, DeleteUserDataFunc d_func); /** * Return an instance of SbkObjectType for a C++ type name as determined by @@ -261,23 +261,23 @@ namespace Object { /** * Returns a string with information about the internal state of the instance object, useful for debug purposes. */ -LIBSHIBOKEN_API std::string info(SbkObject* self); +LIBSHIBOKEN_API std::string info(SbkObject *self); /** * Returns true if the object is an instance of a type created by the Shiboken generator. */ -LIBSHIBOKEN_API bool checkType(PyObject* pyObj); +LIBSHIBOKEN_API bool checkType(PyObject *pyObj); /** * Returns true if this object type is an instance of an user defined type derived from an Shiboken type. * \see Shiboken::ObjectType::isUserType */ -LIBSHIBOKEN_API bool isUserType(PyObject* pyObj); +LIBSHIBOKEN_API bool isUserType(PyObject *pyObj); /** * Generic function used to make ObjectType hashable, the C++ pointer is used as hash value. */ -LIBSHIBOKEN_API Py_hash_t hash(PyObject* pyObj); +LIBSHIBOKEN_API Py_hash_t hash(PyObject *pyObj); /** * Find a child of given wrapper having same address having the specified type. @@ -294,101 +294,101 @@ LIBSHIBOKEN_API SbkObject *findColocatedChild(SbkObject *wrapper, * and as fallback. * \param typeName If non-null, this will be used as helper to find the correct Python type for this object. */ -LIBSHIBOKEN_API PyObject* newObject(SbkObjectType* instanceType, - void* cptr, - bool hasOwnership = true, - bool isExactType = false, - const char* typeName = 0); +LIBSHIBOKEN_API PyObject *newObject(SbkObjectType *instanceType, + void *cptr, + bool hasOwnership = true, + bool isExactType = false, + const char *typeName = nullptr); /** * Changes the valid flag of a PyObject, invalid objects will raise an exception when someone tries to access it. */ -LIBSHIBOKEN_API void setValidCpp(SbkObject* pyObj, bool value); +LIBSHIBOKEN_API void setValidCpp(SbkObject *pyObj, bool value); /** * Tells shiboken the Python object \p pyObj has a C++ wrapper used to intercept virtual method calls. */ -LIBSHIBOKEN_API void setHasCppWrapper(SbkObject* pyObj, bool value); +LIBSHIBOKEN_API void setHasCppWrapper(SbkObject *pyObj, bool value); /** * Return true if the Python object \p pyObj has a C++ wrapper used to intercept virtual method calls. */ -LIBSHIBOKEN_API bool hasCppWrapper(SbkObject* pyObj); +LIBSHIBOKEN_API bool hasCppWrapper(SbkObject *pyObj); /** * Return true if the Python object was created by Python, false otherwise. * \note This function was added to libshiboken only to be used by shiboken.wasCreatedByPython() */ -LIBSHIBOKEN_API bool wasCreatedByPython(SbkObject* pyObj); +LIBSHIBOKEN_API bool wasCreatedByPython(SbkObject *pyObj); /** * Call the C++ object destructor and invalidates the Python object. * \note This function was added to libshiboken only to be used by shiboken.delete() */ -LIBSHIBOKEN_API void callCppDestructors(SbkObject* pyObj); +LIBSHIBOKEN_API void callCppDestructors(SbkObject *pyObj); /** * Return true if the Python is responsible for deleting the underlying C++ object. */ -LIBSHIBOKEN_API bool hasOwnership(SbkObject* pyObj); +LIBSHIBOKEN_API bool hasOwnership(SbkObject *pyObj); /** * Sets python as responsible to delete the underlying C++ object. * \note You this overload only when the PyObject can be a sequence and you want to * call this function for every item in the sequence. - * \see getOwnership(SbkObject*) + * \see getOwnership(SbkObject *) */ -LIBSHIBOKEN_API void getOwnership(PyObject* pyObj); +LIBSHIBOKEN_API void getOwnership(PyObject *pyObj); /** * Sets python as responsible to delete the underlying C++ object. */ -LIBSHIBOKEN_API void getOwnership(SbkObject* pyObj); +LIBSHIBOKEN_API void getOwnership(SbkObject *pyObj); /** * Release the ownership, so Python will not delete the underlying C++ object. * \note You this overload only when the PyObject can be a sequence and you want to * call this function for every item in the sequence. - * \see releaseOwnership(SbkObject*) + * \see releaseOwnership(SbkObject *) */ -LIBSHIBOKEN_API void releaseOwnership(PyObject* pyObj); +LIBSHIBOKEN_API void releaseOwnership(PyObject *pyObj); /** * Release the ownership, so Python will not delete the underlying C++ object. */ -LIBSHIBOKEN_API void releaseOwnership(SbkObject* pyObj); +LIBSHIBOKEN_API void releaseOwnership(SbkObject *pyObj); /** * Get the C++ pointer of type \p desiredType from a Python object. */ -LIBSHIBOKEN_API void* cppPointer(SbkObject* pyObj, PyTypeObject* desiredType); +LIBSHIBOKEN_API void *cppPointer(SbkObject *pyObj, PyTypeObject *desiredType); /** * Return a list with all C++ pointers held from a Python object. * \note This function was added to libshiboken only to be used by shiboken.getCppPointer() */ -LIBSHIBOKEN_API std::vector<void*> cppPointers(SbkObject* pyObj); +LIBSHIBOKEN_API std::vector<void *>cppPointers(SbkObject *pyObj); /** * Set the C++ pointer of type \p desiredType of a Python object. */ -LIBSHIBOKEN_API bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr); +LIBSHIBOKEN_API bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr); /** * Returns false and sets a Python RuntimeError if the Python wrapper is not marked as valid. */ -LIBSHIBOKEN_API bool isValid(PyObject* pyObj); +LIBSHIBOKEN_API bool isValid(PyObject *pyObj); /** * Returns false if the Python wrapper is not marked as valid. * \param pyObj the object. * \param throwPyError sets a Python RuntimeError when the object isn't valid. */ -LIBSHIBOKEN_API bool isValid(SbkObject* pyObj, bool throwPyError = true); +LIBSHIBOKEN_API bool isValid(SbkObject *pyObj, bool throwPyError = true); /** * Returns false if the Python wrapper is not marked as valid. * \param pyObj the object. * \param throwPyError sets a Python RuntimeError when the object isn't valid. */ -LIBSHIBOKEN_API bool isValid(PyObject* pyObj, bool throwPyError); +LIBSHIBOKEN_API bool isValid(PyObject *pyObj, bool throwPyError); /** * Set the parent of \p child to \p parent. @@ -396,36 +396,36 @@ LIBSHIBOKEN_API bool isValid(PyObject* pyObj, bool throwPyError); * \param parent the parent object, if null, the child will have no parents. * \param child the child. */ -LIBSHIBOKEN_API void setParent(PyObject* parent, PyObject* child); +LIBSHIBOKEN_API void setParent(PyObject *parent, PyObject *child); /** * Remove this child from their parent, if any. * \param child the child. */ -LIBSHIBOKEN_API void removeParent(SbkObject* child, bool giveOwnershipBack = true, bool keepReferenc = false); +LIBSHIBOKEN_API void removeParent(SbkObject *child, bool giveOwnershipBack = true, bool keepReferenc = false); /** * Mark the object as invalid */ -LIBSHIBOKEN_API void invalidate(SbkObject* self); +LIBSHIBOKEN_API void invalidate(SbkObject *self); /** * Help function can be used to invalidate a sequence of object **/ -LIBSHIBOKEN_API void invalidate(PyObject* pyobj); +LIBSHIBOKEN_API void invalidate(PyObject *pyobj); /** * Make the object valid again */ -LIBSHIBOKEN_API void makeValid(SbkObject* self); +LIBSHIBOKEN_API void makeValid(SbkObject *self); -/// \deprecated Use destroy(SbkObject*, void*) -SBK_DEPRECATED(LIBSHIBOKEN_API void destroy(SbkObject* self)); +/// \deprecated Use destroy(SbkObject *, void *) +SBK_DEPRECATED(LIBSHIBOKEN_API void destroy(SbkObject *self)); /** * Destroy any data in Shiboken structure and c++ pointer if the pyboject has the ownership */ -LIBSHIBOKEN_API void destroy(SbkObject* self, void* cppData); +LIBSHIBOKEN_API void destroy(SbkObject *self, void *cppData); /** * Set user data on type of \p wrapper. @@ -433,11 +433,11 @@ LIBSHIBOKEN_API void destroy(SbkObject* self, void* cppData); * \param userData the user data * \param d_func a function used to delete the user data */ -LIBSHIBOKEN_API void setTypeUserData(SbkObject* wrapper, void* userData, DeleteUserDataFunc d_func); +LIBSHIBOKEN_API void setTypeUserData(SbkObject *wrapper, void *userData, DeleteUserDataFunc d_func); /** * Get the user data previously set by Shiboken::Object::setTypeUserData */ -LIBSHIBOKEN_API void* getTypeUserData(SbkObject* wrapper); +LIBSHIBOKEN_API void *getTypeUserData(SbkObject *wrapper); /** * Increments the reference count of the referred Python object. @@ -451,7 +451,7 @@ LIBSHIBOKEN_API void* getTypeUserData(SbkObject* wrapper); * \param key a key that identifies the C++ method signature and argument where the referred Object came from. * \param referredObject the object whose reference is used by the self object. */ -LIBSHIBOKEN_API void keepReference(SbkObject* self, const char* key, PyObject* referredObject, bool append = false); +LIBSHIBOKEN_API void keepReference(SbkObject *self, const char *key, PyObject *referredObject, bool append = false); /** * Removes any reference previously added by keepReference function @@ -459,7 +459,7 @@ LIBSHIBOKEN_API void keepReference(SbkObject* self, const char* key, PyOb * \param key a key that identifies the C++ method signature and argument from where the referred Object came. * \param referredObject the object whose reference is used by the self object. */ -LIBSHIBOKEN_API void removeReference(SbkObject* self, const char* key, PyObject* referredObject); +LIBSHIBOKEN_API void removeReference(SbkObject *self, const char *key, PyObject *referredObject); } // namespace Object diff --git a/sources/shiboken2/libshiboken/basewrapper_p.h b/sources/shiboken2/libshiboken/basewrapper_p.h index f8a381078..feba6561e 100644 --- a/sources/shiboken2/libshiboken/basewrapper_p.h +++ b/sources/shiboken2/libshiboken/basewrapper_p.h @@ -61,7 +61,7 @@ namespace Shiboken typedef std::unordered_multimap<std::string, PyObject *> RefCountMap; /// Linked list of SbkBaseWrapper pointers -typedef std::set<SbkObject*> ChildrenList; +using ChildrenList = std::set<SbkObject *>; /// Structure used to store information about object parent and children. struct ParentInfo @@ -69,7 +69,7 @@ struct ParentInfo /// Default ctor. ParentInfo() : parent(0), hasWrapperRef(false) {} /// Pointer to parent object. - SbkObject* parent; + SbkObject *parent; /// List of object children. ChildrenList children; /// has internal ref @@ -88,7 +88,7 @@ extern "C" struct SbkObjectPrivate { /// Pointer to the C++ class. - void** cptr; + void ** cptr; /// True when Python is responsible for freeing the used memory. unsigned int hasOwnership : 1; /// This is true when the C++ class of the wrapped object has a virtual destructor AND was created by Python. @@ -98,9 +98,9 @@ struct SbkObjectPrivate /// Marked as true when the object constructor was called unsigned int cppObjectCreated : 1; /// Information about the object parents and children, may be null. - Shiboken::ParentInfo* parentInfo; + Shiboken::ParentInfo *parentInfo; /// Manage reference count of objects that are referred to but not owned from. - Shiboken::RefCountMap* referredObjects; + Shiboken::RefCountMap *referredObjects; ~SbkObjectPrivate() { @@ -121,8 +121,8 @@ struct SbkObjectPrivate struct SbkObjectTypePrivate { - SbkConverter* converter; - int* mi_offsets; + SbkConverter *converter; + int *mi_offsets; MultipleInheritanceInitFunction mi_init; /// Special cast function, null if this class doesn't have multiple inheritance. @@ -134,16 +134,16 @@ struct SbkObjectTypePrivate int is_multicpp : 1; /// True if this type was defined by the user. int is_user_type : 1; - /// Tells is the type is a value type or an object-type, see BEHAVIOUR_* constants. + /// Tells is the type is a value type or an object-type, see BEHAVIOUR_ *constants. // TODO-CONVERTERS: to be deprecated/removed int type_behaviour : 2; int delete_in_main_thread : 1; /// C++ name - char* original_name; + char *original_name; /// Type user data - void* user_data; + void *user_data; DeleteUserDataFunc d_func; - void (*subtype_init)(SbkObjectType*, PyObject*, PyObject*); + void (*subtype_init)(SbkObjectType *, PyObject *, PyObject *); }; @@ -165,7 +165,7 @@ struct DestructorEntry /** * Utility function used to transform a PyObject that implements sequence protocol into a std::list. **/ -std::vector<SbkObject *> splitPyObject(PyObject* pyObj); +std::vector<SbkObject *> splitPyObject(PyObject *pyObj); /** * Visitor class used by walkOnClassHierarchy function. @@ -211,7 +211,7 @@ private: class GetIndexVisitor : public HierarchyVisitor { public: - explicit GetIndexVisitor(PyTypeObject* desiredType) : m_desiredType(desiredType) {} + explicit GetIndexVisitor(PyTypeObject *desiredType) : m_desiredType(desiredType) {} bool visit(SbkObjectType *node) override; @@ -248,21 +248,21 @@ private: */ bool walkThroughClassHierarchy(PyTypeObject *currentType, HierarchyVisitor *visitor); -inline int getTypeIndexOnHierarchy(PyTypeObject* baseType, PyTypeObject* desiredType) +inline int getTypeIndexOnHierarchy(PyTypeObject *baseType, PyTypeObject *desiredType) { GetIndexVisitor visitor(desiredType); walkThroughClassHierarchy(baseType, &visitor); return visitor.index(); } -inline int getNumberOfCppBaseClasses(PyTypeObject* baseType) +inline int getNumberOfCppBaseClasses(PyTypeObject *baseType) { BaseCountVisitor visitor; walkThroughClassHierarchy(baseType, &visitor); return visitor.count(); } -inline std::vector<SbkObjectType *> getCppBaseClasses(PyTypeObject* baseType) +inline std::vector<SbkObjectType *> getCppBaseClasses(PyTypeObject *baseType) { BaseAccumulatorVisitor visitor; walkThroughClassHierarchy(baseType, &visitor); @@ -275,12 +275,12 @@ namespace Object * Decrements the reference counters of every object referred by self. * \param self the wrapper instance that keeps references to other objects. */ -void clearReferences(SbkObject* self); +void clearReferences(SbkObject *self); /** * Destroy internal data **/ -void deallocData(SbkObject* self, bool doCleanup); +void deallocData(SbkObject *self, bool doCleanup); } // namespace Object diff --git a/sources/shiboken2/libshiboken/bindingmanager.cpp b/sources/shiboken2/libshiboken/bindingmanager.cpp index 8a9e912fd..c526d9b2e 100644 --- a/sources/shiboken2/libshiboken/bindingmanager.cpp +++ b/sources/shiboken2/libshiboken/bindingmanager.cpp @@ -64,7 +64,7 @@ public: Graph() = default; - void addEdge(SbkObjectType* from, SbkObjectType* to) + void addEdge(SbkObjectType *from, SbkObjectType *to) { m_edges[from].push_back(to); } @@ -78,7 +78,7 @@ public: for (auto i = m_edges.begin(), end = m_edges.end(); i != end; ++i) { auto node1 = reinterpret_cast<const PyTypeObject *>(i->first); - const NodeList& nodeList = i->second; + const NodeList &nodeList = i->second; for (const SbkObjectType *o : nodeList) { auto node2 = reinterpret_cast<const PyTypeObject *>(o); file << '"' << node2->tp_name << "\" -> \"" @@ -89,13 +89,13 @@ public: } #endif - SbkObjectType* identifyType(void** cptr, SbkObjectType* type, SbkObjectType* baseType) const + SbkObjectType *identifyType(void **cptr, SbkObjectType *type, SbkObjectType *baseType) const { Edges::const_iterator edgesIt = m_edges.find(type); if (edgesIt != m_edges.end()) { - const NodeList& adjNodes = m_edges.find(type)->second; + const NodeList &adjNodes = m_edges.find(type)->second; for (SbkObjectType *node : adjNodes) { - SbkObjectType* newType = identifyType(cptr, node, baseType); + SbkObjectType *newType = identifyType(cptr, node, baseType); if (newType) return newType; } @@ -106,7 +106,7 @@ public: } if (typeFound) { // This "typeFound != type" is needed for backwards compatibility with old modules using a newer version of - // libshiboken because old versions of type_discovery function used to return a SbkObjectType* instead of + // libshiboken because old versions of type_discovery function used to return a SbkObjectType *instead of // a possible variation of the C++ instance pointer (*cptr). if (typeFound != type) *cptr = typeFound; @@ -118,7 +118,7 @@ public: #ifndef NDEBUG -static void showWrapperMap(const WrapperMap& wrapperMap) +static void showWrapperMap(const WrapperMap &wrapperMap) { if (Py_VerboseFlag > 0) { fprintf(stderr, "-------------------------------\n"); @@ -144,12 +144,12 @@ struct BindingManager::BindingManagerPrivate { bool destroying; BindingManagerPrivate() : destroying(false) {} - bool releaseWrapper(void* cptr, SbkObject* wrapper); - void assignWrapper(SbkObject* wrapper, const void* cptr); + bool releaseWrapper(void *cptr, SbkObject *wrapper); + void assignWrapper(SbkObject *wrapper, const void *cptr); }; -bool BindingManager::BindingManagerPrivate::releaseWrapper(void* cptr, SbkObject* wrapper) +bool BindingManager::BindingManagerPrivate::releaseWrapper(void *cptr, SbkObject *wrapper) { // The wrapper argument is checked to ensure that the correct wrapper is released. // Returns true if the correct wrapper is found and released. @@ -162,7 +162,7 @@ bool BindingManager::BindingManagerPrivate::releaseWrapper(void* cptr, SbkObject return false; } -void BindingManager::BindingManagerPrivate::assignWrapper(SbkObject* wrapper, const void* cptr) +void BindingManager::BindingManagerPrivate::assignWrapper(SbkObject *wrapper, const void *cptr) { assert(cptr); WrapperMap::iterator iter = wrapperMapper.find(cptr); @@ -192,27 +192,27 @@ BindingManager::~BindingManager() * shutting down. */ if (Py_IsInitialized()) { // ensure the interpreter is still valid while (!m_d->wrapperMapper.empty()) { - Object::destroy(m_d->wrapperMapper.begin()->second, const_cast<void*>(m_d->wrapperMapper.begin()->first)); + Object::destroy(m_d->wrapperMapper.begin()->second, const_cast<void *>(m_d->wrapperMapper.begin()->first)); } assert(m_d->wrapperMapper.empty()); } delete m_d; } -BindingManager& BindingManager::instance() { +BindingManager &BindingManager::instance() { static BindingManager singleton; return singleton; } -bool BindingManager::hasWrapper(const void* cptr) +bool BindingManager::hasWrapper(const void *cptr) { return m_d->wrapperMapper.find(cptr) != m_d->wrapperMapper.end(); } -void BindingManager::registerWrapper(SbkObject* pyObj, void* cptr) +void BindingManager::registerWrapper(SbkObject *pyObj, void *cptr) { - SbkObjectType* instanceType = reinterpret_cast<SbkObjectType*>(Py_TYPE(pyObj)); - SbkObjectTypePrivate* d = PepType_SOTP(instanceType); + auto instanceType = reinterpret_cast<SbkObjectType *>(Py_TYPE(pyObj)); + SbkObjectTypePrivate *d = PepType_SOTP(instanceType); if (!d) return; @@ -221,27 +221,27 @@ void BindingManager::registerWrapper(SbkObject* pyObj, void* cptr) d->mi_offsets = d->mi_init(cptr); m_d->assignWrapper(pyObj, cptr); if (d->mi_offsets) { - int* offset = d->mi_offsets; + int *offset = d->mi_offsets; while (*offset != -1) { if (*offset > 0) - m_d->assignWrapper(pyObj, reinterpret_cast<void*>((std::size_t) cptr + (*offset))); + m_d->assignWrapper(pyObj, reinterpret_cast<void *>((std::size_t) cptr + (*offset))); offset++; } } } -void BindingManager::releaseWrapper(SbkObject* sbkObj) +void BindingManager::releaseWrapper(SbkObject *sbkObj) { - SbkObjectType* sbkType = reinterpret_cast<SbkObjectType*>(Py_TYPE(sbkObj)); - SbkObjectTypePrivate* d = PepType_SOTP(sbkType); + auto sbkType = reinterpret_cast<SbkObjectType *>(Py_TYPE(sbkObj)); + SbkObjectTypePrivate *d = PepType_SOTP(sbkType); int numBases = ((d && d->is_multicpp) ? getNumberOfCppBaseClasses(Py_TYPE(sbkObj)) : 1); - void** cptrs = reinterpret_cast<SbkObject*>(sbkObj)->d->cptr; + void ** cptrs = reinterpret_cast<SbkObject *>(sbkObj)->d->cptr; for (int i = 0; i < numBases; ++i) { unsigned char *cptr = reinterpret_cast<unsigned char *>(cptrs[i]); m_d->releaseWrapper(cptr, sbkObj); if (d && d->mi_offsets) { - int* offset = d->mi_offsets; + int *offset = d->mi_offsets; while (*offset != -1) { if (*offset > 0) m_d->releaseWrapper(reinterpret_cast<void *>((std::size_t) cptr + (*offset)), sbkObj); @@ -264,7 +264,7 @@ void BindingManager::addToDeletionInMainThread(const DestructorEntry &e) m_d->deleteInMainThread.push_back(e); } -SbkObject* BindingManager::retrieveWrapper(const void* cptr) +SbkObject *BindingManager::retrieveWrapper(const void *cptr) { WrapperMap::iterator iter = m_d->wrapperMapper.find(cptr); if (iter == m_d->wrapperMapper.end()) @@ -272,34 +272,34 @@ SbkObject* BindingManager::retrieveWrapper(const void* cptr) return iter->second; } -PyObject* BindingManager::getOverride(const void* cptr, const char* methodName) +PyObject *BindingManager::getOverride(const void *cptr, const char *methodName) { - SbkObject* wrapper = retrieveWrapper(cptr); + SbkObject *wrapper = retrieveWrapper(cptr); // The refcount can be 0 if the object is dieing and someone called // a virtual method from the destructor if (!wrapper || reinterpret_cast<const PyObject *>(wrapper)->ob_refcnt == 0) return 0; if (wrapper->ob_dict) { - PyObject* method = PyDict_GetItemString(wrapper->ob_dict, methodName); + PyObject *method = PyDict_GetItemString(wrapper->ob_dict, methodName); if (method) { Py_INCREF(reinterpret_cast<PyObject *>(method)); return method; } } - PyObject* pyMethodName = Shiboken::String::fromCString(methodName); + PyObject *pyMethodName = Shiboken::String::fromCString(methodName); PyObject *method = PyObject_GetAttr(reinterpret_cast<PyObject *>(wrapper), pyMethodName); if (method && PyMethod_Check(method) - && PyMethod_GET_SELF(method) == reinterpret_cast<PyObject*>(wrapper)) { - PyObject* defaultMethod; - PyObject* mro = Py_TYPE(wrapper)->tp_mro; + && PyMethod_GET_SELF(method) == reinterpret_cast<PyObject *>(wrapper)) { + PyObject *defaultMethod; + PyObject *mro = Py_TYPE(wrapper)->tp_mro; // The first class in the mro (index 0) is the class being checked and it should not be tested. // The last class in the mro (size - 1) is the base Python object class which should not be tested also. for (int i = 1; i < PyTuple_GET_SIZE(mro) - 1; i++) { - PyTypeObject* parent = reinterpret_cast<PyTypeObject*>(PyTuple_GET_ITEM(mro, i)); + PyTypeObject *parent = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, i)); if (parent->tp_dict) { defaultMethod = PyDict_GetItem(parent->tp_dict, pyMethodName); if (defaultMethod && PyMethod_GET_FUNCTION(method) != defaultMethod) { @@ -315,34 +315,34 @@ PyObject* BindingManager::getOverride(const void* cptr, const char* methodName) return 0; } -void BindingManager::addClassInheritance(SbkObjectType* parent, SbkObjectType* child) +void BindingManager::addClassInheritance(SbkObjectType *parent, SbkObjectType *child) { m_d->classHierarchy.addEdge(parent, child); } -SbkObjectType* BindingManager::resolveType(void* cptr, SbkObjectType* type) +SbkObjectType *BindingManager::resolveType(void *cptr, SbkObjectType *type) { return resolveType(&cptr, type); } -SbkObjectType* BindingManager::resolveType(void** cptr, SbkObjectType* type) +SbkObjectType *BindingManager::resolveType(void **cptr, SbkObjectType *type) { - SbkObjectType* identifiedType = m_d->classHierarchy.identifyType(cptr, type, type); + SbkObjectType *identifiedType = m_d->classHierarchy.identifyType(cptr, type, type); return identifiedType ? identifiedType : type; } -std::set<PyObject*> BindingManager::getAllPyObjects() +std::set<PyObject *> BindingManager::getAllPyObjects() { - std::set<PyObject*> pyObjects; - const WrapperMap& wrappersMap = m_d->wrapperMapper; + std::set<PyObject *> pyObjects; + const WrapperMap &wrappersMap = m_d->wrapperMapper; WrapperMap::const_iterator it = wrappersMap.begin(); for (; it != wrappersMap.end(); ++it) - pyObjects.insert(reinterpret_cast<PyObject*>(it->second)); + pyObjects.insert(reinterpret_cast<PyObject *>(it->second)); return pyObjects; } -void BindingManager::visitAllPyObjects(ObjectVisitor visitor, void* data) +void BindingManager::visitAllPyObjects(ObjectVisitor visitor, void *data) { WrapperMap copy = m_d->wrapperMapper; for (WrapperMap::iterator it = copy.begin(); it != copy.end(); ++it) { diff --git a/sources/shiboken2/libshiboken/bindingmanager.h b/sources/shiboken2/libshiboken/bindingmanager.h index d03aa999a..bfcbdc79b 100644 --- a/sources/shiboken2/libshiboken/bindingmanager.h +++ b/sources/shiboken2/libshiboken/bindingmanager.h @@ -52,36 +52,36 @@ namespace Shiboken struct DestructorEntry; -typedef void (*ObjectVisitor)(SbkObject*, void*); +typedef void (*ObjectVisitor)(SbkObject *, void *); class LIBSHIBOKEN_API BindingManager { public: - BindingManager(const BindingManager&) = delete; - BindingManager(BindingManager&&) = delete; - BindingManager& operator=(const BindingManager&) = delete; - BindingManager& operator=(BindingManager&&) = delete; + BindingManager(const BindingManager &) = delete; + BindingManager(BindingManager &&) = delete; + BindingManager &operator=(const BindingManager &) = delete; + BindingManager &operator=(BindingManager &&) = delete; - static BindingManager& instance(); + static BindingManager &instance(); bool hasWrapper(const void *cptr); - void registerWrapper(SbkObject* pyObj, void* cptr); - void releaseWrapper(SbkObject* wrapper); + void registerWrapper(SbkObject *pyObj, void *cptr); + void releaseWrapper(SbkObject *wrapper); void runDeletionInMainThread(); void addToDeletionInMainThread(const DestructorEntry &); - SbkObject* retrieveWrapper(const void* cptr); - PyObject* getOverride(const void* cptr, const char* methodName); + SbkObject *retrieveWrapper(const void *cptr); + PyObject *getOverride(const void *cptr, const char *methodName); - void addClassInheritance(SbkObjectType* parent, SbkObjectType* child); + void addClassInheritance(SbkObjectType *parent, SbkObjectType *child); /** - * \deprecated Use \fn resolveType(void**, SbkObjectType*), this version is broken when used with multiple inheritance + * \deprecated Use \fn resolveType(void **, SbkObjectType *), this version is broken when used with multiple inheritance * because the \p cptr pointer of the discovered type may be different of the given \p cptr in case * of multiple inheritance */ - SBK_DEPRECATED(SbkObjectType* resolveType(void* cptr, SbkObjectType* type)); + SBK_DEPRECATED(SbkObjectType *resolveType(void *cptr, SbkObjectType *type)); /** * Try to find the correct type of *cptr knowing that it's at least of type \p type. * In case of multiple inheritance this function may change the contents of cptr. @@ -89,9 +89,9 @@ public: * \param type type of *cptr * \warning This function is slow, use it only as last resort. */ - SbkObjectType* resolveType(void** cptr, SbkObjectType* type); + SbkObjectType *resolveType(void **cptr, SbkObjectType *type); - std::set<PyObject*> getAllPyObjects(); + std::set<PyObject *> getAllPyObjects(); /** * Calls the function \p visitor for each object registered on binding manager. @@ -100,14 +100,14 @@ public: * \param visitor function called for each object. * \param data user data passed as second argument to the visitor function. */ - void visitAllPyObjects(ObjectVisitor visitor, void* data); + void visitAllPyObjects(ObjectVisitor visitor, void *data); private: ~BindingManager(); BindingManager(); struct BindingManagerPrivate; - BindingManagerPrivate* m_d; + BindingManagerPrivate *m_d; }; } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/bufferprocs_py37.cpp b/sources/shiboken2/libshiboken/bufferprocs_py37.cpp index 84d670d21..ddb07390e 100644 --- a/sources/shiboken2/libshiboken/bufferprocs_py37.cpp +++ b/sources/shiboken2/libshiboken/bufferprocs_py37.cpp @@ -147,19 +147,18 @@ PyBuffer_IsContiguous(const Pep_buffer *view, char order) } -void* +void * PyBuffer_GetPointer(Pep_buffer *view, Py_ssize_t *indices) { - char* pointer; int i; - pointer = (char *)view->buf; + auto pointer = reinterpret_cast<char *>(view->buf); for (i = 0; i < view->ndim; i++) { pointer += view->strides[i]*indices[i]; if ((view->suboffsets != NULL) && (view->suboffsets[i] >= 0)) { - pointer = *((char**)pointer) + view->suboffsets[i]; + pointer = *reinterpret_cast<char **>(pointer) + view->suboffsets[i]; } } - return (void*)pointer; + return pointer; } @@ -221,7 +220,7 @@ PyBuffer_FromContiguous(Pep_buffer *view, void *buf, Py_ssize_t len, char fort) PyErr_NoMemory(); return -1; } - for (k=0; k<view->ndim;k++) { + for (k=0; k<view->ndim; k++) { indices[k] = 0; } diff --git a/sources/shiboken2/libshiboken/debugfreehook.cpp b/sources/shiboken2/libshiboken/debugfreehook.cpp index c66866cf1..3d52d88dc 100644 --- a/sources/shiboken2/libshiboken/debugfreehook.cpp +++ b/sources/shiboken2/libshiboken/debugfreehook.cpp @@ -107,8 +107,8 @@ static int DebugAllocHook(int nAllocType, void *pvData, #endif // _WIN32 && _DEBUG #ifdef __GLIBC__ -static void (*lastFreeHook)(void* ptr, const void* caller); -static void DebugFreeHook(void* ptr, const void* caller) +static void (*lastFreeHook)(void *ptr, const void *caller); +static void DebugFreeHook(void *ptr, const void *caller) { testPointerBeingFreed(ptr); @@ -150,7 +150,7 @@ void debugInstallFreeHook(void) #endif #ifdef __APPLE__ - malloc_zone_t* zone = malloc_default_zone(); + malloc_zone_t *zone = malloc_default_zone(); assert(zone != NULL); //remove the write protection from the zone struct if (zone->version >= 8) { @@ -176,7 +176,7 @@ void debugRemoveFreeHook(void) #endif #ifdef __APPLE__ - malloc_zone_t* zone = malloc_default_zone(); + malloc_zone_t *zone = malloc_default_zone(); assert(zone != NULL); //remove the write protection from the zone struct if (zone->version >= 8) { diff --git a/sources/shiboken2/libshiboken/gilstate.h b/sources/shiboken2/libshiboken/gilstate.h index 9da4871d1..f0ff45d59 100644 --- a/sources/shiboken2/libshiboken/gilstate.h +++ b/sources/shiboken2/libshiboken/gilstate.h @@ -49,10 +49,10 @@ namespace Shiboken class LIBSHIBOKEN_API GilState { public: - GilState(const GilState&) = delete; - GilState(GilState&&) = delete; - GilState& operator=(const GilState&) = delete; - GilState& operator=(GilState&&) = delete; + GilState(const GilState &) = delete; + GilState(GilState &&) = delete; + GilState &operator=(const GilState &) = delete; + GilState &operator=(GilState &&) = delete; GilState(); ~GilState(); diff --git a/sources/shiboken2/libshiboken/helper.cpp b/sources/shiboken2/libshiboken/helper.cpp index e42daff07..1a2dc7ab9 100644 --- a/sources/shiboken2/libshiboken/helper.cpp +++ b/sources/shiboken2/libshiboken/helper.cpp @@ -51,7 +51,7 @@ namespace Shiboken { // PySide-510: Changed from PySequence to PyList, which is correct. -bool listToArgcArgv(PyObject* argList, int* argc, char*** argv, const char* defaultAppName) +bool listToArgcArgv(PyObject *argList, int *argc, char ***argv, const char *defaultAppName) { if (!PyList_Check(argList)) return false; @@ -63,7 +63,7 @@ bool listToArgcArgv(PyObject* argList, int* argc, char*** argv, const char* defa Shiboken::AutoDecRef args(PySequence_Fast(argList, 0)); int numArgs = int(PySequence_Fast_GET_SIZE(argList)); for (int i = 0; i < numArgs; ++i) { - PyObject* item = PyList_GET_ITEM(args.object(), i); + PyObject *item = PyList_GET_ITEM(args.object(), i); if (!PyBytes_Check(item) && !PyUnicode_Check(item)) return false; } @@ -73,17 +73,17 @@ bool listToArgcArgv(PyObject* argList, int* argc, char*** argv, const char* defa numArgs = 1; *argc = numArgs; - *argv = new char*[*argc]; + *argv = new char *[*argc]; if (hasEmptyArgList) { // Try to get the script name - PyObject* globals = PyEval_GetGlobals(); - PyObject* appName = PyDict_GetItemString(globals, "__file__"); + PyObject *globals = PyEval_GetGlobals(); + PyObject *appName = PyDict_GetItemString(globals, "__file__"); (*argv)[0] = strdup(appName ? Shiboken::String::toCString(appName) : defaultAppName); } else { for (int i = 0; i < numArgs; ++i) { - PyObject* item = PyList_GET_ITEM(args.object(), i); - char* string = 0; + PyObject *item = PyList_GET_ITEM(args.object(), i); + char *string = 0; if (Shiboken::String::check(item)) { string = strdup(Shiboken::String::toCString(item)); } @@ -94,17 +94,17 @@ bool listToArgcArgv(PyObject* argList, int* argc, char*** argv, const char* defa return true; } -int* sequenceToIntArray(PyObject* obj, bool zeroTerminated) +int *sequenceToIntArray(PyObject *obj, bool zeroTerminated) { AutoDecRef seq(PySequence_Fast(obj, "Sequence of ints expected")); if (seq.isNull()) return 0; Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object()); - int* array = new int[size + (zeroTerminated ? 1 : 0)]; + int *array = new int[size + (zeroTerminated ? 1 : 0)]; for (int i = 0; i < size; i++) { - PyObject* item = PySequence_Fast_GET_ITEM(seq.object(), i); + PyObject *item = PySequence_Fast_GET_ITEM(seq.object(), i); if (!PyInt_Check(item)) { PyErr_SetString(PyExc_TypeError, "Sequence of ints expected"); delete[] array; @@ -121,7 +121,7 @@ int* sequenceToIntArray(PyObject* obj, bool zeroTerminated) } -int warning(PyObject* category, int stacklevel, const char* format, ...) +int warning(PyObject *category, int stacklevel, const char *format, ...) { va_list args; va_start(args, format); @@ -134,7 +134,7 @@ int warning(PyObject* category, int stacklevel, const char* format, ...) // check the necessary memory int size = vsnprintf(NULL, 0, format, args) + 1; - char* message = new char[size]; + auto message = new char[size]; int result = 0; if (message) { // format the message diff --git a/sources/shiboken2/libshiboken/helper.h b/sources/shiboken2/libshiboken/helper.h index 9b6d8903f..6c29ad728 100644 --- a/sources/shiboken2/libshiboken/helper.h +++ b/sources/shiboken2/libshiboken/helper.h @@ -60,7 +60,7 @@ namespace Shiboken * \note The argv array is allocated using new operator and each item is allocated using malloc. * \returns True on sucess, false otherwise. */ -LIBSHIBOKEN_API bool listToArgcArgv(PyObject* argList, int* argc, char*** argv, const char* defaultAppName = 0); +LIBSHIBOKEN_API bool listToArgcArgv(PyObject *argList, int *argc, char ***argv, const char *defaultAppName = nullptr); /** * Convert a python sequence into a heap-allocated array of ints. @@ -68,7 +68,7 @@ LIBSHIBOKEN_API bool listToArgcArgv(PyObject* argList, int* argc, char*** argv, * \returns The newly allocated array or NULL in case of error or empty sequence. Check with PyErr_Occurred * if it was successfull. */ -LIBSHIBOKEN_API int* sequenceToIntArray(PyObject* obj, bool zeroTerminated = false); +LIBSHIBOKEN_API int *sequenceToIntArray(PyObject *obj, bool zeroTerminated = false); /** * Creates and automatically deallocates C++ arrays. @@ -77,17 +77,17 @@ template<class T> class AutoArrayPointer { public: - AutoArrayPointer(const AutoArrayPointer&) = delete; - AutoArrayPointer(AutoArrayPointer&&) = delete; - AutoArrayPointer& operator=(const AutoArrayPointer&) = delete; - AutoArrayPointer& operator=(AutoArrayPointer&&) = delete; + AutoArrayPointer(const AutoArrayPointer &) = delete; + AutoArrayPointer(AutoArrayPointer &&) = delete; + AutoArrayPointer &operator=(const AutoArrayPointer &) = delete; + AutoArrayPointer &operator=(AutoArrayPointer &&) = delete; explicit AutoArrayPointer(int size) { data = new T[size]; } - T& operator[](int pos) { return data[pos]; } - operator T*() const { return data; } + T &operator[](int pos) { return data[pos]; } + operator T *() const { return data; } ~AutoArrayPointer() { delete[] data; } private: - T* data; + T *data; }; typedef unsigned long long ThreadId; @@ -97,7 +97,7 @@ LIBSHIBOKEN_API ThreadId mainThreadId(); /** * An utility function used to call PyErr_WarnEx with a formatted message. */ -LIBSHIBOKEN_API int warning(PyObject* category, int stacklevel, const char* format, ...); +LIBSHIBOKEN_API int warning(PyObject *category, int stacklevel, const char *format, ...); } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/pep384_issue33738.cpp b/sources/shiboken2/libshiboken/pep384_issue33738.cpp index ee085438e..c20edeefa 100644 --- a/sources/shiboken2/libshiboken/pep384_issue33738.cpp +++ b/sources/shiboken2/libshiboken/pep384_issue33738.cpp @@ -114,7 +114,7 @@ typedef struct _oldtypeobject { int PyIndex_Check(PyObject *obj) { - PyOldTypeObject *type = reinterpret_cast<PyOldTypeObject*>(Py_TYPE(obj)); + PyOldTypeObject *type = reinterpret_cast<PyOldTypeObject *>(Py_TYPE(obj)); return type->tp_as_number != NULL && type->tp_as_number->nb_index != NULL; } diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp index 9a52603dc..ac0328b6b 100644 --- a/sources/shiboken2/libshiboken/pep384impl.cpp +++ b/sources/shiboken2/libshiboken/pep384impl.cpp @@ -59,8 +59,8 @@ extern "C" * appear at the right offsets. */ -#define make_dummy_int(x) (x * sizeof(void*)) -#define make_dummy(x) (reinterpret_cast<void*>(make_dummy_int(x))) +#define make_dummy_int(x) (x * sizeof(void *)) +#define make_dummy(x) (reinterpret_cast<void *>(make_dummy_int(x))) #ifdef Py_LIMITED_API datetime_struc *PyDateTimeAPI = NULL; diff --git a/sources/shiboken2/libshiboken/python25compat.h b/sources/shiboken2/libshiboken/python25compat.h index fc25aa3e5..b8a4950d9 100644 --- a/sources/shiboken2/libshiboken/python25compat.h +++ b/sources/shiboken2/libshiboken/python25compat.h @@ -48,9 +48,9 @@ */ #if PY_VERSION_HEX < 0x02060000 -#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) -#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) -#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) +#define Py_REFCNT(ob) (((PyObject *)(ob))->ob_refcnt) +#define Py_TYPE(ob) (((PyObject *)(ob))->ob_type) +#define Py_SIZE(ob) (((PyVarObject *)(ob))->ob_size) #define PyVarObject_HEAD_INIT(type, size) \ PyObject_HEAD_INIT(type) size, #define PyType_Modified(t) @@ -90,7 +90,7 @@ typedef struct { #define PyBytes_Concat PyString_Concat #define PyBytes_Size PyString_Size -inline PyObject* PyUnicode_FromString(const char* s) +inline PyObject *PyUnicode_FromString(const char *s) { std::size_t len = std::strlen(s); return PyUnicode_DecodeUTF8(s, len, 0); diff --git a/sources/shiboken2/libshiboken/sbkarrayconverter.h b/sources/shiboken2/libshiboken/sbkarrayconverter.h index 2b82b25b4..5b26c6e3c 100644 --- a/sources/shiboken2/libshiboken/sbkarrayconverter.h +++ b/sources/shiboken2/libshiboken/sbkarrayconverter.h @@ -74,7 +74,7 @@ template <class T> class ArrayHandle { ArrayHandle(const ArrayHandle &) = delete; - ArrayHandle& operator=(const ArrayHandle &) = delete; + ArrayHandle &operator=(const ArrayHandle &) = delete; public: ArrayHandle() {} ~ArrayHandle() { destroy(); } @@ -84,7 +84,7 @@ public: size_t size() const { return m_size; } T *data() const { return m_data; } - operator T*() const { return m_data; } + operator T *() const { return m_data; } private: void destroy(); @@ -108,7 +108,7 @@ public: Array2Handle() {} - operator RowType*() const { return m_rows; } + operator RowType *() const { return m_rows; } void setData(RowType *d) { m_rows = d; } diff --git a/sources/shiboken2/libshiboken/sbkarrayconverter_p.h b/sources/shiboken2/libshiboken/sbkarrayconverter_p.h index a5e003e9a..a7b46702b 100644 --- a/sources/shiboken2/libshiboken/sbkarrayconverter_p.h +++ b/sources/shiboken2/libshiboken/sbkarrayconverter_p.h @@ -46,7 +46,7 @@ extern "C" { -typedef PythonToCppFunc (*IsArrayConvertibleToCppFunc)(PyObject*, int dim1, int dim2); +typedef PythonToCppFunc (*IsArrayConvertibleToCppFunc)(PyObject *, int dim1, int dim2); /** * \internal * Private structure of SbkArrayConverter. diff --git a/sources/shiboken2/libshiboken/sbkconverter.cpp b/sources/shiboken2/libshiboken/sbkconverter.cpp index 4f6ebf65f..15afd5933 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.cpp +++ b/sources/shiboken2/libshiboken/sbkconverter.cpp @@ -49,7 +49,7 @@ #include <unordered_map> -static SbkConverter** PrimitiveTypeConverters; +static SbkConverter **PrimitiveTypeConverters; typedef std::unordered_map<std::string, SbkConverter *> ConvertersMap; static ConvertersMap converters; @@ -61,11 +61,11 @@ void initArrayConverters(); void init() { - static SbkConverter* primitiveTypeConverters[] = { + static SbkConverter *primitiveTypeConverters[] = { Primitive<PY_LONG_LONG>::createConverter(), Primitive<bool>::createConverter(), Primitive<char>::createConverter(), - Primitive<const char*>::createConverter(), + Primitive<const char *>::createConverter(), Primitive<double>::createConverter(), Primitive<float>::createConverter(), Primitive<int>::createConverter(), @@ -112,7 +112,7 @@ SbkConverter *createConverterObject(PyTypeObject *type, CppToPythonFunc pointerToPythonFunc, CppToPythonFunc copyToPythonFunc) { - SbkConverter* converter = new SbkConverter; + auto converter = new SbkConverter; converter->pythonType = type; // PYSIDE-595: All types are heaptypes now, so provide reference. Py_XINCREF(type); @@ -127,7 +127,7 @@ SbkConverter *createConverterObject(PyTypeObject *type, return converter; } -SbkConverter* createConverter(SbkObjectType* type, +SbkConverter *createConverter(SbkObjectType *type, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc, CppToPythonFunc pointerToPythonFunc, @@ -141,12 +141,12 @@ SbkConverter* createConverter(SbkObjectType* type, return converter; } -SbkConverter* createConverter(PyTypeObject* type, CppToPythonFunc toPythonFunc) +SbkConverter *createConverter(PyTypeObject *type, CppToPythonFunc toPythonFunc) { return createConverterObject(type, 0, 0, 0, toPythonFunc); } -void deleteConverter(SbkConverter* converter) +void deleteConverter(SbkConverter *converter) { if (converter) { converter->toCppConversions.clear(); @@ -154,37 +154,37 @@ void deleteConverter(SbkConverter* converter) } } -void setCppPointerToPythonFunction(SbkConverter* converter, CppToPythonFunc pointerToPythonFunc) +void setCppPointerToPythonFunction(SbkConverter *converter, CppToPythonFunc pointerToPythonFunc) { converter->pointerToPython = pointerToPythonFunc; } -void setPythonToCppPointerFunctions(SbkConverter* converter, +void setPythonToCppPointerFunctions(SbkConverter *converter, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc) { converter->toCppPointerConversion = std::make_pair(toCppPointerCheckFunc, toCppPointerConvFunc); } -void addPythonToCppValueConversion(SbkConverter* converter, +void addPythonToCppValueConversion(SbkConverter *converter, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc) { converter->toCppConversions.push_back(std::make_pair(isConvertibleToCppFunc, pythonToCppFunc)); } -void addPythonToCppValueConversion(SbkObjectType* type, +void addPythonToCppValueConversion(SbkObjectType *type, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc) { addPythonToCppValueConversion(PepType_SOTP(type)->converter, pythonToCppFunc, isConvertibleToCppFunc); } -PyObject* pointerToPython(SbkObjectType *type, const void *cppIn) +PyObject *pointerToPython(SbkObjectType *type, const void *cppIn) { return pointerToPython(PepType_SOTP(type)->converter, cppIn); } -PyObject* pointerToPython(const SbkConverter *converter, const void *cppIn) +PyObject *pointerToPython(const SbkConverter *converter, const void *cppIn) { assert(converter); if (!cppIn) @@ -197,12 +197,12 @@ PyObject* pointerToPython(const SbkConverter *converter, const void *cppIn) return converter->pointerToPython(cppIn); } -PyObject* referenceToPython(SbkObjectType *type, const void *cppIn) +PyObject *referenceToPython(SbkObjectType *type, const void *cppIn) { return referenceToPython(PepType_SOTP(type)->converter, cppIn); } -PyObject* referenceToPython(const SbkConverter *converter, const void *cppIn) +PyObject *referenceToPython(const SbkConverter *converter, const void *cppIn) { assert(cppIn); @@ -219,7 +219,7 @@ PyObject* referenceToPython(const SbkConverter *converter, const void *cppIn) return converter->pointerToPython(cppIn); } -static inline PyObject* CopyCppToPython(const SbkConverter *converter, const void *cppIn) +static inline PyObject *CopyCppToPython(const SbkConverter *converter, const void *cppIn) { if (!cppIn) Py_RETURN_NONE; @@ -230,11 +230,11 @@ static inline PyObject* CopyCppToPython(const SbkConverter *converter, const voi } return converter->copyToPython(cppIn); } -PyObject* copyToPython(SbkObjectType *type, const void *cppIn) +PyObject *copyToPython(SbkObjectType *type, const void *cppIn) { return CopyCppToPython(PepType_SOTP(type)->converter, cppIn); } -PyObject* copyToPython(const SbkConverter *converter, const void *cppIn) +PyObject *copyToPython(const SbkConverter *converter, const void *cppIn) { return CopyCppToPython(converter, cppIn); } @@ -284,13 +284,13 @@ PythonToCppFunc isPythonToCppReferenceConvertible(SbkObjectType *type, PyObject return isPythonToCppValueConvertible(type, pyIn); } -void nonePythonToCppNullPtr(PyObject*, void* cppOut) +void nonePythonToCppNullPtr(PyObject *, void *cppOut) { assert(cppOut); - *((void**)cppOut) = 0; + *reinterpret_cast<void **>(cppOut) = nullptr; } -void* cppPointer(PyTypeObject* desiredType, SbkObject* pyIn) +void *cppPointer(PyTypeObject *desiredType, SbkObject *pyIn) { assert(pyIn); if (!ObjectType::checkType(desiredType)) @@ -301,7 +301,7 @@ void* cppPointer(PyTypeObject* desiredType, SbkObject* pyIn) return Object::cppPointer(pyIn, desiredType); } -void pythonToCppPointer(SbkObjectType* type, PyObject* pyIn, void* cppOut) +void pythonToCppPointer(SbkObjectType *type, PyObject *pyIn, void *cppOut) { assert(type); assert(pyIn); @@ -365,14 +365,14 @@ bool isImplicitConversion(SbkObjectType *type, PythonToCppFunc toCppFunc) return toCppFunc != (*conv).second; } -void registerConverterName(SbkConverter* converter , const char* typeName) +void registerConverterName(SbkConverter *converter , const char *typeName) { ConvertersMap::iterator iter = converters.find(typeName); if (iter == converters.end()) converters.insert(std::make_pair(typeName, converter)); } -SbkConverter* getConverter(const char* typeName) +SbkConverter *getConverter(const char *typeName) { ConvertersMap::const_iterator it = converters.find(typeName); if (it != converters.end()) @@ -382,12 +382,12 @@ SbkConverter* getConverter(const char* typeName) return 0; } -SbkConverter* primitiveTypeConverter(int index) +SbkConverter *primitiveTypeConverter(int index) { return PrimitiveTypeConverters[index]; } -bool checkSequenceTypes(PyTypeObject* type, PyObject* pyIn) +bool checkSequenceTypes(PyTypeObject *type, PyObject *pyIn) { assert(type); assert(pyIn); @@ -422,7 +422,7 @@ bool convertibleSequenceTypes(SbkObjectType *type, PyObject *pyIn) return convertibleSequenceTypes(PepType_SOTP(type)->converter, pyIn); } -bool checkPairTypes(PyTypeObject* firstType, PyTypeObject* secondType, PyObject* pyIn) +bool checkPairTypes(PyTypeObject *firstType, PyTypeObject *secondType, PyObject *pyIn) { assert(firstType); assert(secondType); @@ -466,7 +466,7 @@ bool convertiblePairTypes(const SbkConverter *firstConverter, bool firstCheckExa return true; } -bool checkDictTypes(PyTypeObject* keyType, PyTypeObject* valueType, PyObject* pyIn) +bool checkDictTypes(PyTypeObject *keyType, PyTypeObject *valueType, PyObject *pyIn) { assert(keyType); assert(valueType); @@ -474,8 +474,8 @@ bool checkDictTypes(PyTypeObject* keyType, PyTypeObject* valueType, PyObject* py if (!PyDict_Check(pyIn)) return false; - PyObject* key; - PyObject* value; + PyObject *key; + PyObject *value; Py_ssize_t pos = 0; while (PyDict_Next(pyIn, &pos, &key, &value)) { if (!PyObject_TypeCheck(key, keyType)) @@ -486,7 +486,7 @@ bool checkDictTypes(PyTypeObject* keyType, PyTypeObject* valueType, PyObject* py return true; } -bool convertibleDictTypes(const SbkConverter * keyConverter, bool keyCheckExact, const SbkConverter *valueConverter, +bool convertibleDictTypes(const SbkConverter *keyConverter, bool keyCheckExact, const SbkConverter *valueConverter, bool valueCheckExact, PyObject *pyIn) { assert(keyConverter); @@ -494,8 +494,8 @@ bool convertibleDictTypes(const SbkConverter * keyConverter, bool keyCheckExact, assert(pyIn); if (!PyDict_Check(pyIn)) return false; - PyObject* key; - PyObject* value; + PyObject *key; + PyObject *value; Py_ssize_t pos = 0; while (PyDict_Next(pyIn, &pos, &key, &value)) { if (keyCheckExact) { @@ -514,14 +514,14 @@ bool convertibleDictTypes(const SbkConverter * keyConverter, bool keyCheckExact, return true; } -PyTypeObject* getPythonTypeObject(const SbkConverter *converter) +PyTypeObject *getPythonTypeObject(const SbkConverter *converter) { if (converter) return converter->pythonType; return 0; } -PyTypeObject* getPythonTypeObject(const char* typeName) +PyTypeObject *getPythonTypeObject(const char *typeName) { return getPythonTypeObject(getConverter(typeName)); } @@ -545,7 +545,7 @@ bool pythonTypeIsWrapperType(const SbkConverter *converter) return converter->pointerToPython != 0; } -SpecificConverter::SpecificConverter(const char* typeName) +SpecificConverter::SpecificConverter(const char *typeName) : m_type(InvalidConversion) { m_converter = getConverter(typeName); @@ -562,13 +562,13 @@ SpecificConverter::SpecificConverter(const char* typeName) } } -PyObject* SpecificConverter::toPython(const void* cppIn) +PyObject *SpecificConverter::toPython(const void *cppIn) { switch (m_type) { case CopyConversion: return copyToPython(m_converter, cppIn); case PointerConversion: - return pointerToPython(m_converter, *((const void**)cppIn)); + return pointerToPython(m_converter, *((const void **)cppIn)); case ReferenceConversion: return referenceToPython(m_converter, cppIn); default: @@ -577,7 +577,7 @@ PyObject* SpecificConverter::toPython(const void* cppIn) return 0; } -void SpecificConverter::toCpp(PyObject* pyIn, void* cppOut) +void SpecificConverter::toCpp(PyObject *pyIn, void *cppOut) { switch (m_type) { case CopyConversion: diff --git a/sources/shiboken2/libshiboken/sbkconverter.h b/sources/shiboken2/libshiboken/sbkconverter.h index 33c33025b..2d1735f2b 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.h +++ b/sources/shiboken2/libshiboken/sbkconverter.h @@ -77,7 +77,7 @@ struct SbkArrayConverter; * * C++ -> Python */ -typedef PyObject* (*CppToPythonFunc)(const void*); +typedef PyObject *(*CppToPythonFunc)(const void *); /** * This function converts a Python object to a C++ value, it may be @@ -90,7 +90,7 @@ typedef PyObject* (*CppToPythonFunc)(const void*); * * Python -> C++ */ -typedef void (*PythonToCppFunc)(PyObject*,void*); +typedef void (*PythonToCppFunc)(PyObject *,void *); /** * Checks if the Python object passed in the argument is convertible to a @@ -101,7 +101,7 @@ typedef void (*PythonToCppFunc)(PyObject*,void*); * * Python -> C++ ? */ -typedef PythonToCppFunc (*IsConvertibleToCppFunc)(PyObject*); +typedef PythonToCppFunc (*IsConvertibleToCppFunc)(PyObject *); } // extern "C" @@ -120,20 +120,20 @@ public: ReferenceConversion }; - explicit SpecificConverter(const char* typeName); + explicit SpecificConverter(const char *typeName); - inline SbkConverter* converter() { return m_converter; } - inline operator SbkConverter*() const { return m_converter; } + inline SbkConverter *converter() { return m_converter; } + inline operator SbkConverter *() const { return m_converter; } inline bool isValid() { return m_type != InvalidConversion; } inline operator bool() const { return m_type != InvalidConversion; } inline Type conversionType() { return m_type; } - PyObject* toPython(const void* cppIn); - void toCpp(PyObject* pyIn, void* cppOut); + PyObject *toPython(const void *cppIn); + void toCpp(PyObject *pyIn, void *cppOut); private: - SbkConverter* m_converter; + SbkConverter *m_converter; Type m_type; }; @@ -147,7 +147,7 @@ private: * \param copyToPythonFunc Function to convert a C++ object to a Python \p type, copying the object. * \returns The new converter referred by the wrapper \p type. */ -LIBSHIBOKEN_API SbkConverter* createConverter(SbkObjectType* type, +LIBSHIBOKEN_API SbkConverter *createConverter(SbkObjectType *type, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc, CppToPythonFunc pointerToPythonFunc, @@ -159,15 +159,15 @@ LIBSHIBOKEN_API SbkConverter* createConverter(SbkObjectType* type, * \param toPythonFunc Function to convert a C++ object to a Python \p type. * \returns A new type converter. */ -LIBSHIBOKEN_API SbkConverter* createConverter(PyTypeObject* type, CppToPythonFunc toPythonFunc); +LIBSHIBOKEN_API SbkConverter *createConverter(PyTypeObject *type, CppToPythonFunc toPythonFunc); -LIBSHIBOKEN_API void deleteConverter(SbkConverter* converter); +LIBSHIBOKEN_API void deleteConverter(SbkConverter *converter); /// Sets the Python object to C++ pointer conversion function. -LIBSHIBOKEN_API void setCppPointerToPythonFunction(SbkConverter* converter, CppToPythonFunc pointerToPythonFunc); +LIBSHIBOKEN_API void setCppPointerToPythonFunction(SbkConverter *converter, CppToPythonFunc pointerToPythonFunc); /// Sets the C++ pointer to Python object conversion functions. -LIBSHIBOKEN_API void setPythonToCppPointerFunctions(SbkConverter* converter, +LIBSHIBOKEN_API void setPythonToCppPointerFunctions(SbkConverter *converter, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc); @@ -175,10 +175,10 @@ LIBSHIBOKEN_API void setPythonToCppPointerFunctions(SbkConverter* converter, * Adds a new conversion of a Python object to a C++ value. * This is used in copy and implicit conversions. */ -LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkConverter* converter, +LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkConverter *converter, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc); -LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkObjectType* type, +LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkObjectType *type, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc); @@ -188,11 +188,11 @@ LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkObjectType* type, * Retrieves the Python wrapper object for the given \p cppIn C++ pointer object. * This function is used only for Value and Object Types. * Example usage: - * TYPE* var; - * PyObject* pyVar = pointerToPython(SBKTYPE, &var); + * TYPE *var; + * PyObject *pyVar = pointerToPython(SBKTYPE, &var); */ -LIBSHIBOKEN_API PyObject* pointerToPython(SbkObjectType *type, const void *cppIn); -LIBSHIBOKEN_API PyObject* pointerToPython(const SbkConverter *converter, const void *cppIn); +LIBSHIBOKEN_API PyObject *pointerToPython(SbkObjectType *type, const void *cppIn); +LIBSHIBOKEN_API PyObject *pointerToPython(const SbkConverter *converter, const void *cppIn); /** * For the given \p cppIn C++ reference it returns the Python wrapper object, @@ -200,21 +200,21 @@ LIBSHIBOKEN_API PyObject* pointerToPython(const SbkConverter *converter, const v * for when the latter doesn't have an existing wrapper type, the C++ object * is copied to Python. * Example usage: - * TYPE& var = SOMETHING; - * PyObject* pyVar = referenceToPython(SBKTYPE, &var); + * TYPE &var = SOMETHING; + * PyObject *pyVar = referenceToPython(SBKTYPE, &var); */ -LIBSHIBOKEN_API PyObject* referenceToPython(SbkObjectType *type, const void *cppIn); -LIBSHIBOKEN_API PyObject* referenceToPython(const SbkConverter *converter, const void *cppIn); +LIBSHIBOKEN_API PyObject *referenceToPython(SbkObjectType *type, const void *cppIn); +LIBSHIBOKEN_API PyObject *referenceToPython(const SbkConverter *converter, const void *cppIn); /** * Retrieves the Python wrapper object for the given C++ value pointed by \p cppIn. * This function is used only for Value Types. * Example usage: * TYPE var; - * PyObject* pyVar = copyToPython(SBKTYPE, &var); + * PyObject *pyVar = copyToPython(SBKTYPE, &var); */ -LIBSHIBOKEN_API PyObject* copyToPython(SbkObjectType *type, const void *cppIn); -LIBSHIBOKEN_API PyObject* copyToPython(const SbkConverter *converter, const void *cppIn); +LIBSHIBOKEN_API PyObject *copyToPython(SbkObjectType *type, const void *cppIn); +LIBSHIBOKEN_API PyObject *copyToPython(const SbkConverter *converter, const void *cppIn); // Python -> C++ --------------------------------------------------------------------------- @@ -250,10 +250,10 @@ LIBSHIBOKEN_API PythonToCppFunc isPythonToCppConvertible(const SbkArrayConverter * It differs from Shiboken::Object::cppPointer because it casts the pointer to a proper * memory offset depending on the desired type. */ -LIBSHIBOKEN_API void* cppPointer(PyTypeObject* desiredType, SbkObject* pyIn); +LIBSHIBOKEN_API void *cppPointer(PyTypeObject *desiredType, SbkObject *pyIn); /// Converts a Python object \p pyIn to C++ and stores the result in the C++ pointer passed in \p cppOut. -LIBSHIBOKEN_API void pythonToCppPointer(SbkObjectType* type, PyObject* pyIn, void* cppOut); +LIBSHIBOKEN_API void pythonToCppPointer(SbkObjectType *type, PyObject *pyIn, void *cppOut); LIBSHIBOKEN_API void pythonToCppPointer(const SbkConverter *converter, PyObject *pyIn, void *cppOut); /// Converts a Python object \p pyIn to C++, and copies the result in the C++ variable passed in \p cppOut. @@ -264,7 +264,7 @@ LIBSHIBOKEN_API void pythonToCppCopy(const SbkConverter *converter, PyObject *py * Helper function returned by generated convertible checking functions * that returns a C++ NULL when the input Python object is None. */ -LIBSHIBOKEN_API void nonePythonToCppNullPtr(PyObject*, void* cppOut); +LIBSHIBOKEN_API void nonePythonToCppNullPtr(PyObject *, void *cppOut); /** * Returns true if the \p toCpp function passed is an implicit conversion of Python \p type. @@ -274,16 +274,16 @@ LIBSHIBOKEN_API void nonePythonToCppNullPtr(PyObject*, void* cppOut); LIBSHIBOKEN_API bool isImplicitConversion(SbkObjectType *type, PythonToCppFunc toCpp); /// Registers a converter with a type name that may be used to retrieve the converter. -LIBSHIBOKEN_API void registerConverterName(SbkConverter* converter, const char* typeName); +LIBSHIBOKEN_API void registerConverterName(SbkConverter *converter, const char *typeName); /// Returns the converter for a given type name, or NULL if it wasn't registered before. -LIBSHIBOKEN_API SbkConverter* getConverter(const char* typeName); +LIBSHIBOKEN_API SbkConverter *getConverter(const char *typeName); /// Returns the converter for a primitive type. -LIBSHIBOKEN_API SbkConverter* primitiveTypeConverter(int index); +LIBSHIBOKEN_API SbkConverter *primitiveTypeConverter(int index); /// Returns true if a Python sequence is comprised of objects of the given \p type. -LIBSHIBOKEN_API bool checkSequenceTypes(PyTypeObject* type, PyObject* pyIn); +LIBSHIBOKEN_API bool checkSequenceTypes(PyTypeObject *type, PyObject *pyIn); /// Returns true if a Python sequence is comprised of objects of a type convertible to the one represented by the given \p converter. LIBSHIBOKEN_API bool convertibleSequenceTypes(const SbkConverter *converter, PyObject *pyIn); @@ -292,7 +292,7 @@ LIBSHIBOKEN_API bool convertibleSequenceTypes(const SbkConverter *converter, PyO LIBSHIBOKEN_API bool convertibleSequenceTypes(SbkObjectType *type, PyObject *pyIn); /// Returns true if a Python sequence can be converted to a C++ pair. -LIBSHIBOKEN_API bool checkPairTypes(PyTypeObject* firstType, PyTypeObject* secondType, PyObject* pyIn); +LIBSHIBOKEN_API bool checkPairTypes(PyTypeObject *firstType, PyTypeObject *secondType, PyObject *pyIn); /// Returns true if a Python sequence can be converted to a C++ pair. LIBSHIBOKEN_API bool convertiblePairTypes(const SbkConverter *firstConverter, bool firstCheckExact, @@ -300,7 +300,7 @@ LIBSHIBOKEN_API bool convertiblePairTypes(const SbkConverter *firstConverter, bo PyObject *pyIn); /// Returns true if a Python dictionary can be converted to a C++ hash or map. -LIBSHIBOKEN_API bool checkDictTypes(PyTypeObject* keyType, PyTypeObject* valueType, PyObject* pyIn); +LIBSHIBOKEN_API bool checkDictTypes(PyTypeObject *keyType, PyTypeObject *valueType, PyObject *pyIn); /// Returns true if a Python dictionary can be converted to a C++ hash or map. LIBSHIBOKEN_API bool convertibleDictTypes(const SbkConverter *keyConverter, bool keyCheckExact, @@ -308,10 +308,10 @@ LIBSHIBOKEN_API bool convertibleDictTypes(const SbkConverter *keyConverter, bool PyObject *pyIn); /// Returns the Python type object associated with the given \p converter. -LIBSHIBOKEN_API PyTypeObject* getPythonTypeObject(const SbkConverter *converter); +LIBSHIBOKEN_API PyTypeObject *getPythonTypeObject(const SbkConverter *converter); /// Returns the Python type object for the given \p typeName. -LIBSHIBOKEN_API PyTypeObject* getPythonTypeObject(const char* typeName); +LIBSHIBOKEN_API PyTypeObject *getPythonTypeObject(const char *typeName); /// Returns true if the Python type associated with the converter is a value type. LIBSHIBOKEN_API bool pythonTypeIsValueType(const SbkConverter *converter); @@ -343,25 +343,25 @@ LIBSHIBOKEN_API bool pythonTypeIsWrapperType(const SbkConverter *converter); #define SBK_VOIDPTR_IDX 16 #define SBK_NULLPTR_T_IDX 17 -template<typename T> SbkConverter* PrimitiveTypeConverter() { return 0; } -template<> inline SbkConverter* PrimitiveTypeConverter<PY_LONG_LONG>() { return primitiveTypeConverter(SBK_PY_LONG_LONG_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<bool>() { return primitiveTypeConverter(SBK_BOOL_IDX_1); } -template<> inline SbkConverter* PrimitiveTypeConverter<char>() { return primitiveTypeConverter(SBK_CHAR_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<const char*>() { return primitiveTypeConverter(SBK_CONSTCHARPTR_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<double>() { return primitiveTypeConverter(SBK_DOUBLE_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<float>() { return primitiveTypeConverter(SBK_FLOAT_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<int>() { return primitiveTypeConverter(SBK_INT_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<long>() { return primitiveTypeConverter(SBK_LONG_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<short>() { return primitiveTypeConverter(SBK_SHORT_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<signed char>() { return primitiveTypeConverter(SBK_SIGNEDCHAR_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<std::string>() { return primitiveTypeConverter(SBK_STD_STRING_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<unsigned PY_LONG_LONG>() { return primitiveTypeConverter(SBK_UNSIGNEDPY_LONG_LONG_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<unsigned char>() { return primitiveTypeConverter(SBK_UNSIGNEDCHAR_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<unsigned int>() { return primitiveTypeConverter(SBK_UNSIGNEDINT_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<unsigned long>() { return primitiveTypeConverter(SBK_UNSIGNEDLONG_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<unsigned short>() { return primitiveTypeConverter(SBK_UNSIGNEDSHORT_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<void*>() { return primitiveTypeConverter(SBK_VOIDPTR_IDX); } -template<> inline SbkConverter* PrimitiveTypeConverter<std::nullptr_t>() { return primitiveTypeConverter(SBK_NULLPTR_T_IDX); } +template<typename T> SbkConverter *PrimitiveTypeConverter() { return 0; } +template<> inline SbkConverter *PrimitiveTypeConverter<PY_LONG_LONG>() { return primitiveTypeConverter(SBK_PY_LONG_LONG_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<bool>() { return primitiveTypeConverter(SBK_BOOL_IDX_1); } +template<> inline SbkConverter *PrimitiveTypeConverter<char>() { return primitiveTypeConverter(SBK_CHAR_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<const char *>() { return primitiveTypeConverter(SBK_CONSTCHARPTR_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<double>() { return primitiveTypeConverter(SBK_DOUBLE_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<float>() { return primitiveTypeConverter(SBK_FLOAT_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<int>() { return primitiveTypeConverter(SBK_INT_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<long>() { return primitiveTypeConverter(SBK_LONG_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<short>() { return primitiveTypeConverter(SBK_SHORT_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<signed char>() { return primitiveTypeConverter(SBK_SIGNEDCHAR_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<std::string>() { return primitiveTypeConverter(SBK_STD_STRING_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<unsigned PY_LONG_LONG>() { return primitiveTypeConverter(SBK_UNSIGNEDPY_LONG_LONG_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<unsigned char>() { return primitiveTypeConverter(SBK_UNSIGNEDCHAR_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<unsigned int>() { return primitiveTypeConverter(SBK_UNSIGNEDINT_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<unsigned long>() { return primitiveTypeConverter(SBK_UNSIGNEDLONG_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<unsigned short>() { return primitiveTypeConverter(SBK_UNSIGNEDSHORT_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<void *>() { return primitiveTypeConverter(SBK_VOIDPTR_IDX); } +template<> inline SbkConverter *PrimitiveTypeConverter<std::nullptr_t>() { return primitiveTypeConverter(SBK_NULLPTR_T_IDX); } } // namespace Shiboken::Conversions @@ -371,24 +371,24 @@ template<> inline SbkConverter* PrimitiveTypeConverter<std::nullptr_t>() { retur * T isn't a C++ primitive type. * \see SpecialCastFunction */ -template<typename T> PyTypeObject* SbkType() { return 0; } +template<typename T> PyTypeObject *SbkType() { return 0; } // Below are the template specializations for C++ primitive types. -template<> inline PyTypeObject* SbkType<PY_LONG_LONG>() { return &PyLong_Type; } -template<> inline PyTypeObject* SbkType<bool>() { return &PyBool_Type; } -template<> inline PyTypeObject* SbkType<char>() { return &PyInt_Type; } -template<> inline PyTypeObject* SbkType<double>() { return &PyFloat_Type; } -template<> inline PyTypeObject* SbkType<float>() { return &PyFloat_Type; } -template<> inline PyTypeObject* SbkType<int>() { return &PyInt_Type; } -template<> inline PyTypeObject* SbkType<long>() { return &PyLong_Type; } -template<> inline PyTypeObject* SbkType<short>() { return &PyInt_Type; } -template<> inline PyTypeObject* SbkType<signed char>() { return &PyInt_Type; } -template<> inline PyTypeObject* SbkType<unsigned PY_LONG_LONG>() { return &PyLong_Type; } -template<> inline PyTypeObject* SbkType<unsigned char>() { return &PyInt_Type; } -template<> inline PyTypeObject* SbkType<unsigned int>() { return &PyLong_Type; } -template<> inline PyTypeObject* SbkType<unsigned long>() { return &PyLong_Type; } -template<> inline PyTypeObject* SbkType<unsigned short>() { return &PyInt_Type; } -template<> inline PyTypeObject* SbkType<std::nullptr_t>() { return Py_TYPE(&_Py_NoneStruct); } +template<> inline PyTypeObject *SbkType<PY_LONG_LONG>() { return &PyLong_Type; } +template<> inline PyTypeObject *SbkType<bool>() { return &PyBool_Type; } +template<> inline PyTypeObject *SbkType<char>() { return &PyInt_Type; } +template<> inline PyTypeObject *SbkType<double>() { return &PyFloat_Type; } +template<> inline PyTypeObject *SbkType<float>() { return &PyFloat_Type; } +template<> inline PyTypeObject *SbkType<int>() { return &PyInt_Type; } +template<> inline PyTypeObject *SbkType<long>() { return &PyLong_Type; } +template<> inline PyTypeObject *SbkType<short>() { return &PyInt_Type; } +template<> inline PyTypeObject *SbkType<signed char>() { return &PyInt_Type; } +template<> inline PyTypeObject *SbkType<unsigned PY_LONG_LONG>() { return &PyLong_Type; } +template<> inline PyTypeObject *SbkType<unsigned char>() { return &PyInt_Type; } +template<> inline PyTypeObject *SbkType<unsigned int>() { return &PyLong_Type; } +template<> inline PyTypeObject *SbkType<unsigned long>() { return &PyLong_Type; } +template<> inline PyTypeObject *SbkType<unsigned short>() { return &PyInt_Type; } +template<> inline PyTypeObject *SbkType<std::nullptr_t>() { return Py_TYPE(&_Py_NoneStruct); } } // namespace Shiboken @@ -398,7 +398,7 @@ template<> inline PyTypeObject* SbkType<std::nullptr_t>() { return Py_TYPE(&_Py_ #define SbkChar_Check(X) (SbkNumber_Check(X) || Shiboken::String::checkChar(X)) struct _SbkGenericTypePrivate { - SbkConverter** converter; + SbkConverter **converter; }; diff --git a/sources/shiboken2/libshiboken/sbkconverter_p.h b/sources/shiboken2/libshiboken/sbkconverter_p.h index cb968ed89..aa90094af 100644 --- a/sources/shiboken2/libshiboken/sbkconverter_p.h +++ b/sources/shiboken2/libshiboken/sbkconverter_p.h @@ -69,7 +69,7 @@ struct SbkConverter * Python type to which the C++ value will be converted (note that the * C++ type could be produced from various Python types). */ - PyTypeObject* pythonType; + PyTypeObject *pythonType; /** * This function converts a C++ object to a Python object of the type * indicated in pythonType. The identity of the C++ object is kept, @@ -77,7 +77,7 @@ struct SbkConverter * with the C++ instance. * It is used to convert C++ pointers and references to Python objects. */ - CppToPythonFunc pointerToPython; + CppToPythonFunc pointerToPython; /** * This function converts a C++ object to a Python object of the type * indicated in pythonType. The identity of the object is not kept, @@ -86,17 +86,17 @@ struct SbkConverter * reference can't be traced to an object that already has a Python * wrapper assigned for it. */ - CppToPythonFunc copyToPython; + CppToPythonFunc copyToPython; /** * This is a special case of a Python to C++ conversion. It returns * the underlying C++ pointer of a Python wrapper passed as parameter * or NULL if the Python object is a None value. * It comes separated from the other toCppConversions because if you * have a Python object representing a Value Type the type checking - * for both ValueType and ValueType* would be the same, thus the first + * for both ValueType and ValueType *would be the same, thus the first * check would be true and the second would never be reached. */ - ToCppConversion toCppPointerConversion; + ToCppConversion toCppPointerConversion; /** * This is a list of type checking functions that return the * proper Python to C++ conversion function, for the given Python @@ -104,14 +104,14 @@ struct SbkConverter * For Object Types, that never have implicit conversions, this * list is always empty. */ - ToCppConversionVector toCppConversions; + ToCppConversionVector toCppConversions; }; } // extern "C" template<typename T, typename MaxLimitType, bool isSigned> struct OverFlowCheckerBase { - static void formatOverFlowMessage(const MaxLimitType& value, + static void formatOverFlowMessage(const MaxLimitType &value, const std::string *valueAsString = 0) { std::ostringstream str; @@ -157,7 +157,7 @@ struct OverFlowChecker; template<typename T, typename MaxLimitType> struct OverFlowChecker<T, MaxLimitType, true> : public OverFlowCheckerBase<T, MaxLimitType, true> { - static bool check(const MaxLimitType& value, PyObject *pyIn) + static bool check(const MaxLimitType &value, PyObject *pyIn) { std::string valueAsString; const bool isOverflow = @@ -173,7 +173,7 @@ struct OverFlowChecker<T, MaxLimitType, true> : template<typename T, typename MaxLimitType> struct OverFlowChecker<T, MaxLimitType, false> : public OverFlowCheckerBase<T, MaxLimitType, false> { - static bool check(const MaxLimitType& value, PyObject *pyIn) + static bool check(const MaxLimitType &value, PyObject *pyIn) { std::string valueAsString; const bool isOverflow = @@ -204,7 +204,7 @@ struct OverFlowChecker<double, PY_LONG_LONG, true> { template<> struct OverFlowChecker<float, PY_LONG_LONG, true> : public OverFlowCheckerBase<float, PY_LONG_LONG, true> { - static bool check(const double& value, PyObject *) + static bool check(const double &value, PyObject *) { const bool result = value < std::numeric_limits<float>::min() || value > std::numeric_limits<float>::max(); @@ -221,12 +221,12 @@ template <typename T> struct Primitive {}; template <typename T> struct OnePrimitive { - static PyObject* toPython(const void*) { return 0; } - static PythonToCppFunc isConvertible(PyObject*) { return 0; } - static void toCpp(PyObject*, void*) {} - static SbkConverter* createConverter() + static PyObject *toPython(const void *) { return nullptr; } + static PythonToCppFunc isConvertible(PyObject *) { return nullptr; } + static void toCpp(PyObject *, void *) {} + static SbkConverter *createConverter() { - SbkConverter* converter = Shiboken::Conversions::createConverter(Shiboken::SbkType<T>(), + SbkConverter *converter = Shiboken::Conversions::createConverter(Shiboken::SbkType<T>(), Primitive<T>::toPython); Shiboken::Conversions::addPythonToCppValueConversion(converter, Primitive<T>::toCpp, @@ -237,11 +237,11 @@ struct OnePrimitive template <typename T> struct TwoPrimitive : OnePrimitive<T> { - static PythonToCppFunc isOtherConvertible(PyObject*) { return 0; } - static void otherToCpp(PyObject*, void*) {} - static SbkConverter* createConverter() + static PythonToCppFunc isOtherConvertible(PyObject *) { return nullptr; } + static void otherToCpp(PyObject *, void *) {} + static SbkConverter *createConverter() { - SbkConverter* converter = OnePrimitive<T>::createConverter(); + SbkConverter *converter = OnePrimitive<T>::createConverter(); Shiboken::Conversions::addPythonToCppValueConversion(converter, Primitive<T>::otherToCpp, Primitive<T>::isOtherConvertible); return converter; } @@ -252,11 +252,11 @@ struct TwoPrimitive : OnePrimitive<T> template <typename INT> struct IntPrimitive : TwoPrimitive<INT> { - static PyObject* toPython(const void* cppIn) + static PyObject *toPython(const void *cppIn) { return PyInt_FromLong(*reinterpret_cast<const INT *>(cppIn)); } - static void toCpp(PyObject* pyIn, void* cppOut) + static void toCpp(PyObject *pyIn, void *cppOut) { double result = PyFloat_AS_DOUBLE(pyIn); // If cast to long directly it could overflow silently. @@ -264,20 +264,20 @@ struct IntPrimitive : TwoPrimitive<INT> PyErr_SetObject(PyExc_OverflowError, 0); *reinterpret_cast<INT * >(cppOut) = static_cast<INT>(result); } - static PythonToCppFunc isConvertible(PyObject* pyIn) + static PythonToCppFunc isConvertible(PyObject *pyIn) { if (PyFloat_Check(pyIn)) return toCpp; return 0; } - static void otherToCpp(PyObject* pyIn, void* cppOut) + static void otherToCpp(PyObject *pyIn, void *cppOut) { PY_LONG_LONG result = PyLong_AsLongLong(pyIn); if (OverFlowChecker<INT>::check(result, pyIn)) PyErr_SetObject(PyExc_OverflowError, 0); *reinterpret_cast<INT * >(cppOut) = static_cast<INT>(result); } - static PythonToCppFunc isOtherConvertible(PyObject* pyIn) + static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return otherToCpp; @@ -294,7 +294,7 @@ template <> struct Primitive<unsigned short> : IntPrimitive<unsigned short> {}; template <typename LONG> struct UnsignedLongPrimitive : IntPrimitive<LONG> { - static PyObject* toPython(const void* cppIn) + static PyObject *toPython(const void *cppIn) { return PyLong_FromUnsignedLong(*reinterpret_cast<const LONG *>(cppIn)); } @@ -307,18 +307,18 @@ template <> struct Primitive<unsigned long> : UnsignedLongPrimitive<unsigned lon template <> struct Primitive<PY_LONG_LONG> : OnePrimitive<PY_LONG_LONG> { - static PyObject* toPython(const void* cppIn) + static PyObject *toPython(const void *cppIn) { - return PyLong_FromLongLong(*((PY_LONG_LONG*)cppIn)); + return PyLong_FromLongLong(*reinterpret_cast<const PY_LONG_LONG *>(cppIn)); } - static void toCpp(PyObject* pyIn, void* cppOut) + static void toCpp(PyObject *pyIn, void *cppOut) { PY_LONG_LONG result = PyLong_AsLongLong(pyIn); if (OverFlowChecker<PY_LONG_LONG>::check(result, pyIn)) PyErr_SetObject(PyExc_OverflowError, 0); *reinterpret_cast<PY_LONG_LONG * >(cppOut) = result; } - static PythonToCppFunc isConvertible(PyObject* pyIn) + static PythonToCppFunc isConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return toCpp; @@ -329,11 +329,11 @@ struct Primitive<PY_LONG_LONG> : OnePrimitive<PY_LONG_LONG> template <> struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG> { - static PyObject* toPython(const void* cppIn) + static PyObject *toPython(const void *cppIn) { - return PyLong_FromUnsignedLongLong(*((unsigned PY_LONG_LONG*)cppIn)); + return PyLong_FromUnsignedLongLong(*reinterpret_cast<const unsigned PY_LONG_LONG *>(cppIn)); } - static void toCpp(PyObject* pyIn, void* cppOut) + static void toCpp(PyObject *pyIn, void *cppOut) { #if PY_MAJOR_VERSION >= 3 if (PyLong_Check(pyIn)) { @@ -362,7 +362,7 @@ struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG> } #endif // Python 2 } - static PythonToCppFunc isConvertible(PyObject* pyIn) + static PythonToCppFunc isConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return toCpp; @@ -375,25 +375,25 @@ struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG> template <typename FLOAT> struct FloatPrimitive : TwoPrimitive<FLOAT> { - static PyObject* toPython(const void* cppIn) + static PyObject *toPython(const void *cppIn) { return PyFloat_FromDouble(*reinterpret_cast<const FLOAT *>(cppIn)); } - static void toCpp(PyObject* pyIn, void* cppOut) + static void toCpp(PyObject *pyIn, void *cppOut) { *reinterpret_cast<FLOAT *>(cppOut) = FLOAT(PyLong_AsLong(pyIn)); } - static PythonToCppFunc isConvertible(PyObject* pyIn) + static PythonToCppFunc isConvertible(PyObject *pyIn) { if (PyInt_Check(pyIn) || PyLong_Check(pyIn)) return toCpp; return 0; } - static void otherToCpp(PyObject* pyIn, void* cppOut) + static void otherToCpp(PyObject *pyIn, void *cppOut) { *reinterpret_cast<FLOAT *>(cppOut) = FLOAT(PyFloat_AsDouble(pyIn)); } - static PythonToCppFunc isOtherConvertible(PyObject* pyIn) + static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return otherToCpp; @@ -408,17 +408,17 @@ template <> struct Primitive<double> : FloatPrimitive<double> {}; template <> struct Primitive<bool> : OnePrimitive<bool> { - static PyObject* toPython(const void* cppIn) + static PyObject *toPython(const void *cppIn) { return PyBool_FromLong(*reinterpret_cast<const bool *>(cppIn)); } - static PythonToCppFunc isConvertible(PyObject* pyIn) + static PythonToCppFunc isConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return toCpp; return 0; } - static void toCpp(PyObject* pyIn, void* cppOut) + static void toCpp(PyObject *pyIn, void *cppOut) { *reinterpret_cast<bool *>(cppOut) = PyInt_AS_LONG(pyIn) != 0; } @@ -429,32 +429,32 @@ struct Primitive<bool> : OnePrimitive<bool> template <typename CHAR> struct CharPrimitive : IntPrimitive<CHAR> { - static void toCpp(PyObject* pyIn, void* cppOut) + static void toCpp(PyObject *pyIn, void *cppOut) { *reinterpret_cast<CHAR *>(cppOut) = CHAR(Shiboken::String::toCString(pyIn)[0]); } - static PythonToCppFunc isConvertible(PyObject* pyIn) + static PythonToCppFunc isConvertible(PyObject *pyIn) { if (Shiboken::String::checkChar(pyIn)) return toCpp; return 0; } - static void otherToCpp(PyObject* pyIn, void* cppOut) + static void otherToCpp(PyObject *pyIn, void *cppOut) { PY_LONG_LONG result = PyLong_AsLongLong(pyIn); if (OverFlowChecker<CHAR>::check(result, pyIn)) PyErr_SetObject(PyExc_OverflowError, 0); *reinterpret_cast<CHAR *>(cppOut) = CHAR(result); } - static PythonToCppFunc isOtherConvertible(PyObject* pyIn) + static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return otherToCpp; return 0; } - static SbkConverter* createConverter() + static SbkConverter *createConverter() { - SbkConverter* converter = IntPrimitive<CHAR>::createConverter(); + SbkConverter *converter = IntPrimitive<CHAR>::createConverter(); Shiboken::Conversions::addPythonToCppValueConversion(converter, CharPrimitive<CHAR>::otherToCpp, CharPrimitive<CHAR>::isOtherConvertible); return converter; } @@ -464,8 +464,8 @@ template <> struct Primitive<signed char> : CharPrimitive<signed char> {}; template <> struct Primitive<unsigned char> : CharPrimitive<unsigned char> {}; template <> struct Primitive<char> : CharPrimitive<char> { using CharPrimitive<char>::toPython; - static PyObject* toPython(const void* cppIn) { - return Shiboken::String::fromCString((const char*)cppIn, 1); + static PyObject *toPython(const void *cppIn) { + return Shiboken::String::fromCString(reinterpret_cast<const char *>(cppIn), 1); } }; @@ -474,29 +474,29 @@ template <> struct Primitive<char> : CharPrimitive<char> { // Strings --------------------------------------------------------------------------------- template <> -struct Primitive<const char*> : TwoPrimitive<const char*> +struct Primitive<const char *> : TwoPrimitive<const char *> { - static PyObject* toPython(const void* cppIn) + static PyObject *toPython(const void *cppIn) { if (!cppIn) Py_RETURN_NONE; - return Shiboken::String::fromCString((const char*)cppIn); + return Shiboken::String::fromCString(reinterpret_cast<const char *>(cppIn)); } static void toCpp(PyObject *, void *cppOut) { - *((const char**)cppOut) = 0; + *((const char **)cppOut) = 0; } - static PythonToCppFunc isConvertible(PyObject* pyIn) + static PythonToCppFunc isConvertible(PyObject *pyIn) { if (pyIn == Py_None) return toCpp; return 0; } - static void otherToCpp(PyObject* pyIn, void* cppOut) + static void otherToCpp(PyObject *pyIn, void *cppOut) { - *((const char**)cppOut) = (const char*) Shiboken::String::toCString(pyIn); + *reinterpret_cast<const char **>(cppOut) = Shiboken::String::toCString(pyIn); } - static PythonToCppFunc isOtherConvertible(PyObject* pyIn) + static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (Shiboken::String::check(pyIn)) return otherToCpp; @@ -507,25 +507,25 @@ struct Primitive<const char*> : TwoPrimitive<const char*> template <> struct Primitive<std::string> : TwoPrimitive<std::string> { - static PyObject* toPython(const void* cppIn) + static PyObject *toPython(const void *cppIn) { - return Shiboken::String::fromCString(((std::string*)cppIn)->c_str()); + return Shiboken::String::fromCString(reinterpret_cast<const std::string *>(cppIn)->c_str()); } static void toCpp(PyObject *, void *cppOut) { - *((std::string*)cppOut) = std::string(); + reinterpret_cast<std::string *>(cppOut)->clear(); } - static PythonToCppFunc isConvertible(PyObject* pyIn) + static PythonToCppFunc isConvertible(PyObject *pyIn) { if (pyIn == Py_None) return toCpp; return 0; } - static void otherToCpp(PyObject* pyIn, void* cppOut) + static void otherToCpp(PyObject *pyIn, void *cppOut) { - *((std::string*)cppOut) = Shiboken::String::toCString(pyIn); + reinterpret_cast<std::string *>(cppOut)->assign(Shiboken::String::toCString(pyIn)); } - static PythonToCppFunc isOtherConvertible(PyObject* pyIn) + static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (Shiboken::String::check(pyIn)) return otherToCpp; @@ -537,25 +537,25 @@ struct Primitive<std::string> : TwoPrimitive<std::string> template <> struct Primitive<std::nullptr_t> : TwoPrimitive<std::nullptr_t> { - static PyObject* toPython(const void* cppIn) + static PyObject *toPython(const void *cppIn) { return Py_None; } static void toCpp(PyObject *, void *cppOut) { - *reinterpret_cast<std::nullptr_t*>(cppOut) = nullptr; + *reinterpret_cast<std::nullptr_t *>(cppOut) = nullptr; } - static PythonToCppFunc isConvertible(PyObject* pyIn) + static PythonToCppFunc isConvertible(PyObject *pyIn) { if (pyIn == Py_None) return toCpp; return nullptr; } - static void otherToCpp(PyObject* pyIn, void* cppOut) + static void otherToCpp(PyObject *pyIn, void *cppOut) { - *reinterpret_cast<std::nullptr_t*>(cppOut) = nullptr; + *reinterpret_cast<std::nullptr_t *>(cppOut) = nullptr; } - static PythonToCppFunc isOtherConvertible(PyObject* pyIn) + static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (pyIn == nullptr) return otherToCpp; diff --git a/sources/shiboken2/libshiboken/sbkdbg.h b/sources/shiboken2/libshiboken/sbkdbg.h index fdaf2a27a..02ea773ac 100644 --- a/sources/shiboken2/libshiboken/sbkdbg.h +++ b/sources/shiboken2/libshiboken/sbkdbg.h @@ -63,20 +63,20 @@ class BaseLogger { public: - BaseLogger(const BaseLogger&) = delete; - BaseLogger(BaseLogger&&) = delete; - BaseLogger& operator=(const BaseLogger&) = delete; - BaseLogger& operator=(BaseLogger&&) = delete; + BaseLogger(const BaseLogger &) = delete; + BaseLogger(BaseLogger &&) = delete; + BaseLogger &operator=(const BaseLogger &) = delete; + BaseLogger &operator=(BaseLogger &&) = delete; - BaseLogger(std::ostream& output, const char* function, const char* context) + BaseLogger(std::ostream &output, const char *function, const char *context) : m_stream(output), m_function(function), m_context(context) {} ~BaseLogger() { m_stream << std::endl; } - std::ostream& operator()() { return m_stream; }; + std::ostream &operator()() { return m_stream; }; template <typename T> - std::ostream& operator<<(const T& t) + std::ostream &operator<<(const T &t) { m_stream << '['; if (m_context[0]) @@ -84,24 +84,24 @@ public: return m_stream << COLOR_WHITE << m_function << COLOR_END << "] " << t; } private: - std::ostream& m_stream; - const char* m_function; - const char* m_context; + std::ostream &m_stream; + const char *m_function; + const char *m_context; }; -inline std::ostream& operator<<(std::ostream& out, PyObject* obj) +inline std::ostream &operator<<(std::ostream &out, PyObject *obj) { - PyObject* repr = Shiboken::Object::isValid(obj, false) ? PyObject_Repr(obj) : 0; + PyObject *repr = Shiboken::Object::isValid(obj, false) ? PyObject_Repr(obj) : 0; if (repr) { #ifdef IS_PY3K - PyObject* str = PyUnicode_AsUTF8String(repr); + PyObject *str = PyUnicode_AsUTF8String(repr); Py_DECREF(repr); repr = str; #endif out << PyBytes_AS_STRING(repr); Py_DECREF(repr); } else { - out << reinterpret_cast<void*>(obj); + out << reinterpret_cast<void *>(obj); } return out; } @@ -109,7 +109,7 @@ inline std::ostream& operator<<(std::ostream& out, PyObject* obj) class _SbkDbg : public BaseLogger { public: - _SbkDbg(const char* function, const char* context = "") : BaseLogger(std::cout, function, context) {} + _SbkDbg(const char *function, const char *context = "") : BaseLogger(std::cout, function, context) {} }; #ifdef __GNUG__ @@ -122,7 +122,7 @@ public: struct SbkDbg { template <typename T> - SbkDbg& operator<<(const T&) { return *this; } + SbkDbg &operator<<(const T &) { return *this; } }; #endif diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index 26b40c3cb..75054ab71 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -49,18 +49,18 @@ #include <cstring> #include <vector> -#define SBK_ENUM(ENUM) reinterpret_cast<SbkEnumObject*>(ENUM) +#define SBK_ENUM(ENUM) reinterpret_cast<SbkEnumObject *>(ENUM) #define SBK_TYPE_CHECK(o) (strcmp(Py_TYPE(Py_TYPE(o))->tp_name, "Shiboken.EnumType") == 0) -typedef PyObject* (*enum_func)(PyObject*, PyObject*); +typedef PyObject *(*enum_func)(PyObject *, PyObject *); extern "C" { struct SbkEnumTypePrivate { - SbkConverter** converterPtr; - SbkConverter* converter; - const char* cppName; + SbkConverter **converterPtr; + SbkConverter *converter; + const char *cppName; }; struct SbkEnumType @@ -72,10 +72,10 @@ struct SbkEnumObject { PyObject_HEAD long ob_value; - PyObject* ob_name; + PyObject *ob_name; }; -static PyObject* SbkEnumObject_repr(PyObject* self) +static PyObject *SbkEnumObject_repr(PyObject *self) { const SbkEnumObject *enumObj = SBK_ENUM(self); if (enumObj->ob_name) @@ -84,7 +84,7 @@ static PyObject* SbkEnumObject_repr(PyObject* self) return Shiboken::String::fromFormat("%s(%ld)", (Py_TYPE(self))->tp_name, enumObj->ob_value); } -static PyObject* SbkEnumObject_name(PyObject* self, void*) +static PyObject *SbkEnumObject_name(PyObject *self, void *) { SbkEnumObject *enum_self = SBK_ENUM(self); @@ -95,27 +95,27 @@ static PyObject* SbkEnumObject_name(PyObject* self, void*) return enum_self->ob_name; } -static PyObject* SbkEnum_tp_new(PyTypeObject *type, PyObject *args, PyObject *) +static PyObject *SbkEnum_tp_new(PyTypeObject *type, PyObject *args, PyObject *) { long itemValue = 0; if (!PyArg_ParseTuple(args, "|l:__new__", &itemValue)) return 0; - SbkEnumObject* self = PyObject_New(SbkEnumObject, type); + SbkEnumObject *self = PyObject_New(SbkEnumObject, type); if (!self) return 0; self->ob_value = itemValue; - PyObject* item = Shiboken::Enum::getEnumItemFromValue(type, itemValue); + PyObject *item = Shiboken::Enum::getEnumItemFromValue(type, itemValue); if (item) { self->ob_name = SbkEnumObject_name(item, 0); Py_XDECREF(item); } else { self->ob_name = 0; } - return reinterpret_cast<PyObject*>(self); + return reinterpret_cast<PyObject *>(self); } -static PyObject* enum_op(enum_func f, PyObject *a, PyObject *b) { +static PyObject *enum_op(enum_func f, PyObject *a, PyObject *b) { PyObject *valA = a; PyObject *valB = b; PyObject *result = nullptr; @@ -160,54 +160,54 @@ static PyObject* enum_op(enum_func f, PyObject *a, PyObject *b) { * Thus calling PyInt_FromLong() will result in calling PyLong_FromLong in * Py3k. */ -static PyObject* enum_int(PyObject* v) +static PyObject *enum_int(PyObject *v) { return PyInt_FromLong(SBK_ENUM(v)->ob_value); } -static PyObject* enum_and(PyObject* self, PyObject* b) +static PyObject *enum_and(PyObject *self, PyObject *b) { return enum_op(PyNumber_And, self, b); } -static PyObject* enum_or(PyObject* self, PyObject* b) +static PyObject *enum_or(PyObject *self, PyObject *b) { return enum_op(PyNumber_Or, self, b); } -static PyObject* enum_xor(PyObject* self, PyObject* b) +static PyObject *enum_xor(PyObject *self, PyObject *b) { return enum_op(PyNumber_Xor, self, b); } -static int enum_bool(PyObject* v) +static int enum_bool(PyObject *v) { return (SBK_ENUM(v)->ob_value > 0); } -static PyObject* enum_add(PyObject* self, PyObject* v) +static PyObject *enum_add(PyObject *self, PyObject *v) { return enum_op(PyNumber_Add, self, v); } -static PyObject* enum_subtract(PyObject* self, PyObject* v) +static PyObject *enum_subtract(PyObject *self, PyObject *v) { return enum_op(PyNumber_Subtract, self, v); } -static PyObject* enum_multiply(PyObject* self, PyObject* v) +static PyObject *enum_multiply(PyObject *self, PyObject *v) { return enum_op(PyNumber_Multiply, self, v); } #ifndef IS_PY3K -static PyObject* enum_divide(PyObject* self, PyObject* v) +static PyObject *enum_divide(PyObject *self, PyObject *v) { return enum_op(PyNumber_Divide, self, v); } #endif -static PyObject* enum_richcompare(PyObject* self, PyObject* other, int op) +static PyObject *enum_richcompare(PyObject *self, PyObject *other, int op) { PyObject *valA = self; PyObject *valB = other; @@ -246,21 +246,21 @@ static PyObject* enum_richcompare(PyObject* self, PyObject* other, int op) return result; } -static Py_hash_t enum_hash(PyObject* pyObj) +static Py_hash_t enum_hash(PyObject *pyObj) { - Py_hash_t val = reinterpret_cast<SbkEnumObject*>(pyObj)->ob_value; + Py_hash_t val = reinterpret_cast<SbkEnumObject *>(pyObj)->ob_value; if (val == -1) val = -2; return val; } static PyGetSetDef SbkEnumGetSetList[] = { - {const_cast<char*>("name"), &SbkEnumObject_name, 0, 0, 0}, + {const_cast<char *>("name"), &SbkEnumObject_name, nullptr, nullptr, nullptr}, {0, 0, 0, 0, 0} // Sentinel }; -static void SbkEnumTypeDealloc(PyObject* pyObj); -static PyObject* SbkEnumTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds); +static void SbkEnumTypeDealloc(PyObject *pyObj); +static PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds); static PyType_Slot SbkEnumType_Type_slots[] = { {Py_tp_dealloc, (void *)SbkEnumTypeDealloc}, @@ -308,9 +308,9 @@ PyTypeObject *SbkEnumType_TypeF(void) return type; } -void SbkEnumTypeDealloc(PyObject* pyObj) +void SbkEnumTypeDealloc(PyObject *pyObj) { - SbkEnumType* sbkType = reinterpret_cast<SbkEnumType*>(pyObj); + auto sbkType = reinterpret_cast<SbkEnumType *>(pyObj); PyObject_GC_UnTrack(pyObj); #ifndef Py_LIMITED_API @@ -324,13 +324,13 @@ void SbkEnumTypeDealloc(PyObject* pyObj) #endif } -PyObject* SbkEnumTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds) +PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds) { newfunc type_new = reinterpret_cast<newfunc>(PyType_GetSlot(&PyType_Type, Py_tp_new)); - SbkEnumType *newType = reinterpret_cast<SbkEnumType*>(type_new(metatype, args, kwds)); + auto newType = reinterpret_cast<SbkEnumType *>(type_new(metatype, args, kwds)); if (!newType) return 0; - return reinterpret_cast<PyObject*>(newType); + return reinterpret_cast<PyObject *>(newType); } } // extern "C" @@ -340,15 +340,15 @@ namespace Shiboken { class DeclaredEnumTypes { public: - DeclaredEnumTypes(const DeclaredEnumTypes&) = delete; - DeclaredEnumTypes(DeclaredEnumTypes&&) = delete; - DeclaredEnumTypes& operator=(const DeclaredEnumTypes&) = delete; - DeclaredEnumTypes& operator=(DeclaredEnumTypes&&) = delete; + DeclaredEnumTypes(const DeclaredEnumTypes &) = delete; + DeclaredEnumTypes(DeclaredEnumTypes &&) = delete; + DeclaredEnumTypes &operator=(const DeclaredEnumTypes &) = delete; + DeclaredEnumTypes &operator=(DeclaredEnumTypes &&) = delete; DeclaredEnumTypes(); ~DeclaredEnumTypes(); - static DeclaredEnumTypes& instance(); - void addEnumType(PyTypeObject* type); + static DeclaredEnumTypes &instance(); + void addEnumType(PyTypeObject *type); private: std::vector<PyTypeObject *> m_enumTypes; @@ -356,16 +356,16 @@ private: namespace Enum { -bool check(PyObject* pyObj) +bool check(PyObject *pyObj) { return Py_TYPE(Py_TYPE(pyObj)) == SbkEnumType_TypeF(); } -PyObject* getEnumItemFromValue(PyTypeObject* enumType, long itemValue) +PyObject *getEnumItemFromValue(PyTypeObject *enumType, long itemValue) { PyObject *key, *value; Py_ssize_t pos = 0; - PyObject *values = PyDict_GetItemString(enumType->tp_dict, const_cast<char*>("values")); + PyObject *values = PyDict_GetItemString(enumType->tp_dict, const_cast<char *>("values")); while (PyDict_Next(values, &pos, &key, &value)) { SbkEnumObject *obj = reinterpret_cast<SbkEnumObject *>(value); @@ -377,19 +377,19 @@ PyObject* getEnumItemFromValue(PyTypeObject* enumType, long itemValue) return 0; } -static PyTypeObject* createEnum(const char* fullName, const char* cppName, - const char* /* shortName */, - PyTypeObject* flagsType) +static PyTypeObject *createEnum(const char *fullName, const char *cppName, + const char */* shortName */, + PyTypeObject *flagsType) { - PyTypeObject* enumType = newTypeWithName(fullName, cppName, flagsType); + PyTypeObject *enumType = newTypeWithName(fullName, cppName, flagsType); if (PyType_Ready(enumType) < 0) return 0; return enumType; } -PyTypeObject* createGlobalEnum(PyObject* module, const char* name, const char* fullName, const char* cppName, PyTypeObject* flagsType) +PyTypeObject *createGlobalEnum(PyObject *module, const char *name, const char *fullName, const char *cppName, PyTypeObject *flagsType) { - PyTypeObject* enumType = createEnum(fullName, cppName, name, flagsType); + PyTypeObject *enumType = createEnum(fullName, cppName, name, flagsType); if (enumType && PyModule_AddObject(module, name, reinterpret_cast<PyObject *>(enumType)) < 0) return 0; if (flagsType && PyModule_AddObject(module, PepType_GetNameStr(flagsType), @@ -398,9 +398,9 @@ PyTypeObject* createGlobalEnum(PyObject* module, const char* name, const char* f return enumType; } -PyTypeObject* createScopedEnum(SbkObjectType* scope, const char* name, const char* fullName, const char* cppName, PyTypeObject* flagsType) +PyTypeObject *createScopedEnum(SbkObjectType *scope, const char *name, const char *fullName, const char *cppName, PyTypeObject *flagsType) { - PyTypeObject* enumType = createEnum(fullName, cppName, name, flagsType); + PyTypeObject *enumType = createEnum(fullName, cppName, name, flagsType); if (enumType && PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(scope)->tp_dict, name, reinterpret_cast<PyObject *>(enumType)) < 0) return nullptr; @@ -411,18 +411,18 @@ PyTypeObject* createScopedEnum(SbkObjectType* scope, const char* name, const cha return enumType; } -static PyObject* createEnumItem(PyTypeObject* enumType, const char* itemName, long itemValue) +static PyObject *createEnumItem(PyTypeObject *enumType, const char *itemName, long itemValue) { - PyObject* enumItem = newItem(enumType, itemValue, itemName); + PyObject *enumItem = newItem(enumType, itemValue, itemName); if (PyDict_SetItemString(enumType->tp_dict, itemName, enumItem) < 0) return 0; Py_DECREF(enumItem); return enumItem; } -bool createGlobalEnumItem(PyTypeObject* enumType, PyObject* module, const char* itemName, long itemValue) +bool createGlobalEnumItem(PyTypeObject *enumType, PyObject *module, const char *itemName, long itemValue) { - PyObject* enumItem = createEnumItem(enumType, itemName, itemValue); + PyObject *enumItem = createEnumItem(enumType, itemName, itemValue); if (enumItem) { if (PyModule_AddObject(module, itemName, enumItem) < 0) return false; @@ -449,7 +449,7 @@ bool createScopedEnumItem(PyTypeObject *enumType, PyTypeObject *scope, return false; } -bool createScopedEnumItem(PyTypeObject* enumType, SbkObjectType* scope, const char* itemName, long itemValue) +bool createScopedEnumItem(PyTypeObject *enumType, SbkObjectType *scope, const char *itemName, long itemValue) { return createScopedEnumItem(enumType, reinterpret_cast<PyTypeObject *>(scope), itemName, itemValue); } @@ -458,12 +458,12 @@ PyObject * newItem(PyTypeObject *enumType, long itemValue, const char *itemName) { bool newValue = true; - SbkEnumObject* enumObj; + SbkEnumObject *enumObj; if (!itemName) { - enumObj = reinterpret_cast<SbkEnumObject*>( + enumObj = reinterpret_cast<SbkEnumObject *>( getEnumItemFromValue(enumType, itemValue)); if (enumObj) - return reinterpret_cast<PyObject*>(enumObj); + return reinterpret_cast<PyObject *>(enumObj); newValue = false; } @@ -476,16 +476,16 @@ newItem(PyTypeObject *enumType, long itemValue, const char *itemName) enumObj->ob_value = itemValue; if (newValue) { - PyObject* values = PyDict_GetItemString(enumType->tp_dict, const_cast<char*>("values")); + PyObject *values = PyDict_GetItemString(enumType->tp_dict, const_cast<char *>("values")); if (!values) { values = PyDict_New(); - PyDict_SetItemString(enumType->tp_dict, const_cast<char*>("values"), values); + PyDict_SetItemString(enumType->tp_dict, const_cast<char *>("values"), values); Py_DECREF(values); // ^ values still alive, because setitemstring incref it } - PyDict_SetItemString(values, itemName, reinterpret_cast<PyObject*>(enumObj)); + PyDict_SetItemString(values, itemName, reinterpret_cast<PyObject *>(enumObj)); } - return reinterpret_cast<PyObject*>(enumObj); + return reinterpret_cast<PyObject *>(enumObj); } static PyType_Slot SbkNewType_slots[] = { @@ -581,8 +581,8 @@ copyNumberMethods(PyTypeObject *flagsType, } PyTypeObject * -newTypeWithName(const char* name, - const char* cppName, +newTypeWithName(const char *name, + const char *cppName, PyTypeObject *numbers_fromFlag) { // Careful: PyType_FromSpec does not allocate the string. @@ -606,40 +606,40 @@ newTypeWithName(const char* name, Py_TYPE(type) = SbkEnumType_TypeF(); Py_INCREF(Py_TYPE(type)); - SbkEnumType* enumType = reinterpret_cast<SbkEnumType*>(type); + SbkEnumType *enumType = reinterpret_cast<SbkEnumType *>(type); PepType_SETP(enumType)->cppName = cppName; PepType_SETP(enumType)->converterPtr = &PepType_SETP(enumType)->converter; DeclaredEnumTypes::instance().addEnumType(type); return type; } -const char* getCppName(PyTypeObject* enumType) +const char *getCppName(PyTypeObject *enumType) { assert(Py_TYPE(enumType) == SbkEnumType_TypeF()); - return PepType_SETP(reinterpret_cast<SbkEnumType*>(enumType))->cppName; + return PepType_SETP(reinterpret_cast<SbkEnumType *>(enumType))->cppName; } -long int getValue(PyObject* enumItem) +long int getValue(PyObject *enumItem) { assert(Shiboken::Enum::check(enumItem)); - return reinterpret_cast<SbkEnumObject*>(enumItem)->ob_value; + return reinterpret_cast<SbkEnumObject *>(enumItem)->ob_value; } -void setTypeConverter(PyTypeObject* enumType, SbkConverter* converter) +void setTypeConverter(PyTypeObject *enumType, SbkConverter *converter) { - //reinterpret_cast<SbkEnumType*>(enumType)->converter = converter; + //reinterpret_cast<SbkEnumType *>(enumType)->converter = converter; *PepType_SGTP(enumType)->converter = converter; } -SbkConverter* getTypeConverter(PyTypeObject* enumType) +SbkConverter *getTypeConverter(PyTypeObject *enumType) { - //return reinterpret_cast<SbkEnumType*>(enumType)->converter; + //return reinterpret_cast<SbkEnumType *>(enumType)->converter; return *PepType_SGTP(enumType)->converter; } } // namespace Enum -DeclaredEnumTypes& DeclaredEnumTypes::instance() +DeclaredEnumTypes &DeclaredEnumTypes::instance() { static DeclaredEnumTypes me; return me; @@ -662,7 +662,7 @@ DeclaredEnumTypes::~DeclaredEnumTypes() m_enumTypes.clear(); } -void DeclaredEnumTypes::addEnumType(PyTypeObject* type) +void DeclaredEnumTypes::addEnumType(PyTypeObject *type) { m_enumTypes.push_back(type); } diff --git a/sources/shiboken2/libshiboken/sbkenum.h b/sources/shiboken2/libshiboken/sbkenum.h index c1ec7c4c1..199027836 100644 --- a/sources/shiboken2/libshiboken/sbkenum.h +++ b/sources/shiboken2/libshiboken/sbkenum.h @@ -57,14 +57,14 @@ struct SbkEnumTypePrivate; namespace Shiboken { -inline bool isShibokenEnum(PyObject* pyObj) +inline bool isShibokenEnum(PyObject *pyObj) { return Py_TYPE(Py_TYPE(pyObj)) == SbkEnumType_TypeF(); } namespace Enum { - LIBSHIBOKEN_API bool check(PyObject* obj); + LIBSHIBOKEN_API bool check(PyObject *obj); /** * Creates a new enum type (and its flags type, if any is given) * and registers it to Python and adds it to \p module. @@ -75,17 +75,17 @@ namespace Enum * \param flagsType Optional Python type for the flags associated with the enum. * \return The new enum type or NULL if it fails. */ - LIBSHIBOKEN_API PyTypeObject* createGlobalEnum(PyObject* module, - const char* name, - const char* fullName, - const char* cppName, - PyTypeObject* flagsType = 0); + LIBSHIBOKEN_API PyTypeObject *createGlobalEnum(PyObject *module, + const char *name, + const char *fullName, + const char *cppName, + PyTypeObject *flagsType = nullptr); /// This function does the same as createGlobalEnum, but adds the enum to a Shiboken type or namespace. - LIBSHIBOKEN_API PyTypeObject* createScopedEnum(SbkObjectType* scope, - const char* name, - const char* fullName, - const char* cppName, - PyTypeObject* flagsType = 0); + LIBSHIBOKEN_API PyTypeObject *createScopedEnum(SbkObjectType *scope, + const char *name, + const char *fullName, + const char *cppName, + PyTypeObject *flagsType = nullptr); /** * Creates a new enum item for a given enum type and adds it to \p module. @@ -95,25 +95,25 @@ namespace Enum * \param itemValue Numerical value of the enum item. * \return true if everything goes fine, false if it fails. */ - LIBSHIBOKEN_API bool createGlobalEnumItem(PyTypeObject* enumType, PyObject* module, const char* itemName, long itemValue); + LIBSHIBOKEN_API bool createGlobalEnumItem(PyTypeObject *enumType, PyObject *module, const char *itemName, long itemValue); /// This function does the same as createGlobalEnumItem, but adds the enum to a Shiboken type or namespace. LIBSHIBOKEN_API bool createScopedEnumItem(PyTypeObject *enumType, PyTypeObject *scope, const char *itemName, long itemValue); - LIBSHIBOKEN_API bool createScopedEnumItem(PyTypeObject* enumType, SbkObjectType* scope, const char* itemName, long itemValue); + LIBSHIBOKEN_API bool createScopedEnumItem(PyTypeObject *enumType, SbkObjectType *scope, const char *itemName, long itemValue); - LIBSHIBOKEN_API PyObject* newItem(PyTypeObject* enumType, long itemValue, const char* itemName = 0); + LIBSHIBOKEN_API PyObject *newItem(PyTypeObject *enumType, long itemValue, const char *itemName = 0); - LIBSHIBOKEN_API PyTypeObject* newTypeWithName(const char* name, const char* cppName, + LIBSHIBOKEN_API PyTypeObject *newTypeWithName(const char *name, const char *cppName, PyTypeObject *numbers_fromFlag=nullptr); - LIBSHIBOKEN_API const char* getCppName(PyTypeObject* type); + LIBSHIBOKEN_API const char *getCppName(PyTypeObject *type); - LIBSHIBOKEN_API long getValue(PyObject* enumItem); - LIBSHIBOKEN_API PyObject* getEnumItemFromValue(PyTypeObject* enumType, long itemValue); + LIBSHIBOKEN_API long getValue(PyObject *enumItem); + LIBSHIBOKEN_API PyObject *getEnumItemFromValue(PyTypeObject *enumType, long itemValue); /// Sets the enum's type converter. - LIBSHIBOKEN_API void setTypeConverter(PyTypeObject* enumType, SbkConverter* converter); + LIBSHIBOKEN_API void setTypeConverter(PyTypeObject *enumType, SbkConverter *converter); /// Returns the converter assigned to the enum \p type. - LIBSHIBOKEN_API SbkConverter* getTypeConverter(PyTypeObject* enumType); + LIBSHIBOKEN_API SbkConverter *getTypeConverter(PyTypeObject *enumType); } } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/sbkmodule.cpp b/sources/shiboken2/libshiboken/sbkmodule.cpp index a29ec38c7..7bfbf51a8 100644 --- a/sources/shiboken2/libshiboken/sbkmodule.cpp +++ b/sources/shiboken2/libshiboken/sbkmodule.cpp @@ -57,10 +57,10 @@ namespace Shiboken namespace Module { -PyObject* import(const char* moduleName) +PyObject *import(const char *moduleName) { - PyObject* sysModules = PyImport_GetModuleDict(); - PyObject* module = PyDict_GetItemString(sysModules, moduleName); + PyObject *sysModules = PyImport_GetModuleDict(); + PyObject *module = PyDict_GetItemString(sysModules, moduleName); if (module) Py_INCREF(module); else @@ -72,37 +72,37 @@ PyObject* import(const char* moduleName) return module; } -PyObject* create(const char* moduleName, void* moduleData) +PyObject *create(const char *moduleName, void *moduleData) { Shiboken::init(); #ifndef IS_PY3K return Py_InitModule(moduleName, reinterpret_cast<PyMethodDef *>(moduleData)); #else - return PyModule_Create(reinterpret_cast<PyModuleDef*>(moduleData)); + return PyModule_Create(reinterpret_cast<PyModuleDef *>(moduleData)); #endif } -void registerTypes(PyObject* module, PyTypeObject** types) +void registerTypes(PyObject *module, PyTypeObject **types) { ModuleTypesMap::iterator iter = moduleTypes.find(module); if (iter == moduleTypes.end()) moduleTypes.insert(std::make_pair(module, types)); } -PyTypeObject** getTypes(PyObject* module) +PyTypeObject **getTypes(PyObject *module) { ModuleTypesMap::iterator iter = moduleTypes.find(module); return (iter == moduleTypes.end()) ? 0 : iter->second; } -void registerTypeConverters(PyObject* module, SbkConverter** converters) +void registerTypeConverters(PyObject *module, SbkConverter **converters) { ModuleConvertersMap::iterator iter = moduleConverters.find(module); if (iter == moduleConverters.end()) moduleConverters.insert(std::make_pair(module, converters)); } -SbkConverter** getTypeConverters(PyObject* module) +SbkConverter **getTypeConverters(PyObject *module) { ModuleConvertersMap::iterator iter = moduleConverters.find(module); return (iter == moduleConverters.end()) ? 0 : iter->second; diff --git a/sources/shiboken2/libshiboken/sbkmodule.h b/sources/shiboken2/libshiboken/sbkmodule.h index 659c41c4d..75eff5a79 100644 --- a/sources/shiboken2/libshiboken/sbkmodule.h +++ b/sources/shiboken2/libshiboken/sbkmodule.h @@ -46,7 +46,7 @@ #if PY_MAJOR_VERSION >= 3 #define SBK_MODULE_INIT_ERROR 0 #define SBK_MODULE_INIT_FUNCTION_BEGIN(ModuleName) \ - extern "C" SBK_EXPORT_MODULE PyObject* PyInit_##ModuleName() { + extern "C" SBK_EXPORT_MODULE PyObject *PyInit_##ModuleName() { #define SBK_MODULE_INIT_FUNCTION_END \ return module; } @@ -72,43 +72,43 @@ namespace Module { * If the module is already imported, it increments its reference count before returning it. * \returns the module specified in \p moduleName or NULL if an error occurs. */ -LIBSHIBOKEN_API PyObject* import(const char* moduleName); +LIBSHIBOKEN_API PyObject *import(const char *moduleName); /** * Creates a new Python module named \p moduleName using the information passed in \p moduleData. - * In fact, \p moduleData expects a "PyMethodDef*" object, but that's for Python 2. A void* + * In fact, \p moduleData expects a "PyMethodDef *" object, but that's for Python 2. A "void*" * was preferred to make this work with future Python 3 support. * \returns a newly created module. */ -LIBSHIBOKEN_API PyObject* create(const char* moduleName, void* moduleData); +LIBSHIBOKEN_API PyObject *create(const char *moduleName, void *moduleData); /** * Registers the list of types created by \p module. * \param module Module where the types were created. - * \param types Array of PyTypeObject* objects representing the types created on \p module. + * \param types Array of PyTypeObject *objects representing the types created on \p module. */ -LIBSHIBOKEN_API void registerTypes(PyObject* module, PyTypeObject** types); +LIBSHIBOKEN_API void registerTypes(PyObject *module, PyTypeObject **types); /** * Retrieves the array of types. * \param module Module where the types were created. - * \returns A pointer to the PyTypeObject* array of types. + * \returns A pointer to the PyTypeObject *array of types. */ -LIBSHIBOKEN_API PyTypeObject** getTypes(PyObject* module); +LIBSHIBOKEN_API PyTypeObject **getTypes(PyObject *module); /** * Registers the list of converters created by \p module for non-wrapper types. * \param module Module where the converters were created. - * \param converters Array of SbkConverter* objects representing the converters created on \p module. + * \param converters Array of SbkConverter *objects representing the converters created on \p module. */ -LIBSHIBOKEN_API void registerTypeConverters(PyObject* module, SbkConverter** converters); +LIBSHIBOKEN_API void registerTypeConverters(PyObject *module, SbkConverter **converters); /** * Retrieves the array of converters. * \param module Module where the converters were created. - * \returns A pointer to the SbkConverter* array of converters. + * \returns A pointer to the SbkConverter *array of converters. */ -LIBSHIBOKEN_API SbkConverter** getTypeConverters(PyObject* module); +LIBSHIBOKEN_API SbkConverter **getTypeConverters(PyObject *module); } } // namespace Shiboken::Module diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp index a3ffcdabb..d3c337524 100644 --- a/sources/shiboken2/libshiboken/sbkstring.cpp +++ b/sources/shiboken2/libshiboken/sbkstring.cpp @@ -46,7 +46,7 @@ namespace Shiboken namespace String { -bool checkType(PyTypeObject* type) +bool checkType(PyTypeObject *type) { return type == &PyUnicode_Type #if PY_MAJOR_VERSION < 3 @@ -55,7 +55,7 @@ bool checkType(PyTypeObject* type) ; } -bool check(PyObject* obj) +bool check(PyObject *obj) { return obj == Py_None || #if PY_MAJOR_VERSION < 3 @@ -64,17 +64,17 @@ bool check(PyObject* obj) PyUnicode_Check(obj); } -bool checkChar(PyObject* pyobj) +bool checkChar(PyObject *pyobj) { return check(pyobj) && (len(pyobj) == 1); } -bool isConvertible(PyObject* obj) +bool isConvertible(PyObject *obj) { return check(obj); } -PyObject* fromCString(const char* value) +PyObject *fromCString(const char *value) { #ifdef IS_PY3K return PyUnicode_FromString(value); @@ -83,7 +83,7 @@ PyObject* fromCString(const char* value) #endif } -PyObject* fromCString(const char* value, int len) +PyObject *fromCString(const char *value, int len) { #ifdef IS_PY3K return PyUnicode_FromStringAndSize(value, len); @@ -92,13 +92,13 @@ PyObject* fromCString(const char* value, int len) #endif } -const char* toCString(PyObject* str, Py_ssize_t* len) +const char *toCString(PyObject *str, Py_ssize_t *len) { if (str == Py_None) return NULL; if (PyUnicode_Check(str)) { if (len) { - // We need to encode the unicode string into utf8 to know the size of returned char*. + // We need to encode the unicode string into utf8 to know the size of returned char *. Shiboken::AutoDecRef uniStr(PyUnicode_AsUTF8String(str)); *len = PyBytes_GET_SIZE(uniStr.object()); } @@ -122,10 +122,10 @@ const char* toCString(PyObject* str, Py_ssize_t* len) return 0; } -bool concat(PyObject** val1, PyObject* val2) +bool concat(PyObject **val1, PyObject *val2) { if (PyUnicode_Check(*val1) && PyUnicode_Check(val2)) { - PyObject* result = PyUnicode_Concat(*val1, val2); + PyObject *result = PyUnicode_Concat(*val1, val2); Py_DECREF(*val1); *val1 = result; return true; @@ -145,11 +145,11 @@ bool concat(PyObject** val1, PyObject* val2) return false; } -PyObject* fromFormat(const char* format, ...) +PyObject *fromFormat(const char *format, ...) { va_list argp; va_start(argp, format); - PyObject* result = 0; + PyObject *result = nullptr; #ifdef IS_PY3K result = PyUnicode_FromFormatV(format, argp); #else @@ -159,7 +159,7 @@ PyObject* fromFormat(const char* format, ...) return result; } -PyObject* fromStringAndSize(const char* str, Py_ssize_t size) +PyObject *fromStringAndSize(const char *str, Py_ssize_t size) { #ifdef IS_PY3K return PyUnicode_FromStringAndSize(str, size); @@ -168,15 +168,15 @@ PyObject* fromStringAndSize(const char* str, Py_ssize_t size) #endif } -int compare(PyObject* val1, const char* val2) +int compare(PyObject *val1, const char *val2) { if (PyUnicode_Check(val1)) #ifdef IS_PY3K return PyUnicode_CompareWithASCIIString(val1, val2); #else { - PyObject* uVal2 = PyUnicode_FromString(val2); - bool result = PyUnicode_Compare(val1, uVal2); + PyObject *uVal2 = PyUnicode_FromString(val2); + bool result = PyUnicode_Compare(val1, uVal2); Py_XDECREF(uVal2); return result; } @@ -187,7 +187,7 @@ int compare(PyObject* val1, const char* val2) } -Py_ssize_t len(PyObject* str) +Py_ssize_t len(PyObject *str) { if (str == Py_None) return 0; diff --git a/sources/shiboken2/libshiboken/sbkstring.h b/sources/shiboken2/libshiboken/sbkstring.h index a6b5fbeed..ec674ee7b 100644 --- a/sources/shiboken2/libshiboken/sbkstring.h +++ b/sources/shiboken2/libshiboken/sbkstring.h @@ -53,18 +53,18 @@ namespace Shiboken { namespace String { - LIBSHIBOKEN_API bool check(PyObject* obj); - LIBSHIBOKEN_API bool checkType(PyTypeObject* obj); - LIBSHIBOKEN_API bool checkChar(PyObject* obj); - LIBSHIBOKEN_API bool isConvertible(PyObject* obj); - LIBSHIBOKEN_API PyObject* fromCString(const char* value); - LIBSHIBOKEN_API PyObject* fromCString(const char* value, int len); - LIBSHIBOKEN_API const char* toCString(PyObject* str, Py_ssize_t* len = 0); - LIBSHIBOKEN_API bool concat(PyObject** val1, PyObject* val2); - LIBSHIBOKEN_API PyObject* fromFormat(const char* format, ...); - LIBSHIBOKEN_API PyObject* fromStringAndSize(const char* str, Py_ssize_t size); - LIBSHIBOKEN_API int compare(PyObject* val1, const char* val2); - LIBSHIBOKEN_API Py_ssize_t len(PyObject* str); + LIBSHIBOKEN_API bool check(PyObject *obj); + LIBSHIBOKEN_API bool checkType(PyTypeObject *obj); + LIBSHIBOKEN_API bool checkChar(PyObject *obj); + LIBSHIBOKEN_API bool isConvertible(PyObject *obj); + LIBSHIBOKEN_API PyObject *fromCString(const char *value); + LIBSHIBOKEN_API PyObject *fromCString(const char *value, int len); + LIBSHIBOKEN_API const char *toCString(PyObject *str, Py_ssize_t *len = 0); + LIBSHIBOKEN_API bool concat(PyObject **val1, PyObject *val2); + LIBSHIBOKEN_API PyObject *fromFormat(const char *format, ...); + LIBSHIBOKEN_API PyObject *fromStringAndSize(const char *str, Py_ssize_t size); + LIBSHIBOKEN_API int compare(PyObject *val1, const char *val2); + LIBSHIBOKEN_API Py_ssize_t len(PyObject *str); } // namespace String } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/shibokenbuffer.cpp b/sources/shiboken2/libshiboken/shibokenbuffer.cpp index a691a31ee..330470183 100644 --- a/sources/shiboken2/libshiboken/shibokenbuffer.cpp +++ b/sources/shiboken2/libshiboken/shibokenbuffer.cpp @@ -41,14 +41,14 @@ #include <cstdlib> #include <cstring> -bool Shiboken::Buffer::checkType(PyObject* pyObj) +bool Shiboken::Buffer::checkType(PyObject *pyObj) { return PyObject_CheckReadBuffer(pyObj) != 0; } -void* Shiboken::Buffer::getPointer(PyObject* pyObj, Py_ssize_t* size) +void *Shiboken::Buffer::getPointer(PyObject *pyObj, Py_ssize_t *size) { - const void* buffer = 0; + const void *buffer = nullptr; #ifdef IS_PY3K Py_buffer view; if (PyObject_GetBuffer(pyObj, &view, PyBUF_ND) == 0) { @@ -67,10 +67,10 @@ void* Shiboken::Buffer::getPointer(PyObject* pyObj, Py_ssize_t* size) if (size) *size = bufferSize; #endif - return const_cast<void*>(buffer); + return const_cast<void *>(buffer); } -PyObject* Shiboken::Buffer::newObject(void* memory, Py_ssize_t size, Type type) +PyObject *Shiboken::Buffer::newObject(void *memory, Py_ssize_t size, Type type) { if (size == 0) Py_RETURN_NONE; @@ -93,7 +93,7 @@ PyObject* Shiboken::Buffer::newObject(void* memory, Py_ssize_t size, Type type) #endif } -PyObject* Shiboken::Buffer::newObject(const void* memory, Py_ssize_t size) +PyObject *Shiboken::Buffer::newObject(const void *memory, Py_ssize_t size) { - return newObject(const_cast<void*>(memory), size, ReadOnly); + return newObject(const_cast<void *>(memory), size, ReadOnly); } diff --git a/sources/shiboken2/libshiboken/shibokenbuffer.h b/sources/shiboken2/libshiboken/shibokenbuffer.h index 04a5b6dd0..8c41dad6c 100644 --- a/sources/shiboken2/libshiboken/shibokenbuffer.h +++ b/sources/shiboken2/libshiboken/shibokenbuffer.h @@ -58,18 +58,18 @@ namespace Buffer * Creates a new Python buffer pointing to a contiguous memory block at * \p memory of size \p size. */ - LIBSHIBOKEN_API PyObject* newObject(void* memory, Py_ssize_t size, Type type); + LIBSHIBOKEN_API PyObject *newObject(void *memory, Py_ssize_t size, Type type); /** * Creates a new <b>read only</b> Python buffer pointing to a contiguous memory block at * \p memory of size \p size. */ - LIBSHIBOKEN_API PyObject* newObject(const void* memory, Py_ssize_t size); + LIBSHIBOKEN_API PyObject *newObject(const void *memory, Py_ssize_t size); /** * Check if is ok to use \p pyObj as argument in all function under Shiboken::Buffer namespace. */ - LIBSHIBOKEN_API bool checkType(PyObject* pyObj); + LIBSHIBOKEN_API bool checkType(PyObject *pyObj); /** * Returns a pointer to the memory pointed by the buffer \p pyObj, \p size is filled with the buffer @@ -77,7 +77,7 @@ namespace Buffer * * If the \p pyObj is a non-contiguous buffer a Python error is set. */ - LIBSHIBOKEN_API void* getPointer(PyObject* pyObj, Py_ssize_t* size = 0); + LIBSHIBOKEN_API void *getPointer(PyObject *pyObj, Py_ssize_t *size = 0); } // namespace Buffer } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index 8003f142a..8f9c5a459 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -831,7 +831,7 @@ void handler(int sig) { void *array[30]; size_t size; - // get void*'s for all entries on the stack + // get void *'s for all entries on the stack size = backtrace(array, 30); // print out all the frames to stderr @@ -1089,7 +1089,7 @@ _build_func_to_type(PyObject *obtype) || (check_name && PyObject_RichCompareBool(look, given, Py_EQ) != 1)) { PyErr_Clear(); Shiboken::AutoDecRef cfunc(PyCFunction_NewEx(meth, - reinterpret_cast<PyObject*>(type), nullptr)); + reinterpret_cast<PyObject *>(type), nullptr)); if (cfunc.isNull()) return -1; if (meth->ml_flags & METH_STATIC) diff --git a/sources/shiboken2/libshiboken/threadstatesaver.h b/sources/shiboken2/libshiboken/threadstatesaver.h index ddad9b67f..10b3af12b 100644 --- a/sources/shiboken2/libshiboken/threadstatesaver.h +++ b/sources/shiboken2/libshiboken/threadstatesaver.h @@ -49,17 +49,17 @@ namespace Shiboken class LIBSHIBOKEN_API ThreadStateSaver { public: - ThreadStateSaver(const ThreadStateSaver&) = delete; - ThreadStateSaver(ThreadStateSaver&&) = delete; - ThreadStateSaver &operator=(const ThreadStateSaver&) = delete; - ThreadStateSaver &operator=(ThreadStateSaver&&) = delete; + ThreadStateSaver(const ThreadStateSaver &) = delete; + ThreadStateSaver(ThreadStateSaver &&) = delete; + ThreadStateSaver &operator=(const ThreadStateSaver &) = delete; + ThreadStateSaver &operator=(ThreadStateSaver &&) = delete; ThreadStateSaver(); ~ThreadStateSaver(); void save(); void restore(); private: - PyThreadState* m_threadState; + PyThreadState *m_threadState; }; } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/tmp-referencetopython/sbkconverter.cpp b/sources/shiboken2/libshiboken/tmp-referencetopython/sbkconverter.cpp index 8e351cedd..ab205e215 100644 --- a/sources/shiboken2/libshiboken/tmp-referencetopython/sbkconverter.cpp +++ b/sources/shiboken2/libshiboken/tmp-referencetopython/sbkconverter.cpp @@ -46,13 +46,13 @@ namespace Shiboken { namespace Conversions { -static SbkConverter* createConverterObject(PyTypeObject* type, +static SbkConverter *createConverterObject(PyTypeObject *type, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc, CppToPythonFunc pointerToPythonFunc, CppToPythonFunc copyToPythonFunc) { - SbkConverter* converter = new SbkConverter; + SbkConverter *converter = new SbkConverter; converter->pythonType = type; converter->pointerToPython = pointerToPythonFunc; @@ -64,20 +64,20 @@ static SbkConverter* createConverterObject(PyTypeObject* type, return converter; } -SbkConverter* createConverter(SbkObjectType* type, +SbkConverter *createConverter(SbkObjectType *type, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc, CppToPythonFunc pointerToPythonFunc, CppToPythonFunc copyToPythonFunc) { - SbkConverter* converter = createConverterObject((PyTypeObject*)type, + SbkConverter *converter = createConverterObject(reinterpret_cast<PyTypeObject *>(type), toCppPointerConvFunc, toCppPointerCheckFunc, pointerToPythonFunc, copyToPythonFunc); type->d->converter = converter; return converter; } -void deleteConverter(SbkConverter* converter) +void deleteConverter(SbkConverter *converter) { if (converter) { converter->toCppConversions.clear(); @@ -85,44 +85,44 @@ void deleteConverter(SbkConverter* converter) } } -void addPythonToCppValueConversion(SbkConverter* converter, +void addPythonToCppValueConversion(SbkConverter *converter, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc) { converter->toCppConversions.push_back(std::make_pair(isConvertibleToCppFunc, pythonToCppFunc)); } -void addPythonToCppValueConversion(SbkObjectType* type, +void addPythonToCppValueConversion(SbkObjectType *type, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc) { addPythonToCppValueConversion(type->d->converter, pythonToCppFunc, isConvertibleToCppFunc); } -PyObject* pointerToPython(SbkObjectType* type, const void* cppIn) +PyObject *pointerToPython(SbkObjectType *type, const void *cppIn) { if (!cppIn) Py_RETURN_NONE; return type->d->converter->pointerToPython(cppIn); } -static inline PyObject* CopyCppToPython(SbkConverter* converter, const void* cppIn) +static inline PyObject *CopyCppToPython(SbkConverter *converter, const void *cppIn) { assert(cppIn); return converter->copyToPython(cppIn); } -PyObject* copyToPython(SbkObjectType* type, const void* cppIn) +PyObject *copyToPython(SbkObjectType *type, const void *cppIn) { return CopyCppToPython(type->d->converter, cppIn); } -PyObject* toPython(SbkConverter* converter, const void* cppIn) +PyObject *toPython(SbkConverter *converter, const void *cppIn) { return CopyCppToPython(converter, cppIn); } -PyObject* referenceToPython(SbkObjectType* type, const void* cppIn) +PyObject *referenceToPython(SbkObjectType *type, const void *cppIn) { assert(cppIn); - PyObject* pyOut = (PyObject*)BindingManager::instance().retrieveWrapper(cppIn); + PyObject *pyOut = (PyObject *)BindingManager::instance().retrieveWrapper(cppIn); if (pyOut) { Py_INCREF(pyOut); return pyOut; @@ -134,16 +134,16 @@ PyObject* referenceToPython(SbkObjectType* type, const void* cppIn) return type->d->converter->pointerToPython(cppIn); } -PythonToCppFunc isPythonToCppPointerConvertible(SbkObjectType* type, PyObject* pyIn) +PythonToCppFunc isPythonToCppPointerConvertible(SbkObjectType *type, PyObject *pyIn) { assert(pyIn); return type->d->converter->toCppPointerConversion.first(pyIn); } -static inline PythonToCppFunc IsPythonToCppConvertible(SbkConverter* converter, PyObject* pyIn) +static inline PythonToCppFunc IsPythonToCppConvertible(SbkConverter *converter, PyObject *pyIn) { assert(pyIn); - ToCppConversionList& convs = converter->toCppConversions; + ToCppConversionList &convs = converter->toCppConversions; for (ToCppConversionList::iterator conv = convs.begin(); conv != convs.end(); ++conv) { PythonToCppFunc toCppFunc = 0; if ((toCppFunc = (*conv).first(pyIn))) @@ -151,16 +151,16 @@ static inline PythonToCppFunc IsPythonToCppConvertible(SbkConverter* converter, } return 0; } -PythonToCppFunc isPythonToCppValueConvertible(SbkObjectType* type, PyObject* pyIn) +PythonToCppFunc isPythonToCppValueConvertible(SbkObjectType *type, PyObject *pyIn) { return IsPythonToCppConvertible(type->d->converter, pyIn); } -PythonToCppFunc isPythonToCppConvertible(SbkConverter* converter, PyObject* pyIn) +PythonToCppFunc isPythonToCppConvertible(SbkConverter *converter, PyObject *pyIn) { return IsPythonToCppConvertible(converter, pyIn); } -PythonToCppFunc isPythonToCppReferenceConvertible(SbkObjectType* type, PyObject* pyIn) +PythonToCppFunc isPythonToCppReferenceConvertible(SbkObjectType *type, PyObject *pyIn) { if (pyIn != Py_None) { PythonToCppFunc toCpp = isPythonToCppPointerConvertible(type, pyIn); @@ -170,24 +170,27 @@ PythonToCppFunc isPythonToCppReferenceConvertible(SbkObjectType* type, PyObject* return isPythonToCppValueConvertible(type, pyIn); } -void nonePythonToCppNullPtr(PyObject*, void* cppOut) +void nonePythonToCppNullPtr(PyObject *, void *cppOut) { assert(cppOut); - *((void**)cppOut) = 0; + *reinterpret_cast<void **>(cppOut) = nullptr; } -void pythonToCppPointer(SbkObjectType* type, PyObject* pyIn, void* cppOut) +void pythonToCppPointer(SbkObjectType *type, PyObject *pyIn, void *cppOut) { assert(pyIn); assert(cppOut); - SbkObjectType* inType = (SbkObjectType*)Py_TYPE(pyIn); - if (ObjectType::hasCast(inType)) - *((void**)cppOut) = ObjectType::cast(inType, (SbkObject*)pyIn, (PyTypeObject*)type); - else - *((void**)cppOut) = Object::cppPointer((SbkObject*)pyIn, (PyTypeObject*)type); + SbkObjectType *inType = (SbkObjectType *)Py_TYPE(pyIn); + if (ObjectType::hasCast(inType)) { + *reinterpret_cast<void **>(cppOut) = + ObjectType::cast(inType, reinterpret_cast<SbkObject *>(pyIn), reinterpret_cast<PyTypeObject *>(type)); + } else { + *reinterpret_cast<void **>(cppOut) = + Object::cppPointer(reinterpret_cast<SbkObject *>(pyIn), reinterpret_cast<PyTypeObject *>(type)); + } } -bool isImplicitConversion(SbkObjectType* type, PythonToCppFunc toCppFunc) +bool isImplicitConversion(SbkObjectType *type, PythonToCppFunc toCppFunc) { // This is the Object Type or Value Type conversion that only // retrieves the C++ pointer held in the Python wrapper. diff --git a/sources/shiboken2/libshiboken/tmp-referencetopython/sbkconverter.h b/sources/shiboken2/libshiboken/tmp-referencetopython/sbkconverter.h index cc9ea7a19..3578e4039 100644 --- a/sources/shiboken2/libshiboken/tmp-referencetopython/sbkconverter.h +++ b/sources/shiboken2/libshiboken/tmp-referencetopython/sbkconverter.h @@ -64,7 +64,7 @@ struct SbkConverter; * * C++ -> Python */ -typedef PyObject* (*CppToPythonFunc)(const void*); +typedef PyObject *(*CppToPythonFunc)(const void *); /** * This function converts a Python object to a C++ value, it may be @@ -77,7 +77,7 @@ typedef PyObject* (*CppToPythonFunc)(const void*); * * Python -> C++ */ -typedef void (*PythonToCppFunc)(PyObject*,void*); +typedef void (*PythonToCppFunc)(PyObject *,void *); /** * Checks if the Python object passed in the argument is convertible to a @@ -88,7 +88,7 @@ typedef void (*PythonToCppFunc)(PyObject*,void*); * * Python -> C++ ? */ -typedef PythonToCppFunc (*IsConvertibleToCppFunc)(PyObject*); +typedef PythonToCppFunc (*IsConvertibleToCppFunc)(PyObject *); } // extern "C" @@ -105,22 +105,22 @@ namespace Conversions { * \param copyToPythonFunc Function to convert a C++ object to a Python \p type, copying the object. * \returns The new converter referred by the wrapper \p type. */ -LIBSHIBOKEN_API SbkConverter* createConverter(SbkObjectType* type, +LIBSHIBOKEN_API SbkConverter *createConverter(SbkObjectType *type, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc, CppToPythonFunc pointerToPythonFunc, CppToPythonFunc copyToPythonFunc = 0); -LIBSHIBOKEN_API void deleteConverter(SbkConverter* converter); +LIBSHIBOKEN_API void deleteConverter(SbkConverter *converter); /** * Adds a new conversion of a Python object to a C++ value. * This is used in copy and implicit conversions. */ -LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkConverter* converter, +LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkConverter *converter, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc); -LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkObjectType* type, +LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkObjectType *type, PythonToCppFunc pythonToCppFunc, IsConvertibleToCppFunc isConvertibleToCppFunc); @@ -130,19 +130,19 @@ LIBSHIBOKEN_API void addPythonToCppValueConversion(SbkObjectType* type, * Retrieves the Python wrapper object for the given \p cppIn C++ pointer object. * This function is used only for Value and Object Types. * Example usage: - * TYPE* var; - * PyObject* pyVar = pointerToPython(SBKTYPE, &var); + * TYPE *var; + * PyObject *pyVar = pointerToPython(SBKTYPE, &var); */ -LIBSHIBOKEN_API PyObject* pointerToPython(SbkObjectType* type, const void* cppIn); +LIBSHIBOKEN_API PyObject *pointerToPython(SbkObjectType *type, const void *cppIn); /** * Retrieves the Python wrapper object for the given C++ value pointed by \p cppIn. * This function is used only for Value Types. * Example usage: * TYPE var; - * PyObject* pyVar = copyToPython(SBKTYPE, &var); + * PyObject *pyVar = copyToPython(SBKTYPE, &var); */ -LIBSHIBOKEN_API PyObject* copyToPython(SbkObjectType* type, const void* cppIn); +LIBSHIBOKEN_API PyObject *copyToPython(SbkObjectType *type, const void *cppIn); // TODO:WRITEDOCSTRING - used only for Value Types - cppIn must point to a value /** @@ -150,41 +150,41 @@ LIBSHIBOKEN_API PyObject* copyToPython(SbkObjectType* type, const void* cppIn); * This function is used only for Value and Object Types. * It differs from pointerToPython() for not checking for a NULL pointer. * Example usage: - * TYPE& var = SOMETHING; - * PyObject* pyVar = copyToPython(SBKTYPE, &var); + * TYPE &var = SOMETHING; + * PyObject *pyVar = copyToPython(SBKTYPE, &var); */ -LIBSHIBOKEN_API PyObject* referenceToPython(SbkObjectType* type, const void* cppIn); +LIBSHIBOKEN_API PyObject *referenceToPython(SbkObjectType *type, const void *cppIn); // TODO:WRITEDOCSTRING - used only for Primitives and Containers (and Value Types) - cppIn must point to a primitive, container or value type /// This is the same as copyToPython function. -LIBSHIBOKEN_API PyObject* toPython(SbkConverter* converter, const void* cppIn); +LIBSHIBOKEN_API PyObject *toPython(SbkConverter *converter, const void *cppIn); // Python -> C++ convertibility checks ----------------------------------------------------- // TODO:WRITEDOCSTRING -LIBSHIBOKEN_API PythonToCppFunc isPythonToCppPointerConvertible(SbkObjectType* type, PyObject* pyIn); +LIBSHIBOKEN_API PythonToCppFunc isPythonToCppPointerConvertible(SbkObjectType *type, PyObject *pyIn); // TODO:WRITEDOCSTRING- Returns a Python to C++ conversion function if true, or NULL if false. -LIBSHIBOKEN_API PythonToCppFunc isPythonToCppValueConvertible(SbkObjectType* type, PyObject* pyIn); +LIBSHIBOKEN_API PythonToCppFunc isPythonToCppValueConvertible(SbkObjectType *type, PyObject *pyIn); // TODO:WRITEDOCSTRING- Returns a Python to C++ conversion function if true, or NULL if false. -LIBSHIBOKEN_API PythonToCppFunc isPythonToCppReferenceConvertible(SbkObjectType* type, PyObject* pyIn); +LIBSHIBOKEN_API PythonToCppFunc isPythonToCppReferenceConvertible(SbkObjectType *type, PyObject *pyIn); /// This is the same as isPythonToCppValueConvertible function. -LIBSHIBOKEN_API PythonToCppFunc isPythonToCppConvertible(SbkConverter* converter, PyObject* pyIn); +LIBSHIBOKEN_API PythonToCppFunc isPythonToCppConvertible(SbkConverter *converter, PyObject *pyIn); // Python -> C++ --------------------------------------------------------------------------- // TODO:WRITEDOCSTRING - function used by the generated [TYPE]_PythonToCpp_[TYPE]_PTR -LIBSHIBOKEN_API void pythonToCppPointer(SbkObjectType* type, PyObject* pyIn, void* cppOut); +LIBSHIBOKEN_API void pythonToCppPointer(SbkObjectType *type, PyObject *pyIn, void *cppOut); // TODO:WRITEDOCSTRING - function used by the generated isConvertible when the PyObject is None, // making a C++ NULL pointer the result of the toCpp function call. // DRAFT: When the Python object is a Py_None, it's C++ conversion is always a NULL pointer. -LIBSHIBOKEN_API void nonePythonToCppNullPtr(PyObject*, void* cppOut); +LIBSHIBOKEN_API void nonePythonToCppNullPtr(PyObject *, void *cppOut); // TODO:WRITEDOCSTRING - tells if \p toCpp is an implicit conversion. -LIBSHIBOKEN_API bool isImplicitConversion(SbkObjectType* type, PythonToCppFunc toCpp); +LIBSHIBOKEN_API bool isImplicitConversion(SbkObjectType *type, PythonToCppFunc toCpp); } } // namespace Shiboken::Conversions diff --git a/sources/shiboken2/libshiboken/typespec.cpp b/sources/shiboken2/libshiboken/typespec.cpp index a67daf12d..6dc5b00bc 100644 --- a/sources/shiboken2/libshiboken/typespec.cpp +++ b/sources/shiboken2/libshiboken/typespec.cpp @@ -599,17 +599,16 @@ offsetof(PyHeapTypeObject, as_sequence.sq_slice), PyObject * PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { - PyHeapTypeObject *res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, 0); + auto res = reinterpret_cast<PyHeapTypeObject *>(PyType_GenericAlloc(&PyType_Type, 0)); PyTypeObject *type, *base; PyObject *modname; - char *s; - char *res_start = (char*)res; + auto res_start = reinterpret_cast<char *>(res); PyType_Slot *slot; /* Set the type name and qualname */ - s = (char *)strrchr(spec->name, '.'); // C++11 + auto s = const_cast<char *>(strrchr(spec->name, '.')); // C++11 if (s == NULL) - s = (char*)spec->name; + s = const_cast<char *>(spec->name); else s++; @@ -686,7 +685,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) if (slot->slot == Py_tp_base || slot->slot == Py_tp_bases) /* Processed above */ continue; - *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc; + *reinterpret_cast<void **>(res_start + slotoffsets[slot->slot]) = slot->pfunc; /* need to make a copy of the docstring slot, which usually points to a static string literal */ @@ -746,7 +745,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) goto fail; } - return (PyObject*)res; + return reinterpret_cast<PyObject *>(res); fail: Py_DECREF(res); @@ -770,7 +769,7 @@ PyType_GetSlot(PyTypeObject *type, int slot) /* Extension module requesting slot from a future version */ return NULL; } - return *(void**)(((char*)type) + slotoffsets[slot]); + return *reinterpret_cast<void **>(reinterpret_cast<char *>(type) + slotoffsets[slot]); } } // extern "C" diff --git a/sources/shiboken2/libshiboken/typespec.h b/sources/shiboken2/libshiboken/typespec.h index 81227acac..193b654c2 100644 --- a/sources/shiboken2/libshiboken/typespec.h +++ b/sources/shiboken2/libshiboken/typespec.h @@ -53,19 +53,19 @@ typedef struct{ } PyType_Slot; typedef struct{ - const char* name; + const char *name; int basicsize; int itemsize; unsigned int flags; PyType_Slot *slots; /* terminated by slot==0. */ } PyType_Spec; -LIBSHIBOKEN_API PyObject *PyType_FromSpec(PyType_Spec*); +LIBSHIBOKEN_API PyObject *PyType_FromSpec(PyType_Spec *); #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 -LIBSHIBOKEN_API PyObject *PyType_FromSpecWithBases(PyType_Spec*, PyObject*); +LIBSHIBOKEN_API PyObject *PyType_FromSpecWithBases(PyType_Spec *, PyObject *); #endif #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000 -LIBSHIBOKEN_API void* PyType_GetSlot(PyTypeObject*, int); +LIBSHIBOKEN_API void *PyType_GetSlot(PyTypeObject *, int); #endif // from typeslots.h diff --git a/sources/shiboken2/libshiboken/voidptr.cpp b/sources/shiboken2/libshiboken/voidptr.cpp index 5b0cb84ea..4d09adb0c 100644 --- a/sources/shiboken2/libshiboken/voidptr.cpp +++ b/sources/shiboken2/libshiboken/voidptr.cpp @@ -189,7 +189,7 @@ PyObject *toBytes(PyObject *self, PyObject *args) PyErr_SetString(PyExc_IndexError, "VoidPtr does not have a size set."); return nullptr; } - PyObject *bytes = PyBytes_FromStringAndSize(reinterpret_cast<const char*>(sbkObject->cptr), + PyObject *bytes = PyBytes_FromStringAndSize(reinterpret_cast<const char *>(sbkObject->cptr), sbkObject->size); Py_XINCREF(bytes); return bytes; @@ -290,17 +290,17 @@ static int SbkVoidPtrObject_getbuffer(PyObject *obj, Py_buffer *view, int flags) #if PY_VERSION_HEX < 0x03000000 -static Py_ssize_t SbkVoidPtrObject_readbufferproc(PyObject* self, Py_ssize_t segment, void** ptrptr) +static Py_ssize_t SbkVoidPtrObject_readbufferproc(PyObject *self, Py_ssize_t segment, void **ptrptr) { if (segment || !Shiboken::Object::isValid(self)) return -1; SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self); - *ptrptr = reinterpret_cast<void*>(sbkObject->cptr); + *ptrptr = reinterpret_cast<void *>(sbkObject->cptr); return sbkObject->size; } -static Py_ssize_t SbkVoidPtrObject_segcountproc(PyObject* self, Py_ssize_t* lenp) +static Py_ssize_t SbkVoidPtrObject_segcountproc(PyObject *self, Py_ssize_t *lenp) { if (lenp) { SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self); |