On Feb 19, 2009, at 12:36 PM, Alan Kennedy wrote:
>> Has anyone here found the need to replace calls to buffer() when
>> porting CPython to Jython?
It looks like mercurial is using buffer in about 3 places, for zero-
copying of strs and arrays. E.g. converting Python array to a str-like
object with no copy:
# zero copy representation of addlist as a buffer
addbuf = buffer(addlist)
Or a zero copy substring of a str:
s, self.buf = self.buf[:l], buffer(self.buf, l)
Seems like we could replace these with slower str() calls or
If that works, we could propose a patch to mercurial to use the slower
methods if not hasattr(__builtin__, 'buffer').
> Not personally, but pyftpdlib uses buffer, which I came across when
> trying to address socket problems with it. The author is contactable
> from this bug report.
> There's a link in there to a message on python-dev from Guido about
> "buffer" and why he doesn't like it.
I think eventually we'll need to implement the buffer interface/
object, the interface might subclass java.nio's Buffer, or something
like that. We might *really* need it for NumJy. In CPython, mmap
objects actually implement the interface, and the re module acts on
the buffer interface (so then you can re mmap'd objects).
It'd probably all be easier to add in Jython 3, when the str/unicode
distinction will actually make sense on Java.
The post from Guido is pretty old now, I think all of his and others'
gripes with the buffer interface have been resolved with the new,
revamped buffer interface (PEP 3118) which was added in 2.6.
FYI Travis Oliphant gave a talk on it @ last years PyCon: