diff options
author | Guido van Rossum <guido@python.org> | 2009-03-30 22:01:35 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2009-03-30 22:01:35 (GMT) |
commit | 0ad59d467d06c8c9dce81658f4f278783cb70b9f (patch) | |
tree | ca638bf1bcfbb669d1cbfaa899fe0831990b86c4 /Python/import.c | |
parent | eaaec27b6ed3e01675af083fa9c6c1687c1b3847 (diff) | |
download | cpython-0ad59d467d06c8c9dce81658f4f278783cb70b9f.zip cpython-0ad59d467d06c8c9dce81658f4f278783cb70b9f.tar.gz cpython-0ad59d467d06c8c9dce81658f4f278783cb70b9f.tar.bz2 |
Issue #5604: non-ASCII characters in module name passed to
imp.find_module() were converted to UTF-8 while the path is
converted to the default filesystem encoding, causing nonsense.
Thanks to Andrew Svetlov.
(This time to the right branch. Will block duplicate merge to 3.0.2.)
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/Python/import.c b/Python/import.c index 9c70ed8..2be3308 100644 --- a/Python/import.c +++ b/Python/import.c @@ -3040,15 +3040,20 @@ imp_load_compiled(PyObject *self, PyObject *args) PyObject *fob = NULL; PyObject *m; FILE *fp; - if (!PyArg_ParseTuple(args, "ss|O:load_compiled", - &name, &pathname, &fob)) + if (!PyArg_ParseTuple(args, "ses|O:load_compiled", + &name, + Py_FileSystemDefaultEncoding, &pathname, + &fob)) return NULL; fp = get_file(pathname, fob, "rb"); - if (fp == NULL) + if (fp == NULL) { + PyMem_Free(pathname); return NULL; + } m = load_compiled_module(name, pathname, fp); if (fob == NULL) fclose(fp); + PyMem_Free(pathname); return m; } @@ -3062,15 +3067,20 @@ imp_load_dynamic(PyObject *self, PyObject *args) PyObject *fob = NULL; PyObject *m; FILE *fp = NULL; - if (!PyArg_ParseTuple(args, "ss|O:load_dynamic", - &name, &pathname, &fob)) + if (!PyArg_ParseTuple(args, "ses|O:load_dynamic", + &name, + Py_FileSystemDefaultEncoding, &pathname, + &fob)) return NULL; if (fob) { fp = get_file(pathname, fob, "r"); - if (fp == NULL) + if (fp == NULL) { + PyMem_Free(pathname); return NULL; + } } m = _PyImport_LoadDynamicModule(name, pathname, fp); + PyMem_Free(pathname); return m; } @@ -3084,12 +3094,16 @@ imp_load_source(PyObject *self, PyObject *args) PyObject *fob = NULL; PyObject *m; FILE *fp; - if (!PyArg_ParseTuple(args, "ss|O:load_source", - &name, &pathname, &fob)) + if (!PyArg_ParseTuple(args, "ses|O:load_source", + &name, + Py_FileSystemDefaultEncoding, &pathname, + &fob)) return NULL; fp = get_file(pathname, fob, "r"); - if (fp == NULL) + if (fp == NULL) { + PyMem_Free(pathname); return NULL; + } m = load_source_module(name, pathname, fp); if (fob == NULL) fclose(fp); @@ -3102,13 +3116,15 @@ imp_load_module(PyObject *self, PyObject *args) char *name; PyObject *fob; char *pathname; + PyObject * ret; char *suffix; /* Unused */ char *mode; int type; FILE *fp; - if (!PyArg_ParseTuple(args, "sOs(ssi):load_module", - &name, &fob, &pathname, + if (!PyArg_ParseTuple(args, "sOes(ssi):load_module", + &name, &fob, + Py_FileSystemDefaultEncoding, &pathname, &suffix, &mode, &type)) return NULL; if (*mode) { @@ -3119,6 +3135,7 @@ imp_load_module(PyObject *self, PyObject *args) if (!(*mode == 'r' || *mode == 'U') || strchr(mode, '+')) { PyErr_Format(PyExc_ValueError, "invalid file open mode %.200s", mode); + PyMem_Free(pathname); return NULL; } } @@ -3126,10 +3143,14 @@ imp_load_module(PyObject *self, PyObject *args) fp = NULL; else { fp = get_file(NULL, fob, mode); - if (fp == NULL) + if (fp == NULL) { + PyMem_Free(pathname); return NULL; - } - return load_module(name, fp, pathname, type, NULL); + } + } + ret = load_module(name, fp, pathname, type, NULL); + PyMem_Free(pathname); + return ret; } static PyObject * @@ -3137,9 +3158,13 @@ imp_load_package(PyObject *self, PyObject *args) { char *name; char *pathname; - if (!PyArg_ParseTuple(args, "ss:load_package", &name, &pathname)) + PyObject * ret; + if (!PyArg_ParseTuple(args, "ses:load_package", + &name, Py_FileSystemDefaultEncoding, &pathname)) return NULL; - return load_package(name, pathname); + ret = load_package(name, pathname); + PyMem_Free(pathname); + return ret; } static PyObject * |