diff options
author | Friedemann Kleint <[email protected]> | 2025-01-31 09:30:39 +0100 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2025-02-03 18:12:40 +0100 |
commit | aa9b918153a1414a10c48e996e8a36eccd94140b (patch) | |
tree | c5e0ef7c6db51a81e8f665ee777784671bf2feb4 /sources | |
parent | 4fb8c5ddd8f840b14c65e1f225eb5c5ac4e5ad8b (diff) |
libshiboken: Fix some clang-tidy warnings
- Use auto* for pointers
- Remove duplicate includes
- Use rang-based for
- Remove superfluous inline
- Use of std::string_view::data() (may not be null-terminated)
Pick-to: 6.8
Change-Id: I663d630ad151526ad13546ad079d70635ff1e43d
Reviewed-by: Shyamnath Premnadh <[email protected]>
Diffstat (limited to 'sources')
-rw-r--r-- | sources/shiboken6/libshiboken/autodecref.h | 4 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.cpp | 35 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/bindingmanager.cpp | 11 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/helper.cpp | 12 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/sbkconverter.h | 10 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/sbkenum.cpp | 4 | ||||
-rw-r--r-- | sources/shiboken6/libshiboken/sbkmodule.cpp | 7 |
7 files changed, 39 insertions, 44 deletions
diff --git a/sources/shiboken6/libshiboken/autodecref.h b/sources/shiboken6/libshiboken/autodecref.h index 8af5a1e00..12af8f5ca 100644 --- a/sources/shiboken6/libshiboken/autodecref.h +++ b/sources/shiboken6/libshiboken/autodecref.h @@ -47,8 +47,8 @@ public: /// Returns the pointer of the Python object being held. [[nodiscard]] PyObject *object() const { return m_pyObj; } [[nodiscard]] operator PyObject *() const { return m_pyObj; } - inline operator bool() const { return m_pyObj != nullptr; } - inline PyObject *operator->() { return m_pyObj; } + operator bool() const { return m_pyObj != nullptr; } + PyObject *operator->() { return m_pyObj; } template<typename T> [[deprecated]] T cast() diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index 6480cd85a..9c57635bb 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -1,34 +1,32 @@ // Copyright (C) 2019 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +#include "autodecref.h" #include "basewrapper.h" #include "basewrapper_p.h" #include "bindingmanager.h" +#include "gilstate.h" #include "helper.h" #include "pep384ext.h" #include "sbkconverter.h" #include "sbkerrors.h" #include "sbkfeature_base.h" -#include "sbkstring.h" #include "sbkstaticstrings.h" #include "sbkstaticstrings_p.h" +#include "sbkstring.h" #include "sbktypefactory.h" -#include "autodecref.h" -#include "gilstate.h" -#include <string> -#include <cstring> -#include <cstddef> -#include <set> -#include <sstream> -#include <algorithm> -#include "threadstatesaver.h" #include "signature.h" #include "signature_p.h" +#include "threadstatesaver.h" #include "voidptr.h" -#include <string> +#include <algorithm> +#include <cstddef> +#include <cstring> #include <iostream> +#include <set> #include <sstream> +#include <string> #if defined(__APPLE__) #include <dlfcn.h> @@ -359,7 +357,7 @@ static void SbkDeallocWrapperCommon(PyObject *pyObj, bool canDelete) // Need to decref the type if this is the dealloc func; if type // is subclassed, that dealloc func will decref (see subtype_dealloc // in typeobject.c in the python sources) - auto dealloc = PyType_GetSlot(pyType, Py_tp_dealloc); + auto *dealloc = PyType_GetSlot(pyType, Py_tp_dealloc); // PYSIDE-939: Additional rule: Also when a subtype is heap allocated, // then the subtype_dealloc deref will be suppressed, and we need again @@ -483,7 +481,7 @@ void SbkDeallocWrapperWithPrivateDtor(PyObject *self) void SbkObjectType_tp_dealloc(PyTypeObject *sbkType) { SbkObjectTypePrivate *sotp = PepType_SOTP(sbkType); - auto pyObj = reinterpret_cast<PyObject *>(sbkType); + auto *pyObj = reinterpret_cast<PyObject *>(sbkType); PyObject_GC_UnTrack(pyObj); #if !defined(Py_LIMITED_API) && !defined(PYPY_VERSION) @@ -656,7 +654,7 @@ static PyObject *_setupNew(PyObject *obSelf, PyTypeObject *subtype) auto *self = reinterpret_cast<SbkObject *>(obSelf); Py_INCREF(obSubtype); - auto d = new SbkObjectPrivate; + auto *d = new SbkObjectPrivate; auto *sotp = PepType_SOTP(sbkSubtype); int numBases = ((sotp && sotp->is_multicpp) ? @@ -1113,7 +1111,7 @@ bool canDowncastTo(PyTypeObject *baseType, PyTypeObject *targetType) namespace Object { -static void recursive_invalidate(SbkObject *self, std::set<SbkObject *>& seen); +static void recursive_invalidate(SbkObject *self, std::set<SbkObject *> &seen); bool checkType(PyObject *pyObj) { @@ -1270,8 +1268,7 @@ void releaseOwnership(PyObject *self) } /* Needed forward declarations */ -static void recursive_invalidate(PyObject *pyobj, std::set<SbkObject *>& seen); -static void recursive_invalidate(SbkObject *self, std::set<SbkObject *> &seen); +static void recursive_invalidate(PyObject *pyobj, std::set<SbkObject *> &seen); void invalidate(PyObject *pyobj) { @@ -1681,8 +1678,8 @@ void setParent(PyObject *parent, PyObject *child) } bool parentIsNull = !parent || parent == Py_None; - auto parent_ = reinterpret_cast<SbkObject *>(parent); - auto child_ = reinterpret_cast<SbkObject *>(child); + auto *parent_ = reinterpret_cast<SbkObject *>(parent); + auto *child_ = reinterpret_cast<SbkObject *>(child); if (!parentIsNull) { if (!parent_->d->parentInfo) diff --git a/sources/shiboken6/libshiboken/bindingmanager.cpp b/sources/shiboken6/libshiboken/bindingmanager.cpp index 89990544e..8b6a84d10 100644 --- a/sources/shiboken6/libshiboken/bindingmanager.cpp +++ b/sources/shiboken6/libshiboken/bindingmanager.cpp @@ -290,7 +290,7 @@ void BindingManager::releaseWrapper(SbkObject *sbkObj) auto *d = PepType_SOTP(sbkType); int numBases = ((d && d->is_multicpp) ? getNumberOfCppBaseClasses(Py_TYPE(sbkObj)) : 1); - void ** cptrs = reinterpret_cast<SbkObject *>(sbkObj)->d->cptr; + void **cptrs = sbkObj->d->cptr; const int *mi_offsets = d != nullptr ? d->mi_offsets : nullptr; for (int i = 0; i < numBases; ++i) { if (cptrs[i] != nullptr) @@ -392,11 +392,10 @@ PyObject *BindingManager::getOverride(const void *cptr, if (method != nullptr) { PyObject *mro = Py_TYPE(wrapper)->tp_mro; - int size = PyTuple_Size(mro); bool defaultFound = false; // 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 idx = 1; idx < size - 1; ++idx) { + for (Py_ssize_t idx = 1, size = PyTuple_Size(mro); idx < size - 1; ++idx) { auto *parent = reinterpret_cast<PyTypeObject *>(PyTuple_GetItem(mro, idx)); AutoDecRef parentDict(PepType_GetDict(parent)); if (parentDict) { @@ -468,9 +467,9 @@ void BindingManager::dumpWrapperMap() std::cerr << "-------------------------------\n" << "WrapperMap size: " << wrapperMap.size() << " Types: " << m_d->classHierarchy.nodeSet().size() << '\n'; - for (auto it = wrapperMap.begin(), end = wrapperMap.end(); it != end; ++it) { - const SbkObject *sbkObj = it->second; - std::cerr << "key: " << it->first << ", value: " + for (auto it : wrapperMap) { + const SbkObject *sbkObj = it.second; + std::cerr << "key: " << it.first << ", value: " << static_cast<const void *>(sbkObj) << " (" << (Py_TYPE(sbkObj))->tp_name << ", refcnt: " << Py_REFCNT(reinterpret_cast<const PyObject *>(sbkObj)) << ")\n"; diff --git a/sources/shiboken6/libshiboken/helper.cpp b/sources/shiboken6/libshiboken/helper.cpp index 91337ba15..8ef5f6bfb 100644 --- a/sources/shiboken6/libshiboken/helper.cpp +++ b/sources/shiboken6/libshiboken/helper.cpp @@ -5,12 +5,10 @@ #include "basewrapper_p.h" #include "sbkstring.h" #include "sbkstaticstrings.h" -#include "sbkstaticstrings.h" #include "pep384impl.h" #include <algorithm> #include <optional> - #include <iomanip> #include <iostream> #include <climits> @@ -176,8 +174,8 @@ static void formatPyTuple(PyObject *obj, std::ostream &str) static void formatPyDict(PyObject *obj, std::ostream &str) { - PyObject *key; - PyObject *value; + PyObject *key{}; + PyObject *value{}; Py_ssize_t pos = 0; str << '{'; while (PyDict_Next(obj, &pos, &key, &value) != 0) { @@ -501,7 +499,7 @@ bool listToArgcArgv(PyObject *argList, int *argc, char ***argv, const char *defa PyObject *appName = PyDict_GetItem(globals, Shiboken::PyMagicName::file()); (*argv)[0] = strdup(appName ? Shiboken::String::toCString(appName) : defaultAppName); } else { - for (int i = 0; i < numArgs; ++i) { + for (Py_ssize_t i = 0; i < numArgs; ++i) { PyObject *item = PyList_GetItem(args.object(), i); char *string = nullptr; if (Shiboken::String::check(item)) { @@ -527,7 +525,7 @@ int *sequenceToIntArray(PyObject *obj, bool zeroTerminated) Py_ssize_t size = PySequence_Size(seq.object()); int *array = new int[size + (zeroTerminated ? 1 : 0)]; - for (int i = 0; i < size; i++) { + for (Py_ssize_t i = 0; i < size; i++) { Shiboken::AutoDecRef item(PySequence_GetItem(seq.object(), i)); if (!PyLong_Check(item)) { PyErr_SetString(PyExc_TypeError, "Sequence of ints expected"); @@ -557,7 +555,7 @@ int warning(PyObject *category, int stacklevel, const char *format, ...) // check the necessary memory int size = vsnprintf(nullptr, 0, format, args) + 1; - auto message = new char[size]; + auto *message = new char[size]; int result = 0; if (message) { // format the message diff --git a/sources/shiboken6/libshiboken/sbkconverter.h b/sources/shiboken6/libshiboken/sbkconverter.h index 22d0f923f..a050844f2 100644 --- a/sources/shiboken6/libshiboken/sbkconverter.h +++ b/sources/shiboken6/libshiboken/sbkconverter.h @@ -88,13 +88,13 @@ public: explicit SpecificConverter(const char *typeName); - inline SbkConverter *converter() { return m_converter; } - inline operator SbkConverter *() const { return m_converter; } + SbkConverter *converter() { return m_converter; } + operator SbkConverter *() const { return m_converter; } - inline bool isValid() { return m_type != InvalidConversion; } - inline operator bool() const { return m_type != InvalidConversion; } + bool isValid() { return m_type != InvalidConversion; } + operator bool() const { return m_type != InvalidConversion; } - inline Type conversionType() { return m_type; } + Type conversionType() { return m_type; } PyObject *toPython(const void *cppIn); void toCpp(PyObject *pyIn, void *cppOut); diff --git a/sources/shiboken6/libshiboken/sbkenum.cpp b/sources/shiboken6/libshiboken/sbkenum.cpp index a09dd9faa..5a32876b8 100644 --- a/sources/shiboken6/libshiboken/sbkenum.cpp +++ b/sources/shiboken6/libshiboken/sbkenum.cpp @@ -314,7 +314,7 @@ static PyTypeObject *createEnumForPython(PyObject *scopeOrModule, static PyObject *enumName = String::createStaticString("IntEnum"); if (PyType_Check(scopeOrModule)) { // For global objects, we have no good solution, yet where to put the int info. - auto type = reinterpret_cast<PyTypeObject *>(scopeOrModule); + auto *type = reinterpret_cast<PyTypeObject *>(scopeOrModule); auto *sotp = PepType_SOTP(type); if (!sotp->enumFlagsDict) initEnumFlagsDict(type); @@ -478,7 +478,7 @@ PyTypeObject *createPythonEnum(const char *fullName, PyObject *pyEnumItems, const char *dot = strrchr(fullName, '.'); AutoDecRef name(Shiboken::String::fromCString(dot ? dot + 1 : fullName)); AutoDecRef callArgs(Py_BuildValue("(OO)", name.object(), pyEnumItems)); - auto newType = PyObject_Call(PyEnumType, callArgs, callDict); + auto *newType = PyObject_Call(PyEnumType, callArgs, callDict); setModuleAndQualnameOnType(newType, fullName); diff --git a/sources/shiboken6/libshiboken/sbkmodule.cpp b/sources/shiboken6/libshiboken/sbkmodule.cpp index f254cdfd1..40a90f66b 100644 --- a/sources/shiboken6/libshiboken/sbkmodule.cpp +++ b/sources/shiboken6/libshiboken/sbkmodule.cpp @@ -102,7 +102,8 @@ static void incarnateHelper(PyObject *module, const std::string_view names, auto initFunc = tcStruct.func; PyTypeObject *type = initFunc(modOrType); auto name = names.substr(startPos); - PyObject_SetAttrString(modOrType, name.data(), reinterpret_cast<PyObject *>(type)); + AutoDecRef nameP(PyUnicode_FromStringAndSize(name.data(), name.size())); + PyObject_SetAttr(modOrType, nameP, reinterpret_cast<PyObject *>(type)); } static void incarnateSubtypes(PyObject *module, @@ -542,10 +543,10 @@ SbkConverter **getTypeConverters(PyObject *module) // Replace the dictionary of a module by a different dict. // The dict should be filled with the content of the old dict, before. // Reason: Creating a module dict with __missing__ support. -typedef struct { +struct StartOf_PyModuleObject { PyObject_HEAD PyObject *md_dict; -} StartOf_PyModuleObject; +}; bool replaceModuleDict(PyObject *module, PyObject *modClass, PyObject *dict) { |