diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-06-11 17:40:47 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-06-11 17:40:47 (GMT) |
commit | f1ca0b11b5a86b5b62f51d3ae75fdddb7d1df742 (patch) | |
tree | 70403992d17ebe2a89d9c168c5b264456d18b8b8 /Python/import.c | |
parent | c354c2e6ef54ffc33080323e79c8b0c5e6783dc9 (diff) | |
download | cpython-f1ca0b11b5a86b5b62f51d3ae75fdddb7d1df742.zip cpython-f1ca0b11b5a86b5b62f51d3ae75fdddb7d1df742.tar.gz cpython-f1ca0b11b5a86b5b62f51d3ae75fdddb7d1df742.tar.bz2 |
Issue 1342: Python could not start if installed in a directory
with non-ascii characters.
This is the simple fix, which uses the FileSystemEncoding.
Replacing all the char* with unicode strings is a major rewrite,
and needs more thinking.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Python/import.c b/Python/import.c index dadae2e..14cda6e 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1364,19 +1364,26 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, if (!v) return NULL; if (PyUnicode_Check(v)) { - v = _PyUnicode_AsDefaultEncodedString(v, NULL); + v = PyUnicode_AsEncodedString(v, + Py_FileSystemDefaultEncoding, NULL); if (v == NULL) return NULL; } - if (!PyBytes_Check(v)) + else if (!PyBytes_Check(v)) continue; + else + Py_INCREF(v); + base = PyBytes_AS_STRING(v); size = PyBytes_GET_SIZE(v); len = size; if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) { + Py_DECREF(v); continue; /* Too long */ } strcpy(buf, base); + Py_DECREF(v); + if (strlen(buf) != len) { continue; /* v contains '\0' */ } @@ -3155,8 +3162,8 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds) if (!_PyArg_NoKeywords("NullImporter()", kwds)) return -1; - if (!PyArg_ParseTuple(args, "s:NullImporter", - &path)) + if (!PyArg_ParseTuple(args, "es:NullImporter", + Py_FileSystemDefaultEncoding, &path)) return -1; pathlen = strlen(path); |