Skip to content

Conversation

pitrou
Copy link
Member

@pitrou pitrou commented Apr 13, 2018

{
CHECK_RELEASED(self);
if (self->view.readonly) {
Py_INCREF(self);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we always need to use mbuf_add_view because of the release() thingy:

>>> b = bytes(10)
>>> m = memoryview(b)
>>> with m.toreadonly() as x:
...     pass
... 
>>> m[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: operation forbidden on released memoryview object

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. It's indeed necessary to create a new object.

@skrah
Copy link
Contributor

skrah commented Apr 14, 2018

Looks good!

@pitrou pitrou merged commit 480ab05 into python:master Apr 14, 2018
@pitrou pitrou deleted the memoryview_toreadonly branch April 14, 2018 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants