mirror of
https://github.com/python/cpython.git
synced 2025-10-03 21:55:41 +00:00
Merged revisions 68755 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r68755 | benjamin.peterson | 2009-01-18 18:08:08 -0600 (Sun, 18 Jan 2009) | 1 line raise an OSError for invalid fds #4991 ........
This commit is contained in:
parent
f5def21ce7
commit
61b8e940f3
2 changed files with 24 additions and 0 deletions
|
@ -176,6 +176,10 @@ class OtherFileTests(unittest.TestCase):
|
||||||
f.close()
|
f.close()
|
||||||
os.unlink(TESTFN)
|
os.unlink(TESTFN)
|
||||||
|
|
||||||
|
def testInvalidFd(self):
|
||||||
|
self.assertRaises(ValueError, _fileio._FileIO, -10)
|
||||||
|
self.assertRaises(OSError, _fileio._FileIO, 10)
|
||||||
|
|
||||||
def testBadModeArgument(self):
|
def testBadModeArgument(self):
|
||||||
# verify that we get a sensible error message for bad mode argument
|
# verify that we get a sensible error message for bad mode argument
|
||||||
bad_mode = "qwerty"
|
bad_mode = "qwerty"
|
||||||
|
|
|
@ -119,6 +119,24 @@ dircheck(PyFileIOObject* self, char *name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
check_fd(int fd)
|
||||||
|
{
|
||||||
|
#if defined(HAVE_FSTAT)
|
||||||
|
struct stat buf;
|
||||||
|
if (fstat(fd, &buf) < 0 && errno == EBADF) {
|
||||||
|
PyObject *exc;
|
||||||
|
char *msg = strerror(EBADF);
|
||||||
|
exc = PyObject_CallFunction(PyExc_OSError, "(is)",
|
||||||
|
EBADF, msg);
|
||||||
|
PyErr_SetObject(PyExc_OSError, exc);
|
||||||
|
Py_XDECREF(exc);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
||||||
|
@ -151,6 +169,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
||||||
"Negative filedescriptor");
|
"Negative filedescriptor");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (check_fd(fd))
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue