Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 74060:f44ab94cd28b
(Merge 3.2) Handle correctly _Py_fopen() error: don't replace the exception
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sun, 18 Dec 2011 21:05:22 +0100 |
| parents | 2a140b01d343 |
| children | 87331661042b |
line wrap: on
line diff
--- a/Python/import.c Sun Dec 18 20:47:30 2011 +0100 +++ b/Python/import.c Sun Dec 18 21:05:22 2011 +0100 @@ -3760,26 +3760,38 @@ 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) { + PyErr_SetFromErrno(PyExc_IOError); + return NULL; + } + return fp; } - if (fp) - return fp; -error: - PyErr_SetFromErrno(PyExc_IOError); - return NULL; } static PyObject *
