mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
style: clang-tidy: modernize-use-auto
This commit is contained in:
parent
b491b465c7
commit
ce88e940ce
@ -7,6 +7,7 @@ modernize-use-override,
|
||||
readability-container-size-empty,
|
||||
modernize-use-using,
|
||||
modernize-use-equals-default,
|
||||
modernize-use-auto,
|
||||
'
|
||||
|
||||
HeaderFilterRegex: 'pybind11/.*h'
|
||||
|
@ -432,7 +432,7 @@ PYBIND11_NOINLINE inline std::string error_string() {
|
||||
|
||||
#if !defined(PYPY_VERSION)
|
||||
if (scope.trace) {
|
||||
PyTracebackObject *trace = (PyTracebackObject *) scope.trace;
|
||||
auto *trace = (PyTracebackObject *) scope.trace;
|
||||
|
||||
/* Get the deepest trace possible */
|
||||
while (trace->tb_next)
|
||||
@ -1244,7 +1244,7 @@ template <typename StringType, bool IsView = false> struct string_caster {
|
||||
load_src.ptr(), UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32", nullptr));
|
||||
if (!utfNbytes) { PyErr_Clear(); return false; }
|
||||
|
||||
const CharT *buffer = reinterpret_cast<const CharT *>(PYBIND11_BYTES_AS_STRING(utfNbytes.ptr()));
|
||||
const auto *buffer = reinterpret_cast<const CharT *>(PYBIND11_BYTES_AS_STRING(utfNbytes.ptr()));
|
||||
size_t length = (size_t) PYBIND11_BYTES_SIZE(utfNbytes.ptr()) / sizeof(CharT);
|
||||
if (UTF_N > 8) { buffer++; length--; } // Skip BOM for UTF-16/32
|
||||
value = StringType(buffer, length);
|
||||
@ -1258,7 +1258,7 @@ template <typename StringType, bool IsView = false> struct string_caster {
|
||||
|
||||
static handle cast(const StringType &src, return_value_policy /* policy */, handle /* parent */) {
|
||||
const char *buffer = reinterpret_cast<const char *>(src.data());
|
||||
ssize_t nbytes = ssize_t(src.size() * sizeof(CharT));
|
||||
auto nbytes = ssize_t(src.size() * sizeof(CharT));
|
||||
handle s = decode_utfN(buffer, nbytes);
|
||||
if (!s) throw error_already_set();
|
||||
return s;
|
||||
@ -1364,7 +1364,7 @@ public:
|
||||
// errors. We also allow want to allow unicode characters U+0080 through U+00FF, as those
|
||||
// can fit into a single char value.
|
||||
if (StringCaster::UTF_N == 8 && str_len > 1 && str_len <= 4) {
|
||||
unsigned char v0 = static_cast<unsigned char>(value[0]);
|
||||
auto v0 = static_cast<unsigned char>(value[0]);
|
||||
size_t char0_bytes = !(v0 & 0x80) ? 1 : // low bits only: 0-127
|
||||
(v0 & 0xE0) == 0xC0 ? 2 : // 0b110xxxxx - start of 2-byte sequence
|
||||
(v0 & 0xF0) == 0xE0 ? 3 : // 0b1110xxxx - start of 3-byte sequence
|
||||
|
@ -1296,7 +1296,7 @@ public:
|
||||
m_strides.back() = static_cast<value_type>(strides.back());
|
||||
for (size_type i = m_strides.size() - 1; i != 0; --i) {
|
||||
size_type j = i - 1;
|
||||
value_type s = static_cast<value_type>(shape[i]);
|
||||
auto s = static_cast<value_type>(shape[i]);
|
||||
m_strides[j] = strides[j] + m_strides[i] - strides[i] * s;
|
||||
}
|
||||
}
|
||||
@ -1539,7 +1539,7 @@ private:
|
||||
ssize_t nd = 0;
|
||||
std::vector<ssize_t> shape(0);
|
||||
auto trivial = broadcast(buffers, nd, shape);
|
||||
size_t ndim = (size_t) nd;
|
||||
auto ndim = (size_t) nd;
|
||||
|
||||
size_t size = std::accumulate(shape.begin(), shape.end(), (size_t) 1, std::multiplies<size_t>());
|
||||
|
||||
|
@ -165,7 +165,7 @@ protected:
|
||||
/* Get a pointer to the capture object */
|
||||
auto data = (sizeof(capture) <= sizeof(call.func.data)
|
||||
? &call.func.data : call.func.data[0]);
|
||||
capture *cap = const_cast<capture *>(reinterpret_cast<const capture *>(data));
|
||||
auto *cap = const_cast<capture *>(reinterpret_cast<const capture *>(data));
|
||||
|
||||
/* Override policy for rvalues -- usually to enforce rvp::move on an rvalue */
|
||||
return_value_policy policy = return_value_policy_override<Return>::policy(call.func.policy);
|
||||
@ -420,7 +420,7 @@ protected:
|
||||
}
|
||||
|
||||
/* Install docstring */
|
||||
PyCFunctionObject *func = (PyCFunctionObject *) m_ptr;
|
||||
auto *func = (PyCFunctionObject *) m_ptr;
|
||||
if (func->m_ml->ml_doc)
|
||||
std::free(const_cast<char *>(func->m_ml->ml_doc));
|
||||
func->m_ml->ml_doc = strdup(signatures.c_str());
|
||||
@ -465,7 +465,7 @@ protected:
|
||||
*it = overloads;
|
||||
|
||||
/* Need to know how many arguments + keyword arguments there are to pick the right overload */
|
||||
const size_t n_args_in = (size_t) PyTuple_GET_SIZE(args_in);
|
||||
const auto n_args_in = (size_t) PyTuple_GET_SIZE(args_in);
|
||||
|
||||
handle parent = n_args_in > 0 ? PyTuple_GET_ITEM(args_in, 0) : nullptr,
|
||||
result = PYBIND11_TRY_NEXT_OVERLOAD;
|
||||
@ -860,7 +860,7 @@ public:
|
||||
explicit module(const char *name, const char *doc = nullptr) {
|
||||
if (!options::show_user_defined_docstrings()) doc = nullptr;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyModuleDef *def = new PyModuleDef();
|
||||
auto *def = new PyModuleDef();
|
||||
std::memset(def, 0, sizeof(PyModuleDef));
|
||||
def->m_name = name;
|
||||
def->m_doc = doc;
|
||||
@ -1020,7 +1020,7 @@ protected:
|
||||
void install_buffer_funcs(
|
||||
buffer_info *(*get_buffer)(PyObject *, void *),
|
||||
void *get_buffer_data) {
|
||||
PyHeapTypeObject *type = (PyHeapTypeObject*) m_ptr;
|
||||
auto *type = (PyHeapTypeObject*) m_ptr;
|
||||
auto tinfo = detail::get_type_info(&type->ht_type);
|
||||
|
||||
if (!type->ht_type.tp_as_buffer)
|
||||
@ -1242,7 +1242,7 @@ public:
|
||||
|
||||
template <typename Func> class_& def_buffer(Func &&func) {
|
||||
struct capture { Func func; };
|
||||
capture *ptr = new capture { std::forward<Func>(func) };
|
||||
auto *ptr = new capture { std::forward<Func>(func) };
|
||||
install_buffer_funcs([](PyObject *obj, void *ptr) -> buffer_info* {
|
||||
detail::make_caster<type> caster;
|
||||
if (!caster.load(obj, false))
|
||||
|
@ -1351,7 +1351,7 @@ public:
|
||||
buffer_info request(bool writable = false) const {
|
||||
int flags = PyBUF_STRIDES | PyBUF_FORMAT;
|
||||
if (writable) flags |= PyBUF_WRITABLE;
|
||||
Py_buffer *view = new Py_buffer();
|
||||
auto *view = new Py_buffer();
|
||||
if (PyObject_GetBuffer(m_ptr, view, flags) != 0) {
|
||||
delete view;
|
||||
throw error_already_set();
|
||||
|
@ -223,7 +223,7 @@ void vector_modifiers(enable_if_t<is_copy_constructible<typename Vector::value_t
|
||||
if (!slice.compute(v.size(), &start, &stop, &step, &slicelength))
|
||||
throw error_already_set();
|
||||
|
||||
Vector *seq = new Vector();
|
||||
auto *seq = new Vector();
|
||||
seq->reserve((size_t) slicelength);
|
||||
|
||||
for (size_t i=0; i<slicelength; ++i) {
|
||||
|
@ -212,7 +212,7 @@ TEST_SUBMODULE(numpy_array, sm) {
|
||||
.def(py::init<>())
|
||||
.def("numpy_view", [](py::object &obj) {
|
||||
py::print("ArrayClass::numpy_view()");
|
||||
ArrayClass &a = obj.cast<ArrayClass&>();
|
||||
auto &a = obj.cast<ArrayClass&>();
|
||||
return py::array_t<int>({2}, {4}, a.data, obj);
|
||||
}
|
||||
);
|
||||
@ -362,7 +362,7 @@ TEST_SUBMODULE(numpy_array, sm) {
|
||||
// test_array_resize
|
||||
// reshape array to 2D without changing size
|
||||
sm.def("array_reshape2", [](py::array_t<double> a) {
|
||||
const ssize_t dim_sz = (ssize_t)std::sqrt(a.size());
|
||||
const auto dim_sz = (ssize_t)std::sqrt(a.size());
|
||||
if (dim_sz * dim_sz != a.size())
|
||||
throw std::domain_error("array_reshape2: input array total size is not a squared integer");
|
||||
a.resize({dim_sz, dim_sz});
|
||||
|
@ -60,7 +60,7 @@ TEST_SUBMODULE(opaque_types, m) {
|
||||
m.def("get_null_str_value", [](char *ptr) { return reinterpret_cast<std::intptr_t>(ptr); });
|
||||
|
||||
m.def("return_unique_ptr", []() -> std::unique_ptr<StringList> {
|
||||
StringList *result = new StringList();
|
||||
auto *result = new StringList();
|
||||
result->push_back("some value");
|
||||
return std::unique_ptr<StringList>(result);
|
||||
});
|
||||
|
@ -200,7 +200,7 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
|
||||
size_t start, stop, step, slicelength;
|
||||
if (!slice.compute(s.size(), &start, &stop, &step, &slicelength))
|
||||
throw py::error_already_set();
|
||||
Sequence *seq = new Sequence(slicelength);
|
||||
auto *seq = new Sequence(slicelength);
|
||||
for (size_t i = 0; i < slicelength; ++i) {
|
||||
(*seq)[i] = s[start]; start += step;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user