Add const to buffer:request() (#1890)

This commit is contained in:
Stephen Larew 2019-08-27 08:05:47 -07:00 committed by Wenzel Jakob
parent 8f5a8ab4ac
commit 5b4751af26
2 changed files with 2 additions and 2 deletions

View File

@ -1312,7 +1312,7 @@ class buffer : public object {
public:
PYBIND11_OBJECT_DEFAULT(buffer, object, PyObject_CheckBuffer)
buffer_info request(bool writable = false) {
buffer_info request(bool writable = false) const {
int flags = PyBUF_STRIDES | PyBUF_FORMAT;
if (writable) flags |= PyBUF_WRITABLE;
Py_buffer *view = new Py_buffer();

View File

@ -78,7 +78,7 @@ TEST_SUBMODULE(buffers, m) {
py::class_<Matrix>(m, "Matrix", py::buffer_protocol())
.def(py::init<ssize_t, ssize_t>())
/// Construct from a buffer
.def(py::init([](py::buffer b) {
.def(py::init([](py::buffer const b) {
py::buffer_info info = b.request();
if (info.format != py::format_descriptor<float>::format() || info.ndim != 2)
throw std::runtime_error("Incompatible buffer format!");