[Python-3000-checkins] r67051 - in python/branches/py3k: Lib/test/test_io.py Modules/_fileio.c

christian.heimes python-3000-checkins at python.org
Fri Oct 31 00:47:36 CET 2008


Author: christian.heimes
Date: Thu Oct 30 22:23:35 2008
New Revision: 67051

Log:
Issue #4237: io.FileIO() was raising invalid warnings caused by insufficient initialization of PyFileIOObject struct members.

Modified:
   python/branches/py3k/Lib/test/test_io.py
   python/branches/py3k/Modules/_fileio.c

Modified: python/branches/py3k/Lib/test/test_io.py
==============================================================================
--- python/branches/py3k/Lib/test/test_io.py	(original)
+++ python/branches/py3k/Lib/test/test_io.py	Thu Oct 30 22:23:35 2008
@@ -1237,6 +1237,13 @@
             else:
                 self.assert_(issubclass(obj, io.IOBase))
 
+    def test_fileio_warnings(self):
+        with support.check_warnings() as w:
+            self.assertEqual(w.warnings, [])
+            self.assertRaises(TypeError, io.FileIO, [])
+            self.assertEqual(w.warnings, [])
+            self.assertRaises(ValueError, io.FileIO, "/some/invalid/name", "rt")
+            self.assertEqual(w.warnings, [])
 
 def test_main():
     support.run_unittest(IOTest, BytesIOTest, StringIOTest,

Modified: python/branches/py3k/Modules/_fileio.c
==============================================================================
--- python/branches/py3k/Modules/_fileio.c	(original)
+++ python/branches/py3k/Modules/_fileio.c	Thu Oct 30 22:23:35 2008
@@ -86,6 +86,10 @@
 	self = (PyFileIOObject *) type->tp_alloc(type, 0);
 	if (self != NULL) {
 		self->fd = -1;
+		self->readable = 0;
+		self->writable = 0;
+		self->seekable = -1;
+		self->closefd = 1;
 		self->weakreflist = NULL;
 	}
 
@@ -179,8 +183,6 @@
 	    }
 	}
 
-	self->readable = self->writable = 0;
-	self->seekable = -1;
 	s = mode;
 	while (*s) {
 		switch (*s++) {


More information about the Python-3000-checkins mailing list