[Jython-checkins] jython (merge 2.5 -> default): Merge w/2.5: Fix for http://bugs.jython.org/issue1640 (cStringIO does not
alan.kennedy
jython-checkins at python.org
Wed Mar 21 00:32:50 CET 2012
http://hg.python.org/jython/rev/6163f0c0208f
changeset: 6444:6163f0c0208f
parent: 6441:4be64842a1d9
parent: 6443:9c21ad4e5818
user: Alan Kennedy <alan at xhaus.com>
date: Tue Mar 20 23:32:11 2012 +0000
summary:
Merge w/2.5: Fix for http://bugs.jython.org/issue1640 (cStringIO does not complain on getvalue after close)
files:
Lib/test/test_StringIO_jy.py | 15 +++++++++++++++
NEWS | 1 +
src/org/python/modules/cStringIO.java | 6 ++++++
3 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_StringIO_jy.py b/Lib/test/test_StringIO_jy.py
--- a/Lib/test/test_StringIO_jy.py
+++ b/Lib/test/test_StringIO_jy.py
@@ -28,9 +28,24 @@
f.write("uvwxyz")
self.assertEqual(f.getvalue(), 'abcdef\x00\x00\x00\x00uvwxyz')
+class TestGetValueAfterClose(unittest.TestCase):
+
+ # This test, or something like it, should be really be pushed upstream
+ def test_getvalue_after_close(self):
+ f = cStringIO.StringIO('hello')
+ f.getvalue()
+ f.close()
+ try:
+ f.getvalue()
+ except ValueError:
+ pass
+ else:
+ self.fail("cStringIO.StringIO: getvalue() after close() should have raised ValueError")
+
def test_main():
test_support.run_unittest(TestUnicodeInput)
test_support.run_unittest(TestWrite)
+ test_support.run_unittest(TestGetValueAfterClose)
if __name__ == '__main__':
test_main()
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@
Jython 2.5.3b2
Bugs Fixed
+ - [ 1640 ] cStringIO does not complain on getvalue after close
- [ 1749 ] function descriptor doesn't work in interactive console
- [ 1721 ] NPE when using JSR 223 (TestCase+Patch)
- [ 1536 ] NPE in org.python.jsr223.PyScriptEngine:187
diff --git a/src/org/python/modules/cStringIO.java b/src/org/python/modules/cStringIO.java
--- a/src/org/python/modules/cStringIO.java
+++ b/src/org/python/modules/cStringIO.java
@@ -107,6 +107,11 @@
*/
public void close() {
closed = true;
+ // No point in zeroing the buf, because it won't be reused.
+ // buf is a final variable, so can't set to null.
+ // Therefore, just leave it and let it be GC'ed when the enclosing object is GC'ed
+ // Or remove the final declaration
+ // buf = null;
}
@@ -405,6 +410,7 @@
* @return the contents of the StringIO.
*/
public synchronized PyString getvalue() {
+ _complain_ifclosed();
return new PyString(buf.toString());
}
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list