summaryrefslogtreecommitdiff
path: root/Python/import.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-04 00:41:39 +0000
committerGuido van Rossum <guido@python.org>2007-05-04 00:41:39 +0000
commit68498a9a6c3cba8f728fd01b38f012000fce8ead (patch)
treec21ff7d9e27cde6ac8c59fd993b56946830eabf2 /Python/import.c
parent5673df5bcd2d66d03f077b9eeb27c3261047b19b (diff)
downloadcpython-68498a9a6c3cba8f728fd01b38f012000fce8ead.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.c22
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;