diff options
author | Guido van Rossum <guido@python.org> | 2007-05-04 00:41:39 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-04 00:41:39 +0000 |
commit | f15a29f975bbdef6de0aa19a19b176d1baf8f5ab (patch) | |
tree | 60f4f72289129eaa808e05f2b7c7fb7bde077371 /Python/import.c | |
parent | bae5cedb8d41edc20bea54b8bff0c7f835de8043 (diff) | |
download | cpython-git-f15a29f975bbdef6de0aa19a19b176d1baf8f5ab.tar.gz |
More coding by random modification.
Encoding now return bytes instead of str8.
eval(), exec(), compile() now accept unicode or bytes.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/Python/import.c b/Python/import.c index 7e3d2f4695..2e1f894086 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1254,6 +1254,9 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, for (i = 0; i < npath; i++) { PyObject *copy = NULL; PyObject *v = PyList_GetItem(path, i); + PyObject *origv = v; + char *base; + Py_ssize_t size; if (!v) return NULL; if (PyUnicode_Check(v)) { @@ -1263,15 +1266,24 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, return NULL; v = copy; } - else - if (!PyString_Check(v)) + if (PyString_Check(v)) { + base = PyString_AS_STRING(v); + size = PyString_GET_SIZE(v); + } + else if (PyBytes_Check(v)) { + base = PyBytes_AS_STRING(v); + size = PyBytes_GET_SIZE(v); + } + else { + Py_XDECREF(copy); continue; - len = PyString_GET_SIZE(v); + } + len = size; if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) { Py_XDECREF(copy); continue; /* Too long */ } - strcpy(buf, PyString_AS_STRING(v)); + strcpy(buf, base); if (strlen(buf) != len) { Py_XDECREF(copy); continue; /* v contains '\0' */ @@ -1282,7 +1294,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, PyObject *importer; importer = get_path_importer(path_importer_cache, - path_hooks, v); + path_hooks, origv); if (importer == NULL) { Py_XDECREF(copy); return NULL; |