diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-25 09:33:27 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-25 10:43:56 +0200 |
commit | ddfbbd346b522703a5b6f8d274a7f79983e5f319 (patch) | |
tree | 6ebd312287a1398b4b619b37045370cbeb83e1d1 /sources/shiboken2/libshiboken | |
parent | 2eced73f6b8dd9f568e84e78f786a0ec8d6dd429 (diff) |
shiboken: Introduce nullptr
Apply Fixits by Qt Creator with some amendments.
Change-Id: Ie8300ddb834adb8b649324562f2c912a4e8cf4ce
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/libshiboken')
18 files changed, 131 insertions, 131 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..db7d0ad84 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -93,7 +93,7 @@ static PyType_Slot SbkObjectType_Type_slots[] = { {Py_tp_getset, (void *)SbkObjectType_Type_getsetlist}, {Py_tp_new, (void *)SbkObjectTypeTpNew}, {Py_tp_free, (void *)PyObject_GC_Del}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkObjectType_Type_spec = { "Shiboken.ObjectType", @@ -211,14 +211,14 @@ static PyObject *SbkObjectGetDict(PyObject *pObj, void *) 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) @@ -267,7 +267,7 @@ static PyType_Slot SbkObject_Type_slots[] = { // unsupported: {Py_tp_weaklistoffset, (void *)offsetof(SbkObject, weakreflist)}, {Py_tp_getset, (void *)SbkObjectGetSetList}, // unsupported: {Py_tp_dictoffset, (void *)offsetof(SbkObject, ob_dict)}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkObject_Type_spec = { "Shiboken.Object", @@ -377,7 +377,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) @@ -431,7 +431,7 @@ PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *k &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); @@ -452,7 +452,7 @@ PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *k newfunc type_new = reinterpret_cast<newfunc>(PyType_Type.tp_new); SbkObjectType *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 +543,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 +622,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 +766,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) @@ -1007,7 +1007,7 @@ void callCppDestructors(SbkObject *pyObj) } delete[] pyObj->d->cptr; - pyObj->d->cptr = 0; + pyObj->d->cptr = nullptr; pyObj->d->validCppObject = false; } @@ -1155,7 +1155,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 +1175,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 +1249,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; @@ -1267,7 +1267,7 @@ SbkObject *findColocatedChild(SbkObject *wrapper, return findColocatedChild(child, instanceType); } } - return 0; + return nullptr; } PyObject *newObject(SbkObjectType *instanceType, @@ -1286,7 +1286,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 +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), nullptr, nullptr)); self->d->cptr[0] = cptr; self->d->hasOwnership = hasOwnership; self->d->validCppObject = 1; @@ -1328,7 +1328,7 @@ PyObject *newObject(SbkObjectType *instanceType, void destroy(SbkObject *self) { - destroy(self, 0); + destroy(self, nullptr); } void destroy(SbkObject *self, void *cppData) @@ -1369,7 +1369,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 +1393,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 +1427,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 +1492,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..d119c7ec6 100644 --- a/sources/shiboken2/libshiboken/basewrapper_p.h +++ b/sources/shiboken2/libshiboken/basewrapper_p.h @@ -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; } }; diff --git a/sources/shiboken2/libshiboken/bindingmanager.cpp b/sources/shiboken2/libshiboken/bindingmanager.cpp index c526d9b2e..92451a153 100644 --- a/sources/shiboken2/libshiboken/bindingmanager.cpp +++ b/sources/shiboken2/libshiboken/bindingmanager.cpp @@ -155,7 +155,7 @@ bool BindingManager::BindingManagerPrivate::releaseWrapper(void *cptr, SbkObject // 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)) { + if (iter != wrapperMapper.end() && (wrapper == nullptr || iter->second == wrapper)) { wrapperMapper.erase(iter); return true; } @@ -268,7 +268,7 @@ SbkObject *BindingManager::retrieveWrapper(const void *cptr) { WrapperMap::iterator 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); @@ -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) diff --git a/sources/shiboken2/libshiboken/helper.cpp b/sources/shiboken2/libshiboken/helper.cpp index 1a2dc7ab9..85ae2b133 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,7 +108,7 @@ int *sequenceToIntArray(PyObject *obj, bool zeroTerminated) if (!PyInt_Check(item)) { PyErr_SetString(PyExc_TypeError, "Sequence of ints expected"); delete[] array; - return 0; + return nullptr; } else { array[i] = PyInt_AsLong(item); } @@ -133,7 +133,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/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp index ac0328b6b..8a2930fc8 100644 --- a/sources/shiboken2/libshiboken/pep384impl.cpp +++ b/sources/shiboken2/libshiboken/pep384impl.cpp @@ -74,11 +74,11 @@ dummy_func(PyObject *self, PyObject *args) 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, diff --git a/sources/shiboken2/libshiboken/qapp_macro.cpp b/sources/shiboken2/libshiboken/qapp_macro.cpp index ea9cf0c86..cab205970 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_var = nullptr; static PyObject *qApp_content = (PyObject *)&_Py_ChameleonQAppWrapper_Struct; -static PyObject *qApp_moduledicts[5] = {0, 0, 0, 0, 0}; +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/sbkconverter.cpp b/sources/shiboken2/libshiboken/sbkconverter.cpp index 15afd5933..45551666a 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.cpp +++ b/sources/shiboken2/libshiboken/sbkconverter.cpp @@ -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) @@ -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) { @@ -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)); } @@ -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) @@ -574,7 +574,7 @@ PyObject *SpecificConverter::toPython(const void *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..84de2099a 100644 --- a/sources/shiboken2/libshiboken/sbkconverter_p.h +++ b/sources/shiboken2/libshiboken/sbkconverter_p.h @@ -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; } }; @@ -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; } }; diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index 75054ab71..78dba3c54 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -88,7 +88,7 @@ static PyObject *SbkEnumObject_name(PyObject *self, void *) { SbkEnumObject *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); } @@ -256,7 +256,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 +286,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", @@ -329,7 +329,7 @@ PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwd newfunc 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); } @@ -374,7 +374,7 @@ PyObject *getEnumItemFromValue(PyTypeObject *enumType, long itemValue) return value; } } - return 0; + return nullptr; } static PyTypeObject *createEnum(const char *fullName, const char *cppName, @@ -383,7 +383,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 +391,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 +415,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 +470,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 +514,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 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/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..6d40ce42c 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); @@ -237,7 +237,7 @@ build_name_key_to_func(PyObject *obtype) PyTypeObject *type = reinterpret_cast<PyTypeObject *>(obtype); PyMethodDef *meth = type->tp_methods; - if (meth == 0) + if (meth == nullptr) return 0; Shiboken::AutoDecRef type_key(GetTypeKey(obtype)); @@ -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; @@ -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} }; //////////////////////////////////////////////////////////////////////////// @@ -1060,7 +1060,7 @@ _build_func_to_type(PyObject *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++) { diff --git a/sources/shiboken2/libshiboken/threadstatesaver.cpp b/sources/shiboken2/libshiboken/threadstatesaver.cpp index d64c01f86..0d19528f9 100644 --- a/sources/shiboken2/libshiboken/threadstatesaver.cpp +++ b/sources/shiboken2/libshiboken/threadstatesaver.cpp @@ -59,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/voidptr.cpp b/sources/shiboken2/libshiboken/voidptr.cpp index 4d09adb0c..0dceefc29 100644 --- a/sources/shiboken2/libshiboken/voidptr.cpp +++ b/sources/shiboken2/libshiboken/voidptr.cpp @@ -63,8 +63,8 @@ PyObject *SbkVoidPtrObject_new(PyTypeObject *type, PyObject *args, PyObject *kwd PyObject *ob = type->tp_alloc(type, 0); SbkVoidPtrObject *self = reinterpret_cast<SbkVoidPtrObject *>(ob); - if (self != 0) { - self->cptr = 0; + if (self != nullptr) { + self->cptr = nullptr; self->size = -1; self->isWritable = false; } @@ -82,7 +82,7 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) int isWritable = 0; SbkVoidPtrObject *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)) @@ -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)) @@ -197,7 +197,7 @@ 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) @@ -251,7 +251,7 @@ 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); @@ -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->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", @@ -416,7 +416,7 @@ static void VoidPtrToCpp(PyObject *pyIn, void *cppOut) static PythonToCppFunc VoidPtrToCppIsConvertible(PyObject *pyIn) { - return SbkVoidPtr_Check(pyIn) ? VoidPtrToCpp : 0; + return SbkVoidPtr_Check(pyIn) ? VoidPtrToCpp : nullptr; } static void SbkObjectToCpp(PyObject *pyIn, void *cppOut) @@ -427,7 +427,7 @@ static void SbkObjectToCpp(PyObject *pyIn, void *cppOut) 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() |