Skip to content

allow creation of readonly memoryview objects #1266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ssize_t> py_strides { };
Expand All @@ -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);
Expand Down