Author: Brian Kearns <[email protected]>
Branch: refactor-buffer-api
Changeset: r70932:494600a98b1a
Date: 2014-04-24 15:31 -0400
http://bitbucket.org/pypy/pypy/changeset/494600a98b1a/
Log: fix readonly check in buffer.writebuf_w
diff --git a/pypy/module/struct/test/test_struct.py
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -369,6 +369,8 @@
assert str(buffer(b)) == ('\x00' * 2 +
self.struct.pack("ii", 17, 42) +
'\x00' * (19-sz-2))
+ exc = raises(TypeError, self.struct.pack_into, "ii", buffer(b), 0, 17,
42)
+ assert str(exc.value) == "buffer is read-only"
exc = raises(TypeError, self.struct.pack_into, "ii", 'test', 0, 17, 42)
assert str(exc.value) == "Cannot use string as modifiable buffer"
exc = raises(self.struct.error, self.struct.pack_into, "ii", b[0:1],
0, 17, 42)
diff --git a/pypy/objspace/std/bufferobject.py
b/pypy/objspace/std/bufferobject.py
--- a/pypy/objspace/std/bufferobject.py
+++ b/pypy/objspace/std/bufferobject.py
@@ -29,6 +29,9 @@
return self.buf
def writebuf_w(self, space):
+ if self.buf.readonly:
+ raise OperationError(space.w_TypeError, space.wrap(
+ "buffer is read-only"))
return self.buf
def charbuf_w(self, space):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit