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

PEP 688: Enhance and clarify the specification #2917

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Dec 7, 2022

@encukou this is an attempt to clarify some of the areas you
brought up in https://discuss.python.org/t/pep-688-take-2-making-the-buffer-protocol-accessible-in-python/19756/15?u=jelle
and subsequent posts. Would you mind taking a look to see if
this addresses your concerns?

pep-0688.rst Outdated Show resolved Hide resolved
Co-authored-by: Petr Viktorin <encukou@gmail.com>
encukou
encukou approved these changes Dec 8, 2022
as was returned by ``__buffer__``. It is
also possible to call ``__release_buffer__`` on a C class that
implements ``bf_releasebuffer``.
Copy link
Member

@encukou encukou Dec 8, 2022

Choose a reason for hiding this comment

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

This might be a different concern, but: what does calling __release_buffer__ on such a class do?

Copy link
Member Author

@JelleZijlstra JelleZijlstra Dec 9, 2022

Choose a reason for hiding this comment

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

It calls bf_releasebuffer, if called with the same memoryview that __buffer__ returned: https://github.com/JelleZijlstra/cpython/blob/pep688v2/Objects/typeobject.c#L7672. In fact it calls memoryview.release(), which takes care of ensuring that we don't double-call bf_releasebuffer (which would likely segfault).

Copy link
Member Author

@JelleZijlstra JelleZijlstra Dec 9, 2022

Choose a reason for hiding this comment

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

Would it be worth calling out in the PEP text that some calls to .__release_buffer__() will not result in a call to the underlying bf_releasebuffer slot? (e.g. if you call it twice, or call it with the wrong memoryview) I think the blanket statement that "The interpreter will ensure that such errors do not lead to memory leaks or memory safety violations" is sufficient, but happy to add more detailed wording.

Copy link
Member

@encukou encukou Dec 12, 2022

Choose a reason for hiding this comment

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

IMO it would be good to specify if these situations raise an exception, warn, or are silent no-ops.

Copy link
Member Author

@JelleZijlstra JelleZijlstra Dec 18, 2022

Choose a reason for hiding this comment

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

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants