diff options
Diffstat (limited to 'sources/shiboken2/libshiboken')
26 files changed, 252 insertions, 257 deletions
diff --git a/sources/shiboken2/libshiboken/autodecref.h b/sources/shiboken2/libshiboken/autodecref.h index b2f5a6325..d3353b1e4 100644 --- a/sources/shiboken2/libshiboken/autodecref.h +++ b/sources/shiboken2/libshiboken/autodecref.h @@ -75,14 +75,14 @@ public: Py_XDECREF(m_pyObj); } - inline bool isNull() const { return m_pyObj == 0; } + inline bool isNull() const { return m_pyObj == nullptr; } /// Returns the pointer of the Python object being held. 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); } #endif - inline operator bool() const { return m_pyObj != 0; } + inline operator bool() const { return m_pyObj != nullptr; } inline PyObject *operator->() { return m_pyObj; } template<typename T> diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index a12d95982..b9f6735d8 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -86,14 +86,13 @@ static PyGetSetDef SbkObjectType_Type_getsetlist[] = { }; static PyType_Slot SbkObjectType_Type_slots[] = { - {Py_tp_dealloc, (void *)SbkObjectTypeDealloc}, - {Py_tp_setattro, (void *)PyObject_GenericSetAttr}, - {Py_tp_base, (void *)&PyType_Type}, - {Py_tp_alloc, (void *)PyType_GenericAlloc}, - {Py_tp_getset, (void *)SbkObjectType_Type_getsetlist}, - {Py_tp_new, (void *)SbkObjectTypeTpNew}, - {Py_tp_free, (void *)PyObject_GC_Del}, - {0, 0} + {Py_tp_dealloc, reinterpret_cast<void *>(SbkObjectTypeDealloc)}, + {Py_tp_setattro, reinterpret_cast<void *>(PyObject_GenericSetAttr)}, + {Py_tp_base, static_cast<void *>(&PyType_Type)}, + {Py_tp_alloc, reinterpret_cast<void *>(PyType_GenericAlloc)}, + {Py_tp_new, reinterpret_cast<void *>(SbkObjectTypeTpNew)}, + {Py_tp_free, reinterpret_cast<void *>(PyObject_GC_Del)}, + {0, nullptr} }; static PyType_Spec SbkObjectType_Type_spec = { "Shiboken.ObjectType", @@ -207,23 +206,23 @@ PyTypeObject *SbkObjectType_TypeF(void) static PyObject *SbkObjectGetDict(PyObject *pObj, void *) { - SbkObject *obj = reinterpret_cast<SbkObject *>(pObj); + auto *obj = reinterpret_cast<SbkObject *>(pObj); if (!obj->ob_dict) obj->ob_dict = PyDict_New(); if (!obj->ob_dict) - return 0; + return nullptr; Py_INCREF(obj->ob_dict); return obj->ob_dict; } static PyGetSetDef SbkObjectGetSetList[] = { - {const_cast<char *>("__dict__"), SbkObjectGetDict, 0, 0, 0}, - {0, 0, 0, 0, 0} // Sentinel + {const_cast<char *>("__dict__"), SbkObjectGetDict, nullptr, nullptr, nullptr}, + {nullptr, nullptr, nullptr, nullptr, nullptr} // Sentinel }; static int SbkObject_traverse(PyObject *self, visitproc visit, void *arg) { - SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self); + auto *sbkSelf = reinterpret_cast<SbkObject *>(self); //Visit children Shiboken::ParentInfo *pInfo = sbkSelf->d->parentInfo; @@ -246,7 +245,7 @@ static int SbkObject_traverse(PyObject *self, visitproc visit, void *arg) static int SbkObject_clear(PyObject *self) { - SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self); + auto *sbkSelf = reinterpret_cast<SbkObject *>(self); Shiboken::Object::removeParent(sbkSelf); @@ -261,13 +260,13 @@ static int SbkObject_clear(PyObject *self) } static PyType_Slot SbkObject_Type_slots[] = { - {Py_tp_dealloc, (void *)SbkDeallocWrapperWithPrivateDtor}, - {Py_tp_traverse, (void *)SbkObject_traverse}, - {Py_tp_clear, (void *)SbkObject_clear}, + {Py_tp_dealloc, reinterpret_cast<void *>(SbkDeallocWrapperWithPrivateDtor)}, + {Py_tp_traverse, reinterpret_cast<void *>(SbkObject_traverse)}, + {Py_tp_clear, reinterpret_cast<void *>(SbkObject_clear)}, // unsupported: {Py_tp_weaklistoffset, (void *)offsetof(SbkObject, weakreflist)}, - {Py_tp_getset, (void *)SbkObjectGetSetList}, + {Py_tp_getset, reinterpret_cast<void *>(SbkObjectGetSetList)}, // unsupported: {Py_tp_dictoffset, (void *)offsetof(SbkObject, ob_dict)}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkObject_Type_spec = { "Shiboken.Object", @@ -300,7 +299,7 @@ static int mainThreadDeletionHandler(void *) static void SbkDeallocWrapperCommon(PyObject *pyObj, bool canDelete) { - SbkObject *sbkObj = reinterpret_cast<SbkObject *>(pyObj); + auto *sbkObj = reinterpret_cast<SbkObject *>(pyObj); PyTypeObject *pyType = Py_TYPE(pyObj); // Need to decref the type if this is the dealloc func; if type @@ -377,7 +376,7 @@ void SbkDeallocQAppWrapper(PyObject *pyObj) { SbkDeallocWrapper(pyObj); // PYSIDE-571: make sure to create a singleton deleted qApp. - MakeSingletonQAppWrapper(NULL); + MakeSingletonQAppWrapper(nullptr); } void SbkDeallocWrapperWithPrivateDtor(PyObject *self) @@ -427,11 +426,11 @@ PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *k 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", const_cast<char **>(kwlist), &name, &PyTuple_Type, &pyBases, &PyDict_Type, &dict)) - return NULL; + return nullptr; for (int i=0, i_max=PyTuple_GET_SIZE(pyBases); i < i_max; i++) { PyObject *baseType = PyTuple_GET_ITEM(pyBases, i); @@ -449,10 +448,10 @@ 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)); + auto type_new = reinterpret_cast<newfunc>(PyType_Type.tp_new); + auto *newType = reinterpret_cast<SbkObjectType *>(type_new(metatype, args, kwds)); if (!newType) - return 0; + return nullptr; Shiboken::ObjectType::initPrivateData(newType); SbkObjectTypePrivate *sotp = PepType_SOTP(newType); @@ -543,7 +542,7 @@ PyObject *SbkQAppTpNew(PyTypeObject *subtype, PyObject *, PyObject *) } #endif auto self = reinterpret_cast<SbkObject *>(MakeSingletonQAppWrapper(subtype)); - return self == 0 ? 0 : _setupNew(self, subtype); + return self == nullptr ? nullptr : _setupNew(self, subtype); } void @@ -622,7 +621,7 @@ 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, nullptr)); #else // Python 2.6 doesn't have PyCapsule API, so let's keep usign PyCObject on all Python 2.x if (PyCObject_Check(cppApi)) @@ -766,7 +765,7 @@ bool canCallConstructor(PyTypeObject *myType, PyTypeObject *ctorType) bool hasCast(SbkObjectType *type) { - return PepType_SOTP(type)->mi_specialcast != 0; + return PepType_SOTP(type)->mi_specialcast != nullptr; } void *cast(SbkObjectType *sourceType, SbkObject *obj, PyTypeObject *targetType) @@ -842,7 +841,7 @@ introduceWrapperType(PyObject *enclosingObject, PyObject *heaptype = PyType_FromSpecWithBases(typeSpec, baseTypes); Py_TYPE(heaptype) = SbkObjectType_TypeF(); Py_INCREF(Py_TYPE(heaptype)); - SbkObjectType *type = reinterpret_cast<SbkObjectType *>(heaptype); + auto *type = reinterpret_cast<SbkObjectType *>(heaptype); if (baseType) { if (baseTypes) { for (int i = 0; i < PySequence_Fast_GET_SIZE(baseTypes); ++i) @@ -862,7 +861,7 @@ introduceWrapperType(PyObject *enclosingObject, setOriginalName(type, originalName); setDestructorFunction(type, cppObjDtor); - PyObject *ob_type = reinterpret_cast<PyObject *>(type); + auto *ob_type = reinterpret_cast<PyObject *>(type); if (wrapperFlags & InnerClass) return PyDict_SetItemString(enclosingObject, typeName, ob_type) == 0 ? type : nullptr; @@ -1007,7 +1006,7 @@ void callCppDestructors(SbkObject *pyObj) } delete[] pyObj->d->cptr; - pyObj->d->cptr = 0; + pyObj->d->cptr = nullptr; pyObj->d->validCppObject = false; } @@ -1044,7 +1043,7 @@ void getOwnership(PyObject *pyObj) void releaseOwnership(SbkObject *self) { // skip if the ownership have already moved to c++ - SbkObjectType *selfType = reinterpret_cast<SbkObjectType *>(Py_TYPE(self)); + auto *selfType = reinterpret_cast<SbkObjectType *>(Py_TYPE(self)); if (!self->d->hasOwnership || Shiboken::Conversions::pythonTypeIsValueType(PepType_SOTP(selfType)->converter)) return; @@ -1155,7 +1154,7 @@ void *cppPointer(SbkObject *pyObj, PyTypeObject *desiredType) idx = getTypeIndexOnHierarchy(type, desiredType); if (pyObj->d->cptr) return pyObj->d->cptr[idx]; - return 0; + return nullptr; } std::vector<void *> cppPointers(SbkObject *pyObj) @@ -1175,7 +1174,7 @@ bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr) if (PepType_SOTP(type)->is_multicpp) idx = getTypeIndexOnHierarchy(type, desiredType); - const bool alreadyInitialized = sbkObj->d->cptr[idx] != 0; + const bool alreadyInitialized = sbkObj->d->cptr[idx] != nullptr; if (alreadyInitialized) PyErr_SetString(PyExc_RuntimeError, "You can't initialize an object twice!"); else @@ -1249,11 +1248,11 @@ SbkObject *findColocatedChild(SbkObject *wrapper, return wrapper; if (!(wrapper->d && wrapper->d->cptr)) - return 0; + return nullptr; ParentInfo *pInfo = wrapper->d->parentInfo; if (!pInfo) - return 0; + return nullptr; ChildrenList &children = pInfo->children; @@ -1261,13 +1260,11 @@ SbkObject *findColocatedChild(SbkObject *wrapper, if (!(child->d && child->d->cptr)) continue; if (child->d->cptr[0] == wrapper->d->cptr[0]) { - if (reinterpret_cast<const void *>(Py_TYPE(child)) == reinterpret_cast<const void *>(instanceType)) - return child; - else - return findColocatedChild(child, instanceType); + return reinterpret_cast<const void *>(Py_TYPE(child)) == reinterpret_cast<const void *>(instanceType) + ? child : findColocatedChild(child, instanceType); } } - return 0; + return nullptr; } PyObject *newObject(SbkObjectType *instanceType, @@ -1286,7 +1283,7 @@ PyObject *newObject(SbkObjectType *instanceType, bool shouldCreate = true; bool shouldRegister = true; - SbkObject *self = 0; + SbkObject *self = nullptr; // Some logic to ensure that colocated child field does not overwrite the parent if (BindingManager::instance().hasWrapper(cptr)) { @@ -1313,7 +1310,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), nullptr, nullptr)); self->d->cptr[0] = cptr; self->d->hasOwnership = hasOwnership; self->d->validCppObject = 1; @@ -1328,7 +1325,7 @@ PyObject *newObject(SbkObjectType *instanceType, void destroy(SbkObject *self) { - destroy(self, 0); + destroy(self, nullptr); } void destroy(SbkObject *self, void *cppData) @@ -1369,7 +1366,7 @@ void destroy(SbkObject *self, void *cppData) // the cpp object instance was deleted delete[] self->d->cptr; - self->d->cptr = 0; + self->d->cptr = nullptr; } // After this point the object can be death do not use the self pointer bellow @@ -1393,7 +1390,7 @@ void removeParent(SbkObject *child, bool giveOwnershipBack, bool keepReference) oldBrothers.erase(iChild); - pInfo->parent = 0; + pInfo->parent = nullptr; // This will keep the wrapper reference, will wait for wrapper destruction to remove that if (keepReference && @@ -1427,7 +1424,7 @@ void setParent(PyObject *parent, PyObject *child) * follows the sequence protocol. */ if (PySequence_Check(child) && !Object::checkType(child)) { - Shiboken::AutoDecRef seq(PySequence_Fast(child, 0)); + Shiboken::AutoDecRef seq(PySequence_Fast(child, nullptr)); for (Py_ssize_t i = 0, max = PySequence_Size(seq); i < max; ++i) setParent(parent, PySequence_Fast_GET_ITEM(seq.object(), i)); return; @@ -1492,7 +1489,7 @@ void deallocData(SbkObject *self, bool cleanup) // Remove from BindingManager Shiboken::BindingManager::instance().releaseWrapper(self); delete[] self->d->cptr; - self->d->cptr = 0; + self->d->cptr = nullptr; // delete self->d; PYSIDE-205: wrong! } delete self->d; // PYSIDE-205: always delete d. diff --git a/sources/shiboken2/libshiboken/basewrapper_p.h b/sources/shiboken2/libshiboken/basewrapper_p.h index feba6561e..56a647b21 100644 --- a/sources/shiboken2/libshiboken/basewrapper_p.h +++ b/sources/shiboken2/libshiboken/basewrapper_p.h @@ -58,7 +58,7 @@ namespace Shiboken * This mapping associates a method and argument of an wrapper object with the wrapper of * said argument when it needs the binding to help manage its reference count. */ -typedef std::unordered_multimap<std::string, PyObject *> RefCountMap; +using RefCountMap = std::unordered_multimap<std::string, PyObject *> ; /// Linked list of SbkBaseWrapper pointers using ChildrenList = std::set<SbkObject *>; @@ -67,7 +67,7 @@ using ChildrenList = std::set<SbkObject *>; struct ParentInfo { /// Default ctor. - ParentInfo() : parent(0), hasWrapperRef(false) {} + ParentInfo() : parent(nullptr), hasWrapperRef(false) {} /// Pointer to parent object. SbkObject *parent; /// List of object children. @@ -105,9 +105,9 @@ struct SbkObjectPrivate ~SbkObjectPrivate() { delete parentInfo; - parentInfo = 0; + parentInfo = nullptr; delete referredObjects; - referredObjects = 0; + referredObjects = nullptr; } }; @@ -198,7 +198,7 @@ private: class BaseAccumulatorVisitor : public HierarchyVisitor { public: - typedef std::vector<SbkObjectType *> Result; + using Result = std::vector<SbkObjectType *>; bool visit(SbkObjectType *node) override; diff --git a/sources/shiboken2/libshiboken/bindingmanager.cpp b/sources/shiboken2/libshiboken/bindingmanager.cpp index c526d9b2e..725150e87 100644 --- a/sources/shiboken2/libshiboken/bindingmanager.cpp +++ b/sources/shiboken2/libshiboken/bindingmanager.cpp @@ -52,13 +52,13 @@ namespace Shiboken { -typedef std::unordered_map<const void *, SbkObject *> WrapperMap; +using WrapperMap = std::unordered_map<const void *, SbkObject *>; class Graph { public: - typedef std::vector<SbkObjectType *> NodeList; - typedef std::unordered_map<SbkObjectType *, NodeList> Edges; + using NodeList = std::vector<SbkObjectType *>; + using Edges = std::unordered_map<SbkObjectType *, NodeList>; Edges m_edges; @@ -91,7 +91,7 @@ public: SbkObjectType *identifyType(void **cptr, SbkObjectType *type, SbkObjectType *baseType) const { - Edges::const_iterator edgesIt = m_edges.find(type); + auto edgesIt = m_edges.find(type); if (edgesIt != m_edges.end()) { const NodeList &adjNodes = m_edges.find(type)->second; for (SbkObjectType *node : adjNodes) { @@ -154,8 +154,8 @@ bool BindingManager::BindingManagerPrivate::releaseWrapper(void *cptr, SbkObject // The wrapper argument is checked to ensure that the correct wrapper is released. // Returns true if the correct wrapper is found and released. // If wrapper argument is NULL, no such check is performed. - WrapperMap::iterator iter = wrapperMapper.find(cptr); - if (iter != wrapperMapper.end() && (wrapper == 0 || iter->second == wrapper)) { + auto iter = wrapperMapper.find(cptr); + if (iter != wrapperMapper.end() && (wrapper == nullptr || iter->second == wrapper)) { wrapperMapper.erase(iter); return true; } @@ -165,7 +165,7 @@ bool BindingManager::BindingManagerPrivate::releaseWrapper(void *cptr, SbkObject void BindingManager::BindingManagerPrivate::assignWrapper(SbkObject *wrapper, const void *cptr) { assert(cptr); - WrapperMap::iterator iter = wrapperMapper.find(cptr); + auto iter = wrapperMapper.find(cptr); if (iter == wrapperMapper.end()) wrapperMapper.insert(std::make_pair(cptr, wrapper)); } @@ -224,7 +224,7 @@ void BindingManager::registerWrapper(SbkObject *pyObj, void *cptr) 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 *>(reinterpret_cast<uintptr_t>(cptr) + *offset)); offset++; } } @@ -238,13 +238,13 @@ void BindingManager::releaseWrapper(SbkObject *sbkObj) void ** cptrs = reinterpret_cast<SbkObject *>(sbkObj)->d->cptr; for (int i = 0; i < numBases; ++i) { - unsigned char *cptr = reinterpret_cast<unsigned char *>(cptrs[i]); + auto *cptr = reinterpret_cast<unsigned char *>(cptrs[i]); m_d->releaseWrapper(cptr, sbkObj); if (d && 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); + m_d->releaseWrapper(reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(cptr) + *offset), sbkObj); offset++; } } @@ -266,9 +266,9 @@ void BindingManager::addToDeletionInMainThread(const DestructorEntry &e) SbkObject *BindingManager::retrieveWrapper(const void *cptr) { - WrapperMap::iterator iter = m_d->wrapperMapper.find(cptr); + auto iter = m_d->wrapperMapper.find(cptr); if (iter == m_d->wrapperMapper.end()) - return 0; + return nullptr; return iter->second; } @@ -278,7 +278,7 @@ PyObject *BindingManager::getOverride(const void *cptr, const char *methodName) // 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; + return nullptr; if (wrapper->ob_dict) { PyObject *method = PyDict_GetItemString(wrapper->ob_dict, methodName); @@ -299,7 +299,7 @@ PyObject *BindingManager::getOverride(const void *cptr, const char *methodName) // 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)); + auto *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) { @@ -312,7 +312,7 @@ PyObject *BindingManager::getOverride(const void *cptr, const char *methodName) Py_XDECREF(method); Py_DECREF(pyMethodName); - return 0; + return nullptr; } void BindingManager::addClassInheritance(SbkObjectType *parent, SbkObjectType *child) @@ -335,7 +335,7 @@ std::set<PyObject *> BindingManager::getAllPyObjects() { std::set<PyObject *> pyObjects; const WrapperMap &wrappersMap = m_d->wrapperMapper; - WrapperMap::const_iterator it = wrappersMap.begin(); + auto it = wrappersMap.begin(); for (; it != wrappersMap.end(); ++it) pyObjects.insert(reinterpret_cast<PyObject *>(it->second)); @@ -345,7 +345,7 @@ std::set<PyObject *> BindingManager::getAllPyObjects() void BindingManager::visitAllPyObjects(ObjectVisitor visitor, void *data) { WrapperMap copy = m_d->wrapperMapper; - for (WrapperMap::iterator it = copy.begin(); it != copy.end(); ++it) { + for (auto it = copy.begin(); it != copy.end(); ++it) { if (hasWrapper(it->first)) visitor(it->second, data); } diff --git a/sources/shiboken2/libshiboken/gilstate.cpp b/sources/shiboken2/libshiboken/gilstate.cpp index 64a0b60f3..a59c6f01e 100644 --- a/sources/shiboken2/libshiboken/gilstate.cpp +++ b/sources/shiboken2/libshiboken/gilstate.cpp @@ -43,7 +43,6 @@ namespace Shiboken { GilState::GilState() - : m_locked(false) { if (Py_IsInitialized()) { m_gstate = PyGILState_Ensure(); diff --git a/sources/shiboken2/libshiboken/gilstate.h b/sources/shiboken2/libshiboken/gilstate.h index f0ff45d59..d22f688ba 100644 --- a/sources/shiboken2/libshiboken/gilstate.h +++ b/sources/shiboken2/libshiboken/gilstate.h @@ -59,7 +59,7 @@ public: void release(); private: PyGILState_STATE m_gstate; - bool m_locked; + bool m_locked = false; }; } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/helper.cpp b/sources/shiboken2/libshiboken/helper.cpp index 1a2dc7ab9..fac72d56f 100644 --- a/sources/shiboken2/libshiboken/helper.cpp +++ b/sources/shiboken2/libshiboken/helper.cpp @@ -60,7 +60,7 @@ bool listToArgcArgv(PyObject *argList, int *argc, char ***argv, const char *defa defaultAppName = "PySideApplication"; // Check all items - Shiboken::AutoDecRef args(PySequence_Fast(argList, 0)); + Shiboken::AutoDecRef args(PySequence_Fast(argList, nullptr)); int numArgs = int(PySequence_Fast_GET_SIZE(argList)); for (int i = 0; i < numArgs; ++i) { PyObject *item = PyList_GET_ITEM(args.object(), i); @@ -83,7 +83,7 @@ bool listToArgcArgv(PyObject *argList, int *argc, char ***argv, const char *defa } else { for (int i = 0; i < numArgs; ++i) { PyObject *item = PyList_GET_ITEM(args.object(), i); - char *string = 0; + char *string = nullptr; if (Shiboken::String::check(item)) { string = strdup(Shiboken::String::toCString(item)); } @@ -98,7 +98,7 @@ int *sequenceToIntArray(PyObject *obj, bool zeroTerminated) { AutoDecRef seq(PySequence_Fast(obj, "Sequence of ints expected")); if (seq.isNull()) - return 0; + return nullptr; Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object()); int *array = new int[size + (zeroTerminated ? 1 : 0)]; @@ -108,10 +108,9 @@ int *sequenceToIntArray(PyObject *obj, bool zeroTerminated) if (!PyInt_Check(item)) { PyErr_SetString(PyExc_TypeError, "Sequence of ints expected"); delete[] array; - return 0; - } else { - array[i] = PyInt_AsLong(item); + return nullptr; } + array[i] = PyInt_AsLong(item); } if (zeroTerminated) @@ -133,7 +132,7 @@ int warning(PyObject *category, int stacklevel, const char *format, ...) #endif // check the necessary memory - int size = vsnprintf(NULL, 0, format, args) + 1; + int size = vsnprintf(nullptr, 0, format, args) + 1; auto message = new char[size]; int result = 0; if (message) { diff --git a/sources/shiboken2/libshiboken/helper.h b/sources/shiboken2/libshiboken/helper.h index 6c29ad728..14aae8028 100644 --- a/sources/shiboken2/libshiboken/helper.h +++ b/sources/shiboken2/libshiboken/helper.h @@ -44,7 +44,7 @@ #include "shibokenmacros.h" #include "autodecref.h" -#define SBK_UNUSED(x) (void)x; +#define SBK_UNUSED(x) (void)(x); namespace Shiboken { @@ -90,7 +90,7 @@ class AutoArrayPointer T *data; }; -typedef unsigned long long ThreadId; +using ThreadId = unsigned long long; LIBSHIBOKEN_API ThreadId currentThreadId(); LIBSHIBOKEN_API ThreadId mainThreadId(); diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp index ac0328b6b..fe7157d24 100644 --- a/sources/shiboken2/libshiboken/pep384impl.cpp +++ b/sources/shiboken2/libshiboken/pep384impl.cpp @@ -67,18 +67,18 @@ datetime_struc *PyDateTimeAPI = NULL; #endif static PyObject * -dummy_func(PyObject *self, PyObject *args) +dummy_func(PyObject * /* self */, PyObject * /* args */) { Py_RETURN_NONE; } static struct PyMethodDef probe_methoddef[] = { {"dummy", dummy_func, METH_NOARGS}, - {0} + {nullptr} }; static PyGetSetDef probe_getseters[] = { - {0} /* Sentinel */ + {nullptr} /* Sentinel */ }; #define probe_tp_call make_dummy(1) @@ -110,7 +110,7 @@ static PyType_Slot typeprobe_slots[] = { {Py_tp_new, probe_tp_new}, {Py_tp_free, probe_tp_free}, {Py_tp_is_gc, probe_tp_is_gc}, - {0, 0} + {0, nullptr} }; static PyType_Spec typeprobe_spec = { probe_tp_name, @@ -121,15 +121,15 @@ static PyType_Spec typeprobe_spec = { }; static void -check_PyTypeObject_valid(void) +check_PyTypeObject_valid() { - PyObject *obtype = reinterpret_cast<PyObject *>(&PyType_Type); - PyTypeObject *probe_tp_base = reinterpret_cast<PyTypeObject *>( + auto *obtype = reinterpret_cast<PyObject *>(&PyType_Type); + auto *probe_tp_base = reinterpret_cast<PyTypeObject *>( PyObject_GetAttrString(obtype, "__base__")); PyObject *probe_tp_bases = PyObject_GetAttrString(obtype, "__bases__"); - PyTypeObject *check = reinterpret_cast<PyTypeObject *>( + auto *check = reinterpret_cast<PyTypeObject *>( PyType_FromSpecWithBases(&typeprobe_spec, probe_tp_bases)); - PyTypeObject *typetype = reinterpret_cast<PyTypeObject *>(obtype); + auto *typetype = reinterpret_cast<PyTypeObject *>(obtype); PyObject *w = PyObject_GetAttrString(obtype, "__weakrefoffset__"); long probe_tp_weakrefoffset = PyLong_AsLong(w); PyObject *d = PyObject_GetAttrString(obtype, "__dictoffset__"); diff --git a/sources/shiboken2/libshiboken/qapp_macro.cpp b/sources/shiboken2/libshiboken/qapp_macro.cpp index ea9cf0c86..df24a8052 100644 --- a/sources/shiboken2/libshiboken/qapp_macro.cpp +++ b/sources/shiboken2/libshiboken/qapp_macro.cpp @@ -87,9 +87,9 @@ static SbkObject _Py_ChameleonQAppWrapper_Struct = { BRACE_CLOSE }; -static PyObject *qApp_var = NULL; -static PyObject *qApp_content = (PyObject *)&_Py_ChameleonQAppWrapper_Struct; -static PyObject *qApp_moduledicts[5] = {0, 0, 0, 0, 0}; +static PyObject *qApp_var = nullptr; +static PyObject *qApp_content = reinterpret_cast<PyObject *>(&_Py_ChameleonQAppWrapper_Struct); +static PyObject *qApp_moduledicts[5] = {nullptr, nullptr, nullptr, nullptr, nullptr}; static int qApp_var_ref = 0; static int qApp_content_ref = 0; @@ -120,17 +120,17 @@ reset_qApp_var(void) PyObject * MakeSingletonQAppWrapper(PyTypeObject *type) { - if (type == NULL) + if (type == nullptr) type = Py_NONE_TYPE; if (!(type == Py_NONE_TYPE || Py_TYPE(qApp_content) == Py_NONE_TYPE)) { const char *res_name = PepType_GetNameStr(Py_TYPE(qApp_content)); const char *type_name = PepType_GetNameStr(type); PyErr_Format(PyExc_RuntimeError, "Please destroy the %s singleton before" " creating a new %s instance.", res_name, type_name); - return NULL; + return nullptr; } if (reset_qApp_var() < 0) - return NULL; + return nullptr; // always know the max of the refs if (Py_REFCNT(qApp_var) > qApp_var_ref) qApp_var_ref = Py_REFCNT(qApp_var); @@ -201,7 +201,7 @@ setup_qApp_var(PyObject *module) Py_NONE_TYPE->tp_as_number = &none_as_number; #endif qApp_var = Py_BuildValue("s", "qApp"); - if (qApp_var == NULL) + if (qApp_var == nullptr) return -1; // This is a borrowed reference qApp_moduledicts[0] = PyEval_GetBuiltins(); diff --git a/sources/shiboken2/libshiboken/sbkarrayconverter.cpp b/sources/shiboken2/libshiboken/sbkarrayconverter.cpp index 58e0b18a8..fd09efdae 100644 --- a/sources/shiboken2/libshiboken/sbkarrayconverter.cpp +++ b/sources/shiboken2/libshiboken/sbkarrayconverter.cpp @@ -83,7 +83,7 @@ inline void convertPySequence(PyObject *pyIn, Converter c, T *out) // Internal, for usage by numpy SbkArrayConverter *createArrayConverter(IsArrayConvertibleToCppFunc toCppCheckFunc) { - SbkArrayConverter *result = new SbkArrayConverter; + auto *result = new SbkArrayConverter; result->toCppConversions.push_back(toCppCheckFunc); return result; } @@ -115,7 +115,7 @@ static short toShort(PyObject *pyIn) { return short(PyLong_AsLong(pyIn)); } static void sequenceToCppShortArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<short> *handle = reinterpret_cast<ArrayHandle<short> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<short> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, toShort, handle->data()); } @@ -148,7 +148,7 @@ static short toUnsignedShort(PyObject *pyIn) { return static_cast<unsigned short static void sequenceToCppUnsignedShortArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<unsigned short> *handle = reinterpret_cast<ArrayHandle<unsigned short> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<unsigned short> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, toUnsignedShort, handle->data()); } @@ -160,7 +160,7 @@ static PythonToCppFunc sequenceToCppUnsignedShortArrayCheck(PyObject *pyIn, int static void sequenceToCppIntArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<int> *handle = reinterpret_cast<ArrayHandle<int> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<int> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, _PepLong_AsInt, handle->data()); } @@ -172,7 +172,7 @@ static PythonToCppFunc sequenceToCppIntArrayCheck(PyObject *pyIn, int dim1, int static void sequenceToCppUnsignedArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<unsigned> *handle = reinterpret_cast<ArrayHandle<unsigned> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<unsigned> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, PyLong_AsUnsignedLong, handle->data()); } @@ -184,7 +184,7 @@ static PythonToCppFunc sequenceToCppUnsignedArrayCheck(PyObject *pyIn, int dim1, static void sequenceToCppLongLongArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<long long> *handle = reinterpret_cast<ArrayHandle<long long> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<long long> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, PyLong_AsLongLong, handle->data()); } @@ -196,7 +196,7 @@ static PythonToCppFunc sequenceToCppLongLongArrayCheck(PyObject *pyIn, int dim1, static void sequenceToCppUnsignedLongLongArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<unsigned long long> *handle = reinterpret_cast<ArrayHandle<unsigned long long> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<unsigned long long> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, PyLong_AsUnsignedLongLong, handle->data()); } @@ -218,7 +218,7 @@ static inline bool floatArrayCheck(PyObject *pyIn, int expectedSize = -1) static void sequenceToCppDoubleArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<double> *handle = reinterpret_cast<ArrayHandle<double> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<double> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, PyFloat_AsDouble, handle->data()); } @@ -227,7 +227,7 @@ static inline float pyToFloat(PyObject *pyIn) { return float(PyFloat_AsDouble(py static void sequenceToCppFloatArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<float> *handle = reinterpret_cast<ArrayHandle<float> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<float> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, pyToFloat, handle->data()); } diff --git a/sources/shiboken2/libshiboken/sbkarrayconverter.h b/sources/shiboken2/libshiboken/sbkarrayconverter.h index 5b26c6e3c..84cb2f57f 100644 --- a/sources/shiboken2/libshiboken/sbkarrayconverter.h +++ b/sources/shiboken2/libshiboken/sbkarrayconverter.h @@ -73,10 +73,13 @@ enum : int { template <class T> class ArrayHandle { - ArrayHandle(const ArrayHandle &) = delete; - ArrayHandle &operator=(const ArrayHandle &) = delete; public: - ArrayHandle() {} + ArrayHandle(const ArrayHandle &) = delete; + ArrayHandle& operator=(const ArrayHandle &) = delete; + ArrayHandle(ArrayHandle &&) = delete; + ArrayHandle& operator=(ArrayHandle &&) = delete; + + ArrayHandle() = default; ~ArrayHandle() { destroy(); } void allocate(Py_ssize_t size); @@ -106,7 +109,7 @@ class Array2Handle public: typedef T RowType[columns]; - Array2Handle() {} + Array2Handle() = default; operator RowType *() const { return m_rows; } diff --git a/sources/shiboken2/libshiboken/sbkconverter.cpp b/sources/shiboken2/libshiboken/sbkconverter.cpp index 15afd5933..29eb19715 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.cpp +++ b/sources/shiboken2/libshiboken/sbkconverter.cpp @@ -51,7 +51,7 @@ static SbkConverter **PrimitiveTypeConverters; -typedef std::unordered_map<std::string, SbkConverter *> ConvertersMap; +using ConvertersMap = std::unordered_map<std::string, SbkConverter *>; static ConvertersMap converters; namespace Shiboken { @@ -143,7 +143,7 @@ SbkConverter *createConverter(SbkObjectType *type, SbkConverter *createConverter(PyTypeObject *type, CppToPythonFunc toPythonFunc) { - return createConverterObject(type, 0, 0, 0, toPythonFunc); + return createConverterObject(type, nullptr, nullptr, nullptr, toPythonFunc); } void deleteConverter(SbkConverter *converter) @@ -206,7 +206,7 @@ PyObject *referenceToPython(const SbkConverter *converter, const void *cppIn) { assert(cppIn); - PyObject *pyOut = reinterpret_cast<PyObject *>(BindingManager::instance().retrieveWrapper(cppIn)); + auto *pyOut = reinterpret_cast<PyObject *>(BindingManager::instance().retrieveWrapper(cppIn)); if (pyOut) { Py_INCREF(pyOut); return pyOut; @@ -252,7 +252,7 @@ static inline PythonToCppFunc IsPythonToCppConvertible(const SbkConverter *conve if (PythonToCppFunc toCppFunc = c.first(pyIn)) return toCppFunc; } - return 0; + return nullptr; } PythonToCppFunc isPythonToCppValueConvertible(SbkObjectType *type, PyObject *pyIn) { @@ -287,7 +287,7 @@ PythonToCppFunc isPythonToCppReferenceConvertible(SbkObjectType *type, PyObject void nonePythonToCppNullPtr(PyObject *, void *cppOut) { assert(cppOut); - *reinterpret_cast<void **>(cppOut) = nullptr; + *static_cast<void **>(cppOut) = nullptr; } void *cppPointer(PyTypeObject *desiredType, SbkObject *pyIn) @@ -295,7 +295,7 @@ void *cppPointer(PyTypeObject *desiredType, SbkObject *pyIn) assert(pyIn); if (!ObjectType::checkType(desiredType)) return pyIn; - SbkObjectType *inType = reinterpret_cast<SbkObjectType *>(Py_TYPE(pyIn)); + auto *inType = reinterpret_cast<SbkObjectType *>(Py_TYPE(pyIn)); if (ObjectType::hasCast(inType)) return ObjectType::cast(inType, pyIn, desiredType); return Object::cppPointer(pyIn, desiredType); @@ -307,7 +307,7 @@ void pythonToCppPointer(SbkObjectType *type, PyObject *pyIn, void *cppOut) assert(pyIn); assert(cppOut); *reinterpret_cast<void **>(cppOut) = pyIn == Py_None - ? 0 + ? nullptr : cppPointer(reinterpret_cast<PyTypeObject *>(type), reinterpret_cast<SbkObject *>(pyIn)); } @@ -317,7 +317,7 @@ void pythonToCppPointer(const SbkConverter *converter, PyObject *pyIn, void *cpp assert(pyIn); assert(cppOut); *reinterpret_cast<void **>(cppOut) = pyIn == Py_None - ? 0 + ? nullptr : cppPointer(reinterpret_cast<PyTypeObject *>(converter->pythonType), reinterpret_cast<SbkObject *>(pyIn)); } @@ -367,7 +367,7 @@ bool isImplicitConversion(SbkObjectType *type, PythonToCppFunc toCppFunc) void registerConverterName(SbkConverter *converter , const char *typeName) { - ConvertersMap::iterator iter = converters.find(typeName); + auto iter = converters.find(typeName); if (iter == converters.end()) converters.insert(std::make_pair(typeName, converter)); } @@ -379,7 +379,7 @@ SbkConverter *getConverter(const char *typeName) return it->second; if (Py_VerboseFlag > 0) SbkDbg() << "Can't find type resolver for type '" << typeName << "'."; - return 0; + return nullptr; } SbkConverter *primitiveTypeConverter(int index) @@ -518,7 +518,7 @@ PyTypeObject *getPythonTypeObject(const SbkConverter *converter) { if (converter) return converter->pythonType; - return 0; + return nullptr; } PyTypeObject *getPythonTypeObject(const char *typeName) @@ -542,7 +542,7 @@ bool pythonTypeIsObjectType(const SbkConverter *converter) bool pythonTypeIsWrapperType(const SbkConverter *converter) { - return converter->pointerToPython != 0; + return converter->pointerToPython != nullptr; } SpecificConverter::SpecificConverter(const char *typeName) @@ -568,13 +568,13 @@ PyObject *SpecificConverter::toPython(const void *cppIn) case CopyConversion: return copyToPython(m_converter, cppIn); case PointerConversion: - return pointerToPython(m_converter, *((const void **)cppIn)); + return pointerToPython(m_converter, *static_cast<const void * const *>(cppIn)); case ReferenceConversion: return referenceToPython(m_converter, cppIn); default: PyErr_SetString(PyExc_RuntimeError, "tried to use invalid converter in 'C++ to Python' conversion"); } - return 0; + return nullptr; } void SpecificConverter::toCpp(PyObject *pyIn, void *cppOut) diff --git a/sources/shiboken2/libshiboken/sbkconverter.h b/sources/shiboken2/libshiboken/sbkconverter.h index 2d1735f2b..6c7a29300 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.h +++ b/sources/shiboken2/libshiboken/sbkconverter.h @@ -151,7 +151,7 @@ LIBSHIBOKEN_API SbkConverter *createConverter(SbkObjectType *type, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc, CppToPythonFunc pointerToPythonFunc, - CppToPythonFunc copyToPythonFunc = 0); + CppToPythonFunc copyToPythonFunc = nullptr); /** * Creates a converter for a non wrapper type (primitive or container type). @@ -343,7 +343,7 @@ 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<typename T> SbkConverter *PrimitiveTypeConverter() { return nullptr; } 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); } @@ -371,7 +371,7 @@ 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 nullptr; } // Below are the template specializations for C++ primitive types. template<> inline PyTypeObject *SbkType<PY_LONG_LONG>() { return &PyLong_Type; } diff --git a/sources/shiboken2/libshiboken/sbkconverter_p.h b/sources/shiboken2/libshiboken/sbkconverter_p.h index aa90094af..d87162071 100644 --- a/sources/shiboken2/libshiboken/sbkconverter_p.h +++ b/sources/shiboken2/libshiboken/sbkconverter_p.h @@ -54,8 +54,8 @@ extern "C" { -typedef std::pair<IsConvertibleToCppFunc, PythonToCppFunc> ToCppConversion; -typedef std::vector<ToCppConversion> ToCppConversionVector; +using ToCppConversion = std::pair<IsConvertibleToCppFunc, PythonToCppFunc>; +using ToCppConversionVector = std::vector<ToCppConversion>; /** * \internal @@ -112,11 +112,11 @@ struct SbkConverter template<typename T, typename MaxLimitType, bool isSigned> struct OverFlowCheckerBase { static void formatOverFlowMessage(const MaxLimitType &value, - const std::string *valueAsString = 0) + const std::string *valueAsString = nullptr) { std::ostringstream str; str << "libshiboken: Overflow: Value "; - if (valueAsString != 0 && !valueAsString->empty()) + if (valueAsString != nullptr && !valueAsString->empty()) str << *valueAsString; else str << value; @@ -261,27 +261,27 @@ struct IntPrimitive : TwoPrimitive<INT> double result = PyFloat_AS_DOUBLE(pyIn); // If cast to long directly it could overflow silently. if (OverFlowChecker<INT>::check(result, pyIn)) - PyErr_SetObject(PyExc_OverflowError, 0); + PyErr_SetObject(PyExc_OverflowError, nullptr); *reinterpret_cast<INT * >(cppOut) = static_cast<INT>(result); } static PythonToCppFunc isConvertible(PyObject *pyIn) { if (PyFloat_Check(pyIn)) return toCpp; - return 0; + return nullptr; } 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); + PyErr_SetObject(PyExc_OverflowError, nullptr); *reinterpret_cast<INT * >(cppOut) = static_cast<INT>(result); } static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return otherToCpp; - return 0; + return nullptr; } }; template <> struct Primitive<int> : IntPrimitive<int> {}; @@ -322,7 +322,7 @@ struct Primitive<PY_LONG_LONG> : OnePrimitive<PY_LONG_LONG> { if (SbkNumber_Check(pyIn)) return toCpp; - return 0; + return nullptr; } }; @@ -331,7 +331,7 @@ struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG> { static PyObject *toPython(const void *cppIn) { - return PyLong_FromUnsignedLongLong(*reinterpret_cast<const unsigned PY_LONG_LONG *>(cppIn)); + return PyLong_FromUnsignedLongLong(*static_cast<const unsigned PY_LONG_LONG *>(cppIn)); } static void toCpp(PyObject *pyIn, void *cppOut) { @@ -339,7 +339,7 @@ struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG> if (PyLong_Check(pyIn)) { unsigned PY_LONG_LONG result = PyLong_AsUnsignedLongLong(pyIn); if (OverFlowChecker<unsigned PY_LONG_LONG, unsigned PY_LONG_LONG>::check(result, pyIn)) - PyErr_SetObject(PyExc_OverflowError, 0); + PyErr_SetObject(PyExc_OverflowError, nullptr); *reinterpret_cast<unsigned PY_LONG_LONG * >(cppOut) = result; } else { @@ -366,7 +366,7 @@ struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG> { if (SbkNumber_Check(pyIn)) return toCpp; - return 0; + return nullptr; } }; @@ -387,7 +387,7 @@ struct FloatPrimitive : TwoPrimitive<FLOAT> { if (PyInt_Check(pyIn) || PyLong_Check(pyIn)) return toCpp; - return 0; + return nullptr; } static void otherToCpp(PyObject *pyIn, void *cppOut) { @@ -397,7 +397,7 @@ struct FloatPrimitive : TwoPrimitive<FLOAT> { if (SbkNumber_Check(pyIn)) return otherToCpp; - return 0; + return nullptr; } }; template <> struct Primitive<float> : FloatPrimitive<float> {}; @@ -416,7 +416,7 @@ struct Primitive<bool> : OnePrimitive<bool> { if (SbkNumber_Check(pyIn)) return toCpp; - return 0; + return nullptr; } static void toCpp(PyObject *pyIn, void *cppOut) { @@ -437,20 +437,20 @@ struct CharPrimitive : IntPrimitive<CHAR> { if (Shiboken::String::checkChar(pyIn)) return toCpp; - return 0; + return nullptr; } 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); + PyErr_SetObject(PyExc_OverflowError, nullptr); *reinterpret_cast<CHAR *>(cppOut) = CHAR(result); } static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return otherToCpp; - return 0; + return nullptr; } static SbkConverter *createConverter() { @@ -484,13 +484,13 @@ struct Primitive<const char *> : TwoPrimitive<const char *> } static void toCpp(PyObject *, void *cppOut) { - *((const char **)cppOut) = 0; + *((const char **)cppOut) = nullptr; } static PythonToCppFunc isConvertible(PyObject *pyIn) { if (pyIn == Py_None) return toCpp; - return 0; + return nullptr; } static void otherToCpp(PyObject *pyIn, void *cppOut) { @@ -500,7 +500,7 @@ struct Primitive<const char *> : TwoPrimitive<const char *> { if (Shiboken::String::check(pyIn)) return otherToCpp; - return 0; + return nullptr; } }; @@ -519,7 +519,7 @@ struct Primitive<std::string> : TwoPrimitive<std::string> { if (pyIn == Py_None) return toCpp; - return 0; + return nullptr; } static void otherToCpp(PyObject *pyIn, void *cppOut) { @@ -529,7 +529,7 @@ struct Primitive<std::string> : TwoPrimitive<std::string> { if (Shiboken::String::check(pyIn)) return otherToCpp; - return 0; + return nullptr; } }; @@ -537,7 +537,7 @@ 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; } @@ -551,7 +551,7 @@ struct Primitive<std::nullptr_t> : TwoPrimitive<std::nullptr_t> 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; } diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index 75054ab71..71fcf5f64 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -86,9 +86,9 @@ static PyObject *SbkEnumObject_repr(PyObject *self) static PyObject *SbkEnumObject_name(PyObject *self, void *) { - SbkEnumObject *enum_self = SBK_ENUM(self); + auto *enum_self = SBK_ENUM(self); - if (enum_self->ob_name == NULL) + if (enum_self->ob_name == nullptr) Py_RETURN_NONE; Py_INCREF(enum_self->ob_name); @@ -99,18 +99,18 @@ static PyObject *SbkEnum_tp_new(PyTypeObject *type, PyObject *args, PyObject *) { long itemValue = 0; if (!PyArg_ParseTuple(args, "|l:__new__", &itemValue)) - return 0; + return nullptr; SbkEnumObject *self = PyObject_New(SbkEnumObject, type); if (!self) - return 0; + return nullptr; self->ob_value = itemValue; PyObject *item = Shiboken::Enum::getEnumItemFromValue(type, itemValue); if (item) { - self->ob_name = SbkEnumObject_name(item, 0); + self->ob_name = SbkEnumObject_name(item, nullptr); Py_XDECREF(item); } else { - self->ob_name = 0; + self->ob_name = nullptr; } return reinterpret_cast<PyObject *>(self); } @@ -233,9 +233,8 @@ static PyObject *enum_richcompare(PyObject *self, PyObject *other, int op) if (!(enumA || enumB)) { Py_INCREF(Py_NotImplemented); return Py_NotImplemented; - } else { - result = PyObject_RichCompare(valA, valB, op); } + result = PyObject_RichCompare(valA, valB, op); // Decreasing the reference of the used variables a and b. if (enumA) @@ -256,7 +255,7 @@ static Py_hash_t enum_hash(PyObject *pyObj) static PyGetSetDef SbkEnumGetSetList[] = { {const_cast<char *>("name"), &SbkEnumObject_name, nullptr, nullptr, nullptr}, - {0, 0, 0, 0, 0} // Sentinel + {nullptr, nullptr, nullptr, nullptr, nullptr} // Sentinel }; static void SbkEnumTypeDealloc(PyObject *pyObj); @@ -286,7 +285,7 @@ static PyType_Slot SbkEnumType_Type_slots[] = { {Py_tp_alloc, (void *)PyType_GenericAlloc}, {Py_tp_new, (void *)SbkEnumTypeTpNew}, {Py_tp_free, (void *)PyObject_GC_Del}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkEnumType_Type_spec = { "Shiboken.EnumType", @@ -326,10 +325,10 @@ void SbkEnumTypeDealloc(PyObject *pyObj) PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds) { - newfunc type_new = reinterpret_cast<newfunc>(PyType_GetSlot(&PyType_Type, Py_tp_new)); + auto type_new = reinterpret_cast<newfunc>(PyType_GetSlot(&PyType_Type, Py_tp_new)); auto newType = reinterpret_cast<SbkEnumType *>(type_new(metatype, args, kwds)); if (!newType) - return 0; + return nullptr; return reinterpret_cast<PyObject *>(newType); } @@ -368,13 +367,13 @@ PyObject *getEnumItemFromValue(PyTypeObject *enumType, long itemValue) PyObject *values = PyDict_GetItemString(enumType->tp_dict, const_cast<char *>("values")); while (PyDict_Next(values, &pos, &key, &value)) { - SbkEnumObject *obj = reinterpret_cast<SbkEnumObject *>(value); + auto *obj = reinterpret_cast<SbkEnumObject *>(value); if (obj->ob_value == itemValue) { Py_INCREF(obj); return value; } } - return 0; + return nullptr; } static PyTypeObject *createEnum(const char *fullName, const char *cppName, @@ -383,7 +382,7 @@ static PyTypeObject *createEnum(const char *fullName, const char *cppName, { PyTypeObject *enumType = newTypeWithName(fullName, cppName, flagsType); if (PyType_Ready(enumType) < 0) - return 0; + return nullptr; return enumType; } @@ -391,10 +390,10 @@ PyTypeObject *createGlobalEnum(PyObject *module, const char *name, const char *f { PyTypeObject *enumType = createEnum(fullName, cppName, name, flagsType); if (enumType && PyModule_AddObject(module, name, reinterpret_cast<PyObject *>(enumType)) < 0) - return 0; + return nullptr; if (flagsType && PyModule_AddObject(module, PepType_GetNameStr(flagsType), reinterpret_cast<PyObject *>(flagsType)) < 0) - return 0; + return nullptr; return enumType; } @@ -415,7 +414,7 @@ static PyObject *createEnumItem(PyTypeObject *enumType, const char *itemName, lo { PyObject *enumItem = newItem(enumType, itemValue, itemName); if (PyDict_SetItemString(enumType->tp_dict, itemName, enumItem) < 0) - return 0; + return nullptr; Py_DECREF(enumItem); return enumItem; } @@ -470,9 +469,9 @@ newItem(PyTypeObject *enumType, long itemValue, const char *itemName) enumObj = PyObject_New(SbkEnumObject, enumType); if (!enumObj) - return 0; + return nullptr; - enumObj->ob_name = itemName ? PyBytes_FromString(itemName) : 0; + enumObj->ob_name = itemName ? PyBytes_FromString(itemName) : nullptr; enumObj->ob_value = itemValue; if (newValue) { @@ -514,7 +513,7 @@ static PyType_Slot SbkNewType_slots[] = { {Py_tp_richcompare, (void *)enum_richcompare}, {Py_tp_hash, (void *)enum_hash}, {Py_tp_dealloc, (void *)object_dealloc}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkNewType_spec = { "missing Enum name", // to be inserted later @@ -587,7 +586,7 @@ newTypeWithName(const char *name, { // Careful: PyType_FromSpec does not allocate the string. PyType_Slot newslots[99] = {}; // enough but not too big for the stack - PyType_Spec *newspec = new PyType_Spec; + auto *newspec = new PyType_Spec; newspec->name = strdup(name); newspec->basicsize = SbkNewType_spec.basicsize; newspec->itemsize = SbkNewType_spec.itemsize; @@ -602,11 +601,11 @@ newTypeWithName(const char *name, if (numbers_fromFlag) copyNumberMethods(numbers_fromFlag, newslots, &idx); newspec->slots = newslots; - PyTypeObject *type = reinterpret_cast<PyTypeObject *>(PyType_FromSpec(newspec)); + auto *type = reinterpret_cast<PyTypeObject *>(PyType_FromSpec(newspec)); Py_TYPE(type) = SbkEnumType_TypeF(); Py_INCREF(Py_TYPE(type)); - SbkEnumType *enumType = reinterpret_cast<SbkEnumType *>(type); + auto *enumType = reinterpret_cast<SbkEnumType *>(type); PepType_SETP(enumType)->cppName = cppName; PepType_SETP(enumType)->converterPtr = &PepType_SETP(enumType)->converter; DeclaredEnumTypes::instance().addEnumType(type); diff --git a/sources/shiboken2/libshiboken/sbkenum.h b/sources/shiboken2/libshiboken/sbkenum.h index 199027836..759d72636 100644 --- a/sources/shiboken2/libshiboken/sbkenum.h +++ b/sources/shiboken2/libshiboken/sbkenum.h @@ -101,7 +101,7 @@ namespace Enum 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 = nullptr); LIBSHIBOKEN_API PyTypeObject *newTypeWithName(const char *name, const char *cppName, PyTypeObject *numbers_fromFlag=nullptr); diff --git a/sources/shiboken2/libshiboken/sbkmodule.cpp b/sources/shiboken2/libshiboken/sbkmodule.cpp index 7bfbf51a8..9321725d6 100644 --- a/sources/shiboken2/libshiboken/sbkmodule.cpp +++ b/sources/shiboken2/libshiboken/sbkmodule.cpp @@ -43,10 +43,10 @@ #include <unordered_map> /// This hash maps module objects to arrays of Python types. -typedef std::unordered_map<PyObject *, PyTypeObject **> ModuleTypesMap; +using ModuleTypesMap = std::unordered_map<PyObject *, PyTypeObject **> ; /// This hash maps module objects to arrays of converters. -typedef std::unordered_map<PyObject *, SbkConverter **> ModuleConvertersMap; +using ModuleConvertersMap = std::unordered_map<PyObject *, SbkConverter **>; /// All types produced in imported modules are mapped here. static ModuleTypesMap moduleTypes; @@ -84,27 +84,27 @@ PyObject *create(const char *moduleName, void *moduleData) void registerTypes(PyObject *module, PyTypeObject **types) { - ModuleTypesMap::iterator iter = moduleTypes.find(module); + auto iter = moduleTypes.find(module); if (iter == moduleTypes.end()) moduleTypes.insert(std::make_pair(module, types)); } PyTypeObject **getTypes(PyObject *module) { - ModuleTypesMap::iterator iter = moduleTypes.find(module); + auto iter = moduleTypes.find(module); return (iter == moduleTypes.end()) ? 0 : iter->second; } void registerTypeConverters(PyObject *module, SbkConverter **converters) { - ModuleConvertersMap::iterator iter = moduleConverters.find(module); + auto iter = moduleConverters.find(module); if (iter == moduleConverters.end()) moduleConverters.insert(std::make_pair(module, converters)); } SbkConverter **getTypeConverters(PyObject *module) { - ModuleConvertersMap::iterator iter = moduleConverters.find(module); + auto iter = moduleConverters.find(module); return (iter == moduleConverters.end()) ? 0 : iter->second; } diff --git a/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp b/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp index 8bc680796..996968fa1 100644 --- a/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp +++ b/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp @@ -138,7 +138,7 @@ static bool isPrimitiveArray(PyObject *pyIn, int expectedNpType) { if (!PyArray_Check(pyIn)) return false; - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); if (debugNumPy) { std::cerr << __FUNCTION__ << "(expectedNpType=" << expectedNpType; if (const char *name = npTypeName(expectedNpType)) @@ -176,7 +176,7 @@ static inline bool primitiveArrayCheck1(PyObject *pyIn, int expectedNpType, int if (!isPrimitiveArray<1>(pyIn, expectedNpType)) return false; if (expectedSize >= 0) { - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); const int size = int(PyArray_DIMS(pya)[0]); if (size < expectedSize) { warning(PyExc_RuntimeWarning, 0, "A numpy array of size %d was passed to a function expects %d.", @@ -191,8 +191,8 @@ static inline bool primitiveArrayCheck1(PyObject *pyIn, int expectedNpType, int template <class T> static void convertArray1(PyObject *pyIn, void *cppOut) { - ArrayHandle<T> *handle = reinterpret_cast<ArrayHandle<T> *>(cppOut); - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *handle = reinterpret_cast<ArrayHandle<T> *>(cppOut); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); const npy_intp size = PyArray_DIMS(pya)[0]; if (debugNumPy) std::cerr << __FUNCTION__ << ' ' << size << '\n'; @@ -204,8 +204,8 @@ template <class T> static void convertArray2(PyObject *pyIn, void *cppOut) { typedef typename Array2Handle<T, 1>::RowType RowType; - Array2Handle<T, 1> *handle = reinterpret_cast<Array2Handle<T, 1> *>(cppOut); - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *handle = reinterpret_cast<Array2Handle<T, 1> *>(cppOut); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); handle->setData(reinterpret_cast<RowType *>(PyArray_DATA(pya))); } @@ -220,7 +220,7 @@ static inline bool primitiveArrayCheck2(PyObject *pyIn, int expectedNpType, int if (!isPrimitiveArray<2>(pyIn, expectedNpType)) return false; if (expectedDim2 >= 0) { - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); const int dim1 = int(PyArray_DIMS(pya)[0]); const int dim2 = int(PyArray_DIMS(pya)[1]); if (dim1 != expectedDim1 || dim2 != expectedDim2) { diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp index d3c337524..9ba5be281 100644 --- a/sources/shiboken2/libshiboken/sbkstring.cpp +++ b/sources/shiboken2/libshiboken/sbkstring.cpp @@ -95,7 +95,7 @@ PyObject *fromCString(const char *value, int len) const char *toCString(PyObject *str, Py_ssize_t *len) { if (str == Py_None) - return NULL; + return nullptr; if (PyUnicode_Check(str)) { if (len) { // We need to encode the unicode string into utf8 to know the size of returned char *. @@ -119,7 +119,7 @@ const char *toCString(PyObject *str, Py_ssize_t *len) *len = PyBytes_GET_SIZE(str); return PyBytes_AS_STRING(str); } - return 0; + return nullptr; } bool concat(PyObject **val1, PyObject *val2) diff --git a/sources/shiboken2/libshiboken/sbkstring.h b/sources/shiboken2/libshiboken/sbkstring.h index ec674ee7b..7f434e1b9 100644 --- a/sources/shiboken2/libshiboken/sbkstring.h +++ b/sources/shiboken2/libshiboken/sbkstring.h @@ -59,7 +59,7 @@ namespace String 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 const char *toCString(PyObject *str, Py_ssize_t *len = nullptr); 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); diff --git a/sources/shiboken2/libshiboken/shibokenbuffer.h b/sources/shiboken2/libshiboken/shibokenbuffer.h index 8c41dad6c..dc9f8d89f 100644 --- a/sources/shiboken2/libshiboken/shibokenbuffer.h +++ b/sources/shiboken2/libshiboken/shibokenbuffer.h @@ -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 = nullptr); } // namespace Buffer } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index 8f9c5a459..e62f861a2 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -79,7 +79,7 @@ typedef struct safe_globals_struc { PyObject *make_helptext_func; } safe_globals_struc, *safe_globals; -static safe_globals pyside_globals = 0; +static safe_globals pyside_globals = nullptr; static PyObject *GetTypeKey(PyObject *ob); @@ -234,10 +234,10 @@ compute_name_key(PyObject *ob) static int build_name_key_to_func(PyObject *obtype) { - PyTypeObject *type = reinterpret_cast<PyTypeObject *>(obtype); + auto *type = reinterpret_cast<PyTypeObject *>(obtype); PyMethodDef *meth = type->tp_methods; - if (meth == 0) + if (meth == nullptr) return 0; Shiboken::AutoDecRef type_key(GetTypeKey(obtype)); @@ -457,7 +457,7 @@ static safe_globals_struc * init_phase_1(void) { { - safe_globals_struc *p = reinterpret_cast<safe_globals_struc *> + auto *p = reinterpret_cast<safe_globals_struc *> (malloc(sizeof(safe_globals_struc))); if (p == nullptr) goto error; @@ -661,11 +661,11 @@ add_more_getsets(PyTypeObject *type, PyGetSetDef *gsp, PyObject **old_descr) // // keep the original __doc__ functions -static PyObject *old_cf_doc_descr = 0; -static PyObject *old_sm_doc_descr = 0; -static PyObject *old_md_doc_descr = 0; -static PyObject *old_tp_doc_descr = 0; -static PyObject *old_wd_doc_descr = 0; +static PyObject *old_cf_doc_descr = nullptr; +static PyObject *old_sm_doc_descr = nullptr; +static PyObject *old_md_doc_descr = nullptr; +static PyObject *old_tp_doc_descr = nullptr; +static PyObject *old_wd_doc_descr = nullptr; static int handle_doc_in_progress = 0; @@ -675,7 +675,7 @@ handle_doc(PyObject *ob, PyObject *old_descr) init_module_1(); init_module_2(); Shiboken::AutoDecRef ob_type(GetClassOfFunc(ob)); - PyTypeObject *type = reinterpret_cast<PyTypeObject *>(ob_type.object()); + auto *type = reinterpret_cast<PyTypeObject *>(ob_type.object()); if (handle_doc_in_progress || strncmp(type->tp_name, "PySide2.", 8) != 0) return PyObject_CallMethod(old_descr, const_cast<char *>("__get__"), const_cast<char *>("(O)"), ob); handle_doc_in_progress++; @@ -737,35 +737,35 @@ static PyGetSetDef new_PyCFunction_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_cf_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_cf_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; static PyGetSetDef new_PyStaticMethod_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_sm_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_sm_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; static PyGetSetDef new_PyMethodDescr_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_md_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_md_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; static PyGetSetDef new_PyType_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_tp_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_tp_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; static PyGetSetDef new_PyWrapperDescr_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_wd_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_wd_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; //////////////////////////////////////////////////////////////////////////// @@ -795,7 +795,7 @@ get_signature_intern(PyObject *ob, const char *modifier) } static PyObject * -get_signature(PyObject *self, PyObject *args) +get_signature(PyObject * /* self */, PyObject *args) { PyObject *ob; const char *modifier = nullptr; @@ -1056,11 +1056,11 @@ _build_func_to_type(PyObject *obtype) * and record the mapping from static method to this type in a dict. * We also check for hidden methods, see below. */ - PyTypeObject *type = reinterpret_cast<PyTypeObject *>(obtype); + auto *type = reinterpret_cast<PyTypeObject *>(obtype); PyObject *dict = type->tp_dict; PyMethodDef *meth = type->tp_methods; - if (meth == 0) + if (meth == nullptr) return 0; for (; meth->ml_name != nullptr; meth++) { @@ -1123,12 +1123,12 @@ _build_func_to_type(PyObject *obtype) } int -SbkSpecial_Type_Ready(PyObject *module, PyTypeObject *type, +SbkSpecial_Type_Ready(PyObject * /* module */, PyTypeObject *type, const char *signatures[]) { if (PyType_Ready(type) < 0) return -1; - PyObject *ob_type = reinterpret_cast<PyObject *>(type); + auto *ob_type = reinterpret_cast<PyObject *>(type); int ret = PySide_BuildSignatureArgs(ob_type, signatures); if (ret < 0) { PyErr_Print(); diff --git a/sources/shiboken2/libshiboken/threadstatesaver.cpp b/sources/shiboken2/libshiboken/threadstatesaver.cpp index 517341617..0d19528f9 100644 --- a/sources/shiboken2/libshiboken/threadstatesaver.cpp +++ b/sources/shiboken2/libshiboken/threadstatesaver.cpp @@ -42,9 +42,7 @@ namespace Shiboken { -ThreadStateSaver::ThreadStateSaver() - : m_threadState(0) - {} +ThreadStateSaver::ThreadStateSaver() = default; ThreadStateSaver::~ThreadStateSaver() { @@ -61,7 +59,7 @@ void ThreadStateSaver::restore() { if (m_threadState) { PyEval_RestoreThread(m_threadState); - m_threadState = 0; + m_threadState = nullptr; } } diff --git a/sources/shiboken2/libshiboken/threadstatesaver.h b/sources/shiboken2/libshiboken/threadstatesaver.h index 10b3af12b..ddfbcb93b 100644 --- a/sources/shiboken2/libshiboken/threadstatesaver.h +++ b/sources/shiboken2/libshiboken/threadstatesaver.h @@ -59,7 +59,7 @@ public: void save(); void restore(); private: - PyThreadState *m_threadState; + PyThreadState *m_threadState = nullptr; }; } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/voidptr.cpp b/sources/shiboken2/libshiboken/voidptr.cpp index 4d09adb0c..d4ce58c87 100644 --- a/sources/shiboken2/libshiboken/voidptr.cpp +++ b/sources/shiboken2/libshiboken/voidptr.cpp @@ -61,10 +61,10 @@ PyObject *SbkVoidPtrObject_new(PyTypeObject *type, PyObject *args, PyObject *kwd // SbkVoidPtrObject *self = // reinterpret_cast<SbkVoidPtrObject *>(type->tp_alloc); PyObject *ob = type->tp_alloc(type, 0); - SbkVoidPtrObject *self = reinterpret_cast<SbkVoidPtrObject *>(ob); + auto *self = reinterpret_cast<SbkVoidPtrObject *>(ob); - if (self != 0) { - self->cptr = 0; + if (self != nullptr) { + self->cptr = nullptr; self->size = -1; self->isWritable = false; } @@ -80,9 +80,9 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) PyObject *addressObject; Py_ssize_t size = -1; int isWritable = 0; - SbkVoidPtrObject *sbkSelf = reinterpret_cast<SbkVoidPtrObject *>(self); + auto *sbkSelf = reinterpret_cast<SbkVoidPtrObject *>(self); - static const char *kwlist[] = {"address", "size", "writeable", 0}; + static const char *kwlist[] = {"address", "size", "writeable", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ni", const_cast<char **>(kwlist), &addressObject, &size, &isWritable)) @@ -90,7 +90,7 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) // Void pointer. if (SbkVoidPtr_Check(addressObject)) { - SbkVoidPtrObject *sbkOther = reinterpret_cast<SbkVoidPtrObject *>(addressObject); + auto *sbkOther = reinterpret_cast<SbkVoidPtrObject *>(addressObject); sbkSelf->cptr = sbkOther->cptr; sbkSelf->size = sbkOther->size; sbkSelf->isWritable = sbkOther->isWritable; @@ -105,17 +105,17 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) sbkSelf->cptr = bufferView.buf; sbkSelf->size = bufferView.len > 0 ? bufferView.len : size; - sbkSelf->isWritable = bufferView.readonly > 0 ? false : true; + sbkSelf->isWritable = bufferView.readonly <= 0; // Release the buffer. PyBuffer_Release(&bufferView); } // Shiboken::Object wrapper. else if (Shiboken::Object::checkType(addressObject)) { - SbkObject *sbkOther = reinterpret_cast<SbkObject *>(addressObject); + auto *sbkOther = reinterpret_cast<SbkObject *>(addressObject); sbkSelf->cptr = sbkOther->d->cptr[0]; sbkSelf->size = size; - sbkSelf->isWritable = isWritable > 0 ? true : false; + sbkSelf->isWritable = isWritable > 0; } // An integer representing an address. else { @@ -137,7 +137,7 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) } sbkSelf->cptr = cptr; sbkSelf->size = size; - sbkSelf->isWritable = isWritable > 0 ? true : false; + sbkSelf->isWritable = isWritable > 0; } } @@ -147,8 +147,8 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) PyObject *SbkVoidPtrObject_richcmp(PyObject *obj1, PyObject *obj2, int op) { PyObject *result = Py_False; - void *cptr1 = 0; - void *cptr2 = 0; + void *cptr1 = nullptr; + void *cptr2 = nullptr; bool validObjects = true; if (SbkVoidPtr_Check(obj1)) @@ -178,13 +178,13 @@ PyObject *SbkVoidPtrObject_richcmp(PyObject *obj1, PyObject *obj2, int op) PyObject *SbkVoidPtrObject_int(PyObject *v) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); return PyLong_FromVoidPtr(sbkObject->cptr); } PyObject *toBytes(PyObject *self, PyObject *args) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self); if (sbkObject->size < 0) { PyErr_SetString(PyExc_IndexError, "VoidPtr does not have a size set."); return nullptr; @@ -197,12 +197,12 @@ PyObject *toBytes(PyObject *self, PyObject *args) static struct PyMethodDef SbkVoidPtrObject_methods[] = { {"toBytes", toBytes, METH_NOARGS}, - {0} + {nullptr} }; static Py_ssize_t SbkVoidPtrObject_length(PyObject *v) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); if (sbkObject->size < 0) { PyErr_SetString(PyExc_IndexError, "VoidPtr does not have a size set."); return -1; @@ -218,7 +218,7 @@ PyObject *SbkVoidPtrObject_repr(PyObject *v) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); #ifdef IS_PY3K PyObject *s = PyUnicode_FromFormat("%s(%p, %zd, %s)", #else @@ -234,7 +234,7 @@ PyObject *SbkVoidPtrObject_repr(PyObject *v) PyObject *SbkVoidPtrObject_str(PyObject *v) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); #ifdef IS_PY3K PyObject *s = PyUnicode_FromFormat("%s(Address %p, Size %zd, isWritable %s)", #else @@ -251,10 +251,10 @@ PyObject *SbkVoidPtrObject_str(PyObject *v) static int SbkVoidPtrObject_getbuffer(PyObject *obj, Py_buffer *view, int flags) { - if (view == NULL) + if (view == nullptr) return -1; - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(obj); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(obj); if (sbkObject->size < 0) return -1; @@ -273,18 +273,18 @@ static int SbkVoidPtrObject_getbuffer(PyObject *obj, Py_buffer *view, int flags) view->len = sbkObject->size; view->readonly = readonly; view->itemsize = 1; - view->format = NULL; + view->format = nullptr; if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) - view->format = "B"; + view->format = const_cast<char *>("B"); view->ndim = 1; - view->shape = NULL; + view->shape = nullptr; if ((flags & PyBUF_ND) == PyBUF_ND) view->shape = &(view->len); - view->strides = NULL; + view->strides = nullptr; if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) view->strides = &(view->itemsize); - view->suboffsets = NULL; - view->internal = NULL; + view->suboffsets = nullptr; + view->internal = nullptr; return 0; } @@ -321,7 +321,7 @@ PyBufferProcs SbkVoidPtrObjectBufferProc = { static PyBufferProcs SbkVoidPtrObjectBufferProc = { (getbufferproc)SbkVoidPtrObject_getbuffer, // bf_getbuffer - (releasebufferproc)0 // bf_releasebuffer + (releasebufferproc)nullptr // bf_releasebuffer }; #endif @@ -337,7 +337,7 @@ static PyType_Slot SbkVoidPtrType_slots[] = { {Py_tp_new, (void *)SbkVoidPtrObject_new}, {Py_tp_dealloc, (void *)object_dealloc}, {Py_tp_methods, (void *)SbkVoidPtrObject_methods}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkVoidPtrType_spec = { "shiboken2.libshiboken.VoidPtr", @@ -354,7 +354,7 @@ PyTypeObject *SbkVoidPtrTypeF(void) { static PyTypeObject *type = nullptr; if (!type) - type = (PyTypeObject *)PyType_FromSpec(&SbkVoidPtrType_spec); + type = reinterpret_cast<PyTypeObject *>(PyType_FromSpec(&SbkVoidPtrType_spec)); #if PY_VERSION_HEX < 0x03000000 type->tp_as_buffer = &SbkVoidPtrObjectBufferProc; @@ -410,24 +410,24 @@ static PyObject *toPython(const void *cppIn) static void VoidPtrToCpp(PyObject *pyIn, void *cppOut) { - SbkVoidPtrObject *sbkIn = reinterpret_cast<SbkVoidPtrObject *>(pyIn); + auto *sbkIn = reinterpret_cast<SbkVoidPtrObject *>(pyIn); *reinterpret_cast<void **>(cppOut) = sbkIn->cptr; } static PythonToCppFunc VoidPtrToCppIsConvertible(PyObject *pyIn) { - return SbkVoidPtr_Check(pyIn) ? VoidPtrToCpp : 0; + return SbkVoidPtr_Check(pyIn) ? VoidPtrToCpp : nullptr; } static void SbkObjectToCpp(PyObject *pyIn, void *cppOut) { - SbkObject *sbkIn = reinterpret_cast<SbkObject *>(pyIn); + auto *sbkIn = reinterpret_cast<SbkObject *>(pyIn); *reinterpret_cast<void **>(cppOut) = sbkIn->d->cptr[0]; } static PythonToCppFunc SbkObjectToCppIsConvertible(PyObject *pyIn) { - return Shiboken::Object::checkType(pyIn) ? SbkObjectToCpp : 0; + return Shiboken::Object::checkType(pyIn) ? SbkObjectToCpp : nullptr; } static void PythonBufferToCpp(PyObject *pyIn, void *cppOut) @@ -453,14 +453,14 @@ static PythonToCppFunc PythonBufferToCppIsConvertible(PyObject *pyIn) // Bail out if the object can't provide a simple contiguous buffer. if (PyObject_GetBuffer(pyIn, &bufferView, PyBUF_SIMPLE) < 0) - return 0; + return nullptr; // Release the buffer. PyBuffer_Release(&bufferView); return PythonBufferToCpp; } - return 0; + return nullptr; } SbkConverter *createConverter() |