diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-12-18 20:05:22 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-12-18 20:05:22 (GMT) |
commit | 357347627186a037805b12ff1740d36d0f8e2e11 (patch) | |
tree | 528222a77785f9b82fadcc5ae98cd0d44846fc15 /Python | |
parent | bd0850b8575730fb1ea587a64e95c818e9504c13 (diff) | |
parent | bd206e27a49dd4cc94ee264c706614190ce0eb3c (diff) | |
download | cpython-357347627186a037805b12ff1740d36d0f8e2e11.zip cpython-357347627186a037805b12ff1740d36d0f8e2e11.tar.gz cpython-357347627186a037805b12ff1740d36d0f8e2e11.tar.bz2 |
(Merge 3.2) Handle correctly _Py_fopen() error: don't replace the exception
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/Python/import.c b/Python/import.c index 34d1a26..c754131 100644 --- a/Python/import.c +++ b/Python/import.c @@ -3760,26 +3760,38 @@ get_file(PyObject *pathname, PyObject *fob, char *mode) mode = "r" PY_STDIOTEXTMODE; if (fob == NULL) { fp = _Py_fopen(pathname, mode); + if (!fp) { + if (!PyErr_Occurred()) + PyErr_SetFromErrno(PyExc_IOError); + return NULL; + } + return fp; } else { int fd = PyObject_AsFileDescriptor(fob); if (fd == -1) return NULL; - if (!_PyVerify_fd(fd)) - goto error; + if (!_PyVerify_fd(fd)) { + PyErr_SetFromErrno(PyExc_IOError); + return NULL; + } + /* the FILE struct gets a new fd, so that it can be closed * independently of the file descriptor given */ fd = dup(fd); - if (fd == -1) - goto error; + if (fd == -1) { + PyErr_SetFromErrno(PyExc_IOError); + return NULL; + } + fp = fdopen(fd, mode); - } - if (fp) + if (!fp) { + PyErr_SetFromErrno(PyExc_IOError); + return NULL; + } return fp; -error: - PyErr_SetFromErrno(PyExc_IOError); - return NULL; + } } static PyObject * |