diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2021-09-28 18:18:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 18:18:28 (GMT) |
commit | 0c50b8c0b8274d54d6b71ed7bd21057d3642f138 (patch) | |
tree | ed77a5e7e69302e88349da50c5473c1aa7397d00 /PC | |
parent | 84975146a7ce64f1d50dcec8311b7f7188a5c962 (diff) | |
download | cpython-0c50b8c0b8274d54d6b71ed7bd21057d3642f138.zip cpython-0c50b8c0b8274d54d6b71ed7bd21057d3642f138.tar.gz cpython-0c50b8c0b8274d54d6b71ed7bd21057d3642f138.tar.bz2 |
bpo-45211: Remember the stdlib dir during startup. (gh-28586)
During runtime startup we figure out the stdlib dir but currently throw that information away. This change preserves it and exposes it via PyConfig.stdlib_dir, _Py_GetStdlibDir(), and sys._stdlib_dir.
https://bugs.python.org/issue45211
Diffstat (limited to 'PC')
-rw-r--r-- | PC/getpathp.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c index 3800946..16bb499 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -116,6 +116,8 @@ * with a semicolon separated path prior to calling Py_Initialize. */ +#define STDLIB_SUBDIR L"lib" + #define INIT_ERR_BUFFER_OVERFLOW() _PyStatus_ERR("buffer overflow") @@ -293,12 +295,12 @@ search_for_prefix(wchar_t *prefix, const wchar_t *argv0_path) wcscpy_s(stdlibdir, Py_ARRAY_LENGTH(stdlibdir), prefix); /* We initialize with the longest possible path, in case it doesn't fit. This also gives us an initial SEP at stdlibdir[wcslen(prefix)]. */ - join(stdlibdir, L"lib"); + join(stdlibdir, STDLIB_SUBDIR); do { assert(stdlibdir[wcslen(prefix)] == SEP); /* Due to reduce() and our initial value, this result is guaranteed to fit. */ - wcscpy(&stdlibdir[wcslen(prefix) + 1], L"lib"); + wcscpy(&stdlibdir[wcslen(prefix) + 1], STDLIB_SUBDIR); if (is_stdlibdir(stdlibdir)) { return 1; } @@ -1013,6 +1015,12 @@ calculate_path(PyCalculatePath *calculate, _PyPathConfig *pathconfig) } done: + if (pathconfig->stdlib_dir == NULL) { + pathconfig->stdlib_dir = _Py_join_relfile(prefix, STDLIB_SUBDIR); + if (pathconfig->stdlib_dir == NULL) { + return _PyStatus_NO_MEMORY(); + } + } if (pathconfig->prefix == NULL) { pathconfig->prefix = _PyMem_RawWcsdup(prefix); if (pathconfig->prefix == NULL) { |