summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2002-05-30 17:15:25 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2002-05-30 17:15:25 (GMT)
commit4ae6faed9f618c53c42816e868c4cb7194cd045f (patch)
tree88aa59f90bd73551bc2cf22139817da4036bc029
parent40b7703f1c65f58f854f3e1b81203ba71ed45df4 (diff)
downloadcpython-4ae6faed9f618c53c42816e868c4cb7194cd045f.zip
cpython-4ae6faed9f618c53c42816e868c4cb7194cd045f.tar.gz
cpython-4ae6faed9f618c53c42816e868c4cb7194cd045f.tar.bz2
Cover a few corners in the 'U' mode integration to make imp work.
get_file() must convert 'U' to "r" PY_STDIOTEXTMODE before calling fopen(). imp_load_module() must accept 'r' or 'U' or something with '+'. Also reflow some long lines.
-rw-r--r--Python/import.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/Python/import.c b/Python/import.c
index 5c53813..112f7f6 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1040,16 +1040,18 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
#endif /* PYOS_OS2 */
for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
#if defined(PYOS_OS2)
- /* OS/2 limits DLLs to 8 character names (w/o extension)
+ /* OS/2 limits DLLs to 8 character names (w/o
+ extension)
* so if the name is longer than that and its a
* dynamically loaded module we're going to try,
* truncate the name before trying
*/
if (strlen(realname) > 8) {
/* is this an attempt to load a C extension? */
- const struct filedescr *scan = _PyImport_DynLoadFiletab;
+ const struct filedescr *scan;
+ scan = _PyImport_DynLoadFiletab;
while (scan->suffix != NULL) {
- if (strcmp(scan->suffix, fdp->suffix) == 0)
+ if (!strcmp(scan->suffix, fdp->suffix))
break;
else
scan++;
@@ -1067,7 +1069,8 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
PySys_WriteStderr("# trying %s\n", buf);
#endif /* !macintosh */
filemode = fdp->mode;
- if (filemode[0] == 'U') filemode = "r" PY_STDIOTEXTMODE;
+ if (filemode[0] == 'U')
+ filemode = "r" PY_STDIOTEXTMODE;
fp = fopen(buf, filemode);
if (fp != NULL) {
if (case_ok(buf, len, namelen, name))
@@ -2296,6 +2299,8 @@ get_file(char *pathname, PyObject *fob, char *mode)
{
FILE *fp;
if (fob == NULL) {
+ if (mode[0] == 'U')
+ mode = "r" PY_STDIOTEXTMODE;
fp = fopen(pathname, mode);
if (fp == NULL)
PyErr_SetFromErrno(PyExc_IOError);
@@ -2403,10 +2408,11 @@ imp_load_module(PyObject *self, PyObject *args)
&name, &fob, &pathname,
&suffix, &mode, &type))
return NULL;
- if (*mode && (*mode != 'r' || strchr(mode, '+') != NULL)) {
- PyErr_Format(PyExc_ValueError,
- "invalid file open mode %.200s", mode);
- return NULL;
+ if (*mode &&
+ !(*mode == 'r' || *mode == 'U' || strchr(mode, '+'))) {
+ PyErr_Format(PyExc_ValueError,
+ "invalid file open mode %.200s", mode);
+ return NULL;
}
if (fob == Py_None)
fp = NULL;