mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
The error detection code in FileIO.close() could fail to reflect the errno
value, and report it as -1 instead.
This commit is contained in:
parent
652e7076fe
commit
0ae29cf617
3 changed files with 19 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import errno
|
||||||
import unittest
|
import unittest
|
||||||
from array import array
|
from array import array
|
||||||
from weakref import proxy
|
from weakref import proxy
|
||||||
|
@ -113,6 +114,20 @@ class AutoFileTests(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.fail("Should have raised IOError")
|
self.fail("Should have raised IOError")
|
||||||
|
|
||||||
|
def testErrnoOnClose(self):
|
||||||
|
# Test that the IOError's `errno` attribute is correctly set when
|
||||||
|
# close() fails. Here we first close the file descriptor ourselves so
|
||||||
|
# that close() fails with EBADF ('Bad file descriptor').
|
||||||
|
f = self.f
|
||||||
|
os.close(f.fileno())
|
||||||
|
self.f = None
|
||||||
|
try:
|
||||||
|
f.close()
|
||||||
|
except IOError as e:
|
||||||
|
self.assertEqual(e.errno, errno.EBADF)
|
||||||
|
else:
|
||||||
|
self.fail("Should have raised IOError")
|
||||||
|
|
||||||
|
|
||||||
class OtherFileTests(unittest.TestCase):
|
class OtherFileTests(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- The error detection code in FileIO.close() could fail to reflect the `errno`
|
||||||
|
value, and report it as -1 instead.
|
||||||
|
|
||||||
|
|
||||||
What's New in Python 3.1 alpha 1
|
What's New in Python 3.1 alpha 1
|
||||||
================================
|
================================
|
||||||
|
|
|
@ -97,10 +97,8 @@ fileio_close(PyFileIOObject *self)
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
errno = internal_close(self);
|
errno = internal_close(self);
|
||||||
if (errno < 0) {
|
if (errno < 0)
|
||||||
PyErr_SetFromErrno(PyExc_IOError);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
return PyObject_CallMethod((PyObject*)&PyRawIOBase_Type,
|
return PyObject_CallMethod((PyObject*)&PyRawIOBase_Type,
|
||||||
"close", "O", self);
|
"close", "O", self);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue