summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-05-04 20:40:25 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-05-04 20:40:25 (GMT)
commitf3a42dee9a44fd052285078aff009e8d0451d4fa (patch)
treee49adcdfaf54ca0518d8e470f99469c8fb249745 /Python/import.c
parent149e255e00c6c69f1f641eced2549fa323fa8cf5 (diff)
downloadcpython-f3a42dee9a44fd052285078aff009e8d0451d4fa.zip
cpython-f3a42dee9a44fd052285078aff009e8d0451d4fa.tar.gz
cpython-f3a42dee9a44fd052285078aff009e8d0451d4fa.tar.bz2
Simplify code for load_dynamic()
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c46
1 files changed, 3 insertions, 43 deletions
diff --git a/Python/import.c b/Python/import.c
index 4f8229b..920d304 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1964,48 +1964,6 @@ imp_is_frozen(PyObject *self, PyObject *args)
return PyBool_FromLong((long) (p == NULL ? 0 : p->size));
}
-static FILE *
-get_file(PyObject *pathname, PyObject *fob, char *mode)
-{
- FILE *fp;
- if (mode[0] == 'U')
- 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)) {
- 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) {
- PyErr_SetFromErrno(PyExc_IOError);
- return NULL;
- }
-
- fp = fdopen(fd, mode);
- if (!fp) {
- PyErr_SetFromErrno(PyExc_IOError);
- return NULL;
- }
- return fp;
- }
-}
-
#ifdef HAVE_DYNAMIC_LOADING
static PyObject *
@@ -2018,9 +1976,11 @@ imp_load_dynamic(PyObject *self, PyObject *args)
&name, PyUnicode_FSDecoder, &pathname, &fob))
return NULL;
if (fob != NULL) {
- fp = get_file(NULL, fob, "r");
+ fp = _Py_fopen(pathname, "r");
if (fp == NULL) {
Py_DECREF(pathname);
+ if (!PyErr_Occurred())
+ PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
}