Nick Coghlan <ncogh...@gmail.com> added the comment:

Hmm, if we're ever creating a new copy of a Py_buffer without calling GetBuffer 
again on the original object, then *that* is a bug (exactly comparable to 
copying a PyObject pointer without incrementing the reference count - it's OK 
if you can guarantee the lifecycle of your borrowed pointer is shorter than the 
lifecycle of the original, but disallowed otherwise).

This still doesn't sound like a problem with the spec to me, it sounds like a 
problem with the implementation strategy that was originally used when 
integrating the spec into the interpeter core (which I readily agree received 
far less attention than the spec itself did).

It really sounds like we should be creating a _Py_ManagedBuffer internal 
object, with each instance containing a PyObject* and a Py_buffer instance. We 
don't need to alter PEP 3118 to do that - such a change is entirely consumer 
side, so the objects providing the buffers don't need to care how the lifecycle 
of the Py_buffer struct is managed.

When we need another reference to the buffer, we can then just increment the 
refcount of the _Py_ManagedBuffer instance rather than having to call GetBuffer 
again on the original object.

The contents of Py_buffer objects that have been passed to GetBuffer really 
shouldn't be getting modified at all - for those cases, we should maintain 
*two* Py_buffer structs, one (unmodified) with the original results of the 
GetBuffer call, and a second owned by the caller (for manipulation).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10181>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to