[Jython-checkins] jython: memoryview: correct double acquisition of export
jeff.allen
jython-checkins at python.org
Fri Nov 15 00:01:35 CET 2013
http://hg.python.org/jython/rev/360eb0a402fe
changeset: 7148:360eb0a402fe
parent: 7146:4af2f4241912
user: Jeff Allen <ja.py at farowl.co.uk>
date: Fri Nov 01 22:58:33 2013 +0000
summary:
memoryview: correct double acquisition of export
Added test to test_bytes to show that a released memoryview
no longer locks its underlying object (Jython only, in v2.7).
files:
Lib/test/test_bytes.py | 5 +++
src/org/python/core/PyMemoryView.java | 20 +++++++-------
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -886,6 +886,11 @@
self.assertRaises(BufferError, delslice)
self.assertEqual(b, orig)
+ if test.test_support.is_jython:
+ # Show that releasing v releases the bytearray for size change
+ v.release()
+ b.pop()
+
def test_empty_bytearray(self):
# Issue #7561: operations on empty bytearrays could crash in many
# situations, due to a fragile implementation of the
diff --git a/src/org/python/core/PyMemoryView.java b/src/org/python/core/PyMemoryView.java
--- a/src/org/python/core/PyMemoryView.java
+++ b/src/org/python/core/PyMemoryView.java
@@ -38,14 +38,19 @@
private boolean hashCacheValid = false;
/**
- * Construct a PyMemoryView from a PyBuffer interface. The buffer so obtained will be writable
- * if the underlying object permits it. The <code>memoryview</code> takes a new lease on the
- * <code>PyBuffer</code>.
+ * Construct a <code>PyMemoryView</code> from an object bearing the {@link BufferProtocol}
+ * interface. If this object is already an exported buffer, the <code>memoryview</code> takes a
+ * new lease on it. The buffer so obtained will be writable if the underlying object permits it.
*
* @param pybuf buffer exported by some underlying object
*/
- public PyMemoryView(PyBuffer pybuf) {
+ public PyMemoryView(BufferProtocol pybuf) {
super(TYPE);
+ /*
+ * Ask for the full set of facilities (strides, indirect, etc.) from the object in case they
+ * are necessary for navigation, but only ask for read access. If the object is writable,
+ * the PyBuffer will be writable.
+ */
backing = pybuf.getBuffer(PyBUF.FULL_RO);
}
@@ -63,12 +68,7 @@
PyObject obj = ap.getPyObject(0);
if (obj instanceof BufferProtocol) {
- /*
- * Ask for the full set of facilities (strides, indirect, etc.) from the object in case
- * they are necessary for navigation, but only ask for read access. If the object is
- * writable, the PyBuffer will be writable.
- */
- return new PyMemoryView(((BufferProtocol)obj).getBuffer(PyBUF.FULL_RO));
+ return new PyMemoryView((BufferProtocol)obj);
} else {
throw Py.TypeError("cannot make memory view because object does not have "
+ "the buffer interface");
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list