Author: Richard Plangger <[email protected]>
Branch: strbuf-as-buffer
Changeset: r89213:aa59208c8d13
Date: 2016-12-21 11:58 +0100
http://bitbucket.org/pypy/pypy/changeset/aa59208c8d13/
Log: change test, use memoryview instead of buffer (need to ensure that
the buffer is writable)
diff --git a/lib-python/2.7/ctypes/test/test_frombuffer.py
b/lib-python/2.7/ctypes/test/test_frombuffer.py
--- a/lib-python/2.7/ctypes/test/test_frombuffer.py
+++ b/lib-python/2.7/ctypes/test/test_frombuffer.py
@@ -32,7 +32,7 @@
del a; gc.collect(); gc.collect(); gc.collect()
self.assertEqual(x[:], expected)
- self.assertRaises((TypeError, ValueError),
+ self.assertRaises(TypeError,
(c_char * 16).from_buffer, "a" * 16)
def test_fom_buffer_with_offset(self):
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -85,7 +85,9 @@
def from_buffer(self, obj, offset=0):
size = self._sizeofinstances()
- buf = buffer(obj, offset, size)
+ buf = memoryview(obj)[offset:]
+ if buf.readonly:
+ raise TypeError("Cannot use %s as modifiable buffer" %
str(type(obj)))
if len(buf) < size:
raise ValueError(
"Buffer size too small (%d instead of at least %d bytes)"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit