[Python-3000] PyBUF_LOCK fails on bytes objects. they're read-only, why should it fail?

Gregory P. Smith greg at krypto.org
Fri Mar 14 18:45:11 CET 2008


bytes objects are by their definition immutable and read only.  but when
passing one to a buffer api that tries to use the PyBUF_LOCK flag it raises
BufferError "Cannot lock this object." from PyBuffer_FillInfo in
Objects/abstract.c as called by Objects/bytesobject.c's bytes_getbuffer
method.

I think the problem is a >= 0 where a != 0 was intended in
PyBuffer_FillInfo:

--- Objects/abstract.c  (revision 61375)
+++ Objects/abstract.c  (working copy)
@@ -673,7 +673,7 @@
 {
        if (view == NULL) return 0;
        if (((flags & PyBUF_LOCK) == PyBUF_LOCK) &&
-           readonly >= 0) {
+           readonly != 0) {
                PyErr_SetString(PyExc_BufferError,
                                "Cannot lock this object.");
                return -1;


All tests pass for me with this patch applied.

-gps
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20080314/1a8c3be3/attachment.htm 


More information about the Python-3000 mailing list