diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index bcee8b5b81..688ed52b55 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -1242,7 +1242,7 @@ class buffer : public object { class memoryview : public object { public: - explicit memoryview(const buffer_info& info) { + explicit memoryview(const buffer_info& info, bool readonly=false) { static Py_buffer buf { }; // Py_buffer uses signed sizes, strides and shape!.. static std::vector py_strides { }; @@ -1261,7 +1261,7 @@ class memoryview : public object { buf.strides = py_strides.data(); buf.shape = py_shape.data(); buf.suboffsets = nullptr; - buf.readonly = false; + buf.readonly = readonly; buf.internal = nullptr; m_ptr = PyMemoryView_FromBuffer(&buf);