diff options
author | Christian Heimes <christian@cheimes.de> | 2008-10-30 21:52:43 +0000 |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-10-30 21:52:43 +0000 |
commit | 8efccfdfd17ce2aaf176f7462cf8086e1282b985 (patch) | |
tree | 2559f3e8554b71a73269138060069798e6cfe6de | |
parent | c353ea795c6850d85e29849e763e83382df4e3e2 (diff) | |
download | cpython-git-8efccfdfd17ce2aaf176f7462cf8086e1282b985.tar.gz |
Merged revisions 67052 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67052 | christian.heimes | 2008-10-30 22:26:15 +0100 (Thu, 30 Oct 2008) | 1 line
Issue #4237: io.FileIO() was raising invalid warnings caused by insufficient initialization of PyFileIOObject struct members.
........
-rw-r--r-- | Lib/test/test_io.py | 7 | ||||
-rw-r--r-- | Modules/_fileio.c | 6 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 9ef2a818b3..08a524fa99 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1236,6 +1236,13 @@ class MiscIOTest(unittest.TestCase): else: self.assert_(issubclass(obj, io.IOBase)) + def test_fileio_warnings(self): + with test_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(): test_support.run_unittest(IOTest, BytesIOTest, StringIOTest, diff --git a/Modules/_fileio.c b/Modules/_fileio.c index d7f7893671..0d770ceb34 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -86,6 +86,10 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kews) 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 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) } } - self->readable = self->writable = 0; - self->seekable = -1; s = mode; while (*s) { switch (*s++) { |