Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins

cpython: Simplify code for load dynamic()

 

 

Python checkins RSS feed   Index | Next | Previous | View Threaded


python-checkins at python

May 4, 2012, 1:42 PM

Post #1 of 1 (58 views)
Permalink
cpython: Simplify code for load dynamic()

http://hg.python.org/cpython/rev/cd519a923d41
changeset: 76764:cd519a923d41
user: Antoine Pitrou <solipsis [at] pitrou>
date: Fri May 04 22:40:25 2012 +0200
summary:
Simplify code for load_dynamic()

files:
Python/import.c | 46 ++----------------------------------
1 files changed, 3 insertions(+), 43 deletions(-)


diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -1964,48 +1964,6 @@
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 @@
&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;
}
}

--
Repository URL: http://hg.python.org/cpython

Python checkins RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.