Mercurial > cpython-lru_cache-weakref
diff Modules/getpath.c @ 63961:4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
at interpreter startup before importing any non-builtin modules.
Should fix #9589.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Fri, 13 Aug 2010 22:25:01 +0000 |
| parents | 8723c1dd1d25 |
| children | 7be5916333df |
line wrap: on
line diff
--- a/Modules/getpath.c Fri Aug 13 22:23:24 2010 +0000 +++ b/Modules/getpath.c Fri Aug 13 22:25:01 2010 +0000 @@ -394,12 +394,35 @@ return 1; } - /* Check to see if argv[0] is in the build directory */ + /* Check to see if argv[0] is in the build directory. "pybuilddir.txt" + is written by setup.py and contains the relative path to the location + of shared library modules. */ wcscpy(exec_prefix, argv0_path); - joinpath(exec_prefix, L"Modules/Setup"); + joinpath(exec_prefix, L"pybuilddir.txt"); if (isfile(exec_prefix)) { - reduce(exec_prefix); - return -1; + FILE *f = _Py_wfopen(exec_prefix, L"rb"); + if (f == NULL) + errno = 0; + else { + char buf[MAXPATHLEN+1]; + PyObject *decoded; + wchar_t rel_builddir_path[MAXPATHLEN+1]; + size_t n; + n = fread(buf, 1, MAXPATHLEN, f); + buf[n] = '\0'; + fclose(f); + decoded = PyUnicode_DecodeUTF8(buf, n, "surrogateescape"); + if (decoded != NULL) { + n = PyUnicode_AsWideChar(decoded, rel_builddir_path, MAXPATHLEN); + Py_DECREF(decoded); + if (n >= 0) { + rel_builddir_path[n] = L'\0'; + wcscpy(exec_prefix, argv0_path); + joinpath(exec_prefix, rel_builddir_path); + return -1; + } + } + } } /* Search from argv0_path, until root is found */
