mirror of
https://github.com/python/cpython.git
synced 2024-11-27 20:04:41 +08:00
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.
This commit is contained in:
parent
40b7703f1c
commit
4ae6faed9f
@ -1040,16 +1040,18 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
|
|||||||
#endif /* PYOS_OS2 */
|
#endif /* PYOS_OS2 */
|
||||||
for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
|
for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
|
||||||
#if defined(PYOS_OS2)
|
#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
|
* so if the name is longer than that and its a
|
||||||
* dynamically loaded module we're going to try,
|
* dynamically loaded module we're going to try,
|
||||||
* truncate the name before trying
|
* truncate the name before trying
|
||||||
*/
|
*/
|
||||||
if (strlen(realname) > 8) {
|
if (strlen(realname) > 8) {
|
||||||
/* is this an attempt to load a C extension? */
|
/* 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) {
|
while (scan->suffix != NULL) {
|
||||||
if (strcmp(scan->suffix, fdp->suffix) == 0)
|
if (!strcmp(scan->suffix, fdp->suffix))
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
scan++;
|
scan++;
|
||||||
@ -1067,7 +1069,8 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
|
|||||||
PySys_WriteStderr("# trying %s\n", buf);
|
PySys_WriteStderr("# trying %s\n", buf);
|
||||||
#endif /* !macintosh */
|
#endif /* !macintosh */
|
||||||
filemode = fdp->mode;
|
filemode = fdp->mode;
|
||||||
if (filemode[0] == 'U') filemode = "r" PY_STDIOTEXTMODE;
|
if (filemode[0] == 'U')
|
||||||
|
filemode = "r" PY_STDIOTEXTMODE;
|
||||||
fp = fopen(buf, filemode);
|
fp = fopen(buf, filemode);
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
if (case_ok(buf, len, namelen, name))
|
if (case_ok(buf, len, namelen, name))
|
||||||
@ -2296,6 +2299,8 @@ get_file(char *pathname, PyObject *fob, char *mode)
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
if (fob == NULL) {
|
if (fob == NULL) {
|
||||||
|
if (mode[0] == 'U')
|
||||||
|
mode = "r" PY_STDIOTEXTMODE;
|
||||||
fp = fopen(pathname, mode);
|
fp = fopen(pathname, mode);
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
PyErr_SetFromErrno(PyExc_IOError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
@ -2403,10 +2408,11 @@ imp_load_module(PyObject *self, PyObject *args)
|
|||||||
&name, &fob, &pathname,
|
&name, &fob, &pathname,
|
||||||
&suffix, &mode, &type))
|
&suffix, &mode, &type))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (*mode && (*mode != 'r' || strchr(mode, '+') != NULL)) {
|
if (*mode &&
|
||||||
PyErr_Format(PyExc_ValueError,
|
!(*mode == 'r' || *mode == 'U' || strchr(mode, '+'))) {
|
||||||
"invalid file open mode %.200s", mode);
|
PyErr_Format(PyExc_ValueError,
|
||||||
return NULL;
|
"invalid file open mode %.200s", mode);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
if (fob == Py_None)
|
if (fob == Py_None)
|
||||||
fp = NULL;
|
fp = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user