Skip to content
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

bpo-33176: Add a toreadonly() method to memoryviews. #6466

Merged
merged 2 commits into from
Apr 14, 2018

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