diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 335b78ff1..2713e13a8 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -547,9 +547,11 @@ public: .ptr(); } - explicit dtype(const std::string &format) : dtype(from_args(pybind11::str(format))) {} + explicit dtype(const pybind11::str &format) : dtype(from_args(format)) {} - explicit dtype(const char *format) : dtype(from_args(pybind11::str(format))) {} + explicit dtype(const std::string &format) : dtype(pybind11::str(format)) {} + + explicit dtype(const char *format) : dtype(pybind11::str(format)) {} dtype(list names, list formats, list offsets, ssize_t itemsize) { dict args; @@ -557,7 +559,7 @@ public: args["formats"] = std::move(formats); args["offsets"] = std::move(offsets); args["itemsize"] = pybind11::int_(itemsize); - m_ptr = from_args(std::move(args)).release().ptr(); + m_ptr = from_args(args).release().ptr(); } explicit dtype(int typenum) @@ -568,7 +570,7 @@ public: } /// This is essentially the same as calling numpy.dtype(args) in Python. - static dtype from_args(object args) { + static dtype from_args(const object &args) { PyObject *ptr = nullptr; if ((detail::npy_api::get().PyArray_DescrConverter_(args.ptr(), &ptr) == 0) || !ptr) { throw error_already_set(); diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 26d9025c5..324fa932f 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -1914,8 +1914,8 @@ public: return memoryview::from_buffer(reinterpret_cast(ptr), sizeof(T), format_descriptor::value, - shape, - strides, + std::move(shape), + std::move(strides), readonly); } @@ -1923,7 +1923,8 @@ public: static memoryview from_buffer(const T *ptr, detail::any_container shape, detail::any_container strides) { - return memoryview::from_buffer(const_cast(ptr), shape, strides, true); + return memoryview::from_buffer( + const_cast(ptr), std::move(shape), std::move(strides), true); } /** \rst diff --git a/tests/test_numpy_dtypes.cpp b/tests/test_numpy_dtypes.cpp index 38f2afa07..c25bc042b 100644 --- a/tests/test_numpy_dtypes.cpp +++ b/tests/test_numpy_dtypes.cpp @@ -610,5 +610,5 @@ TEST_SUBMODULE(numpy_dtypes, m) { []() { PYBIND11_NUMPY_DTYPE(SimpleStruct, bool_, uint_, float_, ldbl_); }); // test_str_leak - m.def("dtype_wrapper", [](py::object d) { return py::dtype::from_args(std::move(d)); }); + m.def("dtype_wrapper", [](const py::object &d) { return py::dtype::from_args(d); }); }