Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 73110:63ffa07f9258
Fix test_imp failure under Windows
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Tue, 25 Oct 2011 00:21:02 +0200 |
| parents | eef1027ab2f0 |
| children | a938d0258abe |
line wrap: on
line diff
--- a/Python/import.c Mon Oct 24 21:22:39 2011 +0300 +++ b/Python/import.c Tue Oct 25 00:21:02 2011 +0200 @@ -938,12 +938,19 @@ Py_ssize_t pycache_len = sizeof(CACHEDIR) - 1; int kind; void *data; + Py_UCS4 lastsep; /* Compute the output string size. */ len = PyUnicode_GET_LENGTH(pathstr); /* If there is no separator, this returns -1, so - lastsep will be 0. */ + fname will be 0. */ fname = rightmost_sep_obj(pathstr, 0, len) + 1; + /* Windows: re-use the last separator character (/ or \\) when + appending the __pycache__ path. */ + if (fname > 0) + lastsep = PyUnicode_READ_CHAR(pathstr, fname -1); + else + lastsep = SEP; ext = fname - 1; for(i = fname; i < len; i++) if (PyUnicode_READ_CHAR(pathstr, i) == '.') @@ -965,7 +972,7 @@ pos = fname; for (i = 0; i < pycache_len; i++) PyUnicode_WRITE(kind, data, pos++, CACHEDIR[i]); - PyUnicode_WRITE(kind, data, pos++, SEP); + PyUnicode_WRITE(kind, data, pos++, lastsep); PyUnicode_CopyCharacters(result, pos, pathstr, fname, ext - fname); pos += ext - fname;
