[Python-Dev] PEP 296 - The Buffer Problem
Scott Gilbert
xscottg@yahoo.com
Fri, 26 Jul 2002 19:26:38 -0700 (PDT)
--- Thomas Heller <thomas.heller@ion-tof.com> wrote:
> If the safe buffer PEP would be accepted and implemented,
> here's my proposal for the bytes object.
>
> The bytes object uses the safe buffer interface to gain
> access to the byte array it exposes.
>
> The bytes type would probably accept the following arguments:
>
> PyObject *type - the (bytes) type or subtype to create
> PyObject *obj - the object exposing the safe buffer interface
> size_t offset - starting offset of obj's memory block
> size_t length - number of bytes to use (0 for all)
>
> and maybe a flag requesting read or read/write access.
>
> A convention could be that if a NULL is passed for obj,
> then the bytes object itself allocates a memory block
> of length length.
>
> Of course the bytes object itself would also expose the safe
> buffer interface. And slicing, but not repetition.
>
> Isn't the above sufficient (provided that we somehow
> add the pickle stuff into this picture)?
>
It's probably sufficient but more than necessary. In particular,
supporting the safe buffer protocol makes sense to me (if that gets
accepted), but I'm not eager to immediately support the obj pointer as you
describe above.
We've gotten side-tracked a bit when describing the "view behavior" for the
slicing operations on a bytes object. It was not my intent that the bytes
object typically be used to create views into other Python objects. That
whole discussion was an attempt to describe the slicing behavior. From my
perspective, describing the whole inner-thing and outer-thing stuff was to
explain the implementation. Think of the bytes object as a mutable string
with some additional restrictions, and that's what I have in mind.
The mmap example is sort of a retrofit since mmap should probably have been
implemented via something like bytes in the first place (to get the bytes
style slicing among other things), not because I think there are a lot of
objects that you would want to wrap up in bytes views.
The existing buffer object is ok for creating views, and truthfully I don't
know how often it is really used for that. What I (and I think others)
need is more like a pickleable-mutable-reliable-byte-string. I'm not eager
to grow bytes into a superset object.
Even if I'm wrong about the need for this, at the very least, the
additional functionality can be added later. I really just want to push
through a simple, usable, bytes object for the time being. We can easily
add, we can't easily take away.
__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com