diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-10 08:53:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 08:53:09 (GMT) |
commit | 8510f430781118d9b603c3a2f06945d6ebc5fe42 (patch) | |
tree | 511cb42b478dd031ff36297a5e0c78b27a4e77a2 /Modules/getpath.c | |
parent | 700cb587303461d5a96456c56902cfdd8ad50e2d (diff) | |
download | cpython-8510f430781118d9b603c3a2f06945d6ebc5fe42.zip cpython-8510f430781118d9b603c3a2f06945d6ebc5fe42.tar.gz cpython-8510f430781118d9b603c3a2f06945d6ebc5fe42.tar.bz2 |
bpo-1294959: Add sys.platlibdir attribute (GH-18381)
Add --with-platlibdir option to the configure script: name of the
platform-specific library directory, stored in the new sys.platlitdir
attribute. It is used to build the path of platform-specific dynamic
libraries and the path of the standard library.
It is equal to "lib" on most platforms. On Fedora and SuSE, it is
equal to "lib64" on 64-bit systems.
Co-Authored-By: Jan Matějek <jmatejek@suse.com>
Co-Authored-By: Matěj Cepl <mcepl@cepl.eu>
Co-Authored-By: Charalampos Stratakis <cstratak@redhat.com>
Diffstat (limited to 'Modules/getpath.c')
-rw-r--r-- | Modules/getpath.c | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c index 8632d1f..e97ea8b 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -105,8 +105,9 @@ extern "C" { #endif -#if !defined(PREFIX) || !defined(EXEC_PREFIX) || !defined(VERSION) || !defined(VPATH) -#error "PREFIX, EXEC_PREFIX, VERSION, and VPATH must be constant defined" +#if (!defined(PREFIX) || !defined(EXEC_PREFIX) \ + || !defined(VERSION) || !defined(VPATH) || !defined(PLATLIBDIR)) +#error "PREFIX, EXEC_PREFIX, VERSION, VPATH and PLATLIBDIR macros must be defined" #endif #ifndef LANDMARK @@ -128,6 +129,7 @@ typedef struct { wchar_t *pythonpath_macro; /* PYTHONPATH macro */ wchar_t *prefix_macro; /* PREFIX macro */ wchar_t *exec_prefix_macro; /* EXEC_PREFIX macro */ + wchar_t *platlibdir_macro; /* PLATLIBDIR macro */ wchar_t *vpath_macro; /* VPATH macro */ wchar_t *lib_python; /* "lib/pythonX.Y" */ @@ -809,8 +811,17 @@ calculate_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig) "Could not find platform dependent libraries <exec_prefix>\n"); } + /* <PLATLIBDIR> / "lib-dynload" */ + wchar_t *lib_dynload = joinpath2(calculate->platlibdir_macro, + L"lib-dynload"); + if (lib_dynload == NULL) { + return _PyStatus_NO_MEMORY(); + } + calculate->exec_prefix = joinpath2(calculate->exec_prefix_macro, - L"lib/lib-dynload"); + lib_dynload); + PyMem_RawFree(lib_dynload); + if (calculate->exec_prefix == NULL) { return _PyStatus_NO_MEMORY(); } @@ -1284,27 +1295,35 @@ calculate_read_pyenv(PyCalculatePath *calculate) static PyStatus calculate_zip_path(PyCalculatePath *calculate) { - const wchar_t *lib_python = L"lib/python00.zip"; + PyStatus res; + + /* Path: <PLATLIBDIR> / "python00.zip" */ + wchar_t *path = joinpath2(calculate->platlibdir_macro, L"python00.zip"); + if (path == NULL) { + return _PyStatus_NO_MEMORY(); + } if (calculate->prefix_found > 0) { /* Use the reduced prefix returned by Py_GetPrefix() - Path: <basename(basename(prefix))> / <lib_python> */ + Path: <basename(basename(prefix))> / <PLATLIBDIR> / "python00.zip" */ wchar_t *parent = _PyMem_RawWcsdup(calculate->prefix); if (parent == NULL) { - return _PyStatus_NO_MEMORY(); + res = _PyStatus_NO_MEMORY(); + goto done; } reduce(parent); reduce(parent); - calculate->zip_path = joinpath2(parent, lib_python); + calculate->zip_path = joinpath2(parent, path); PyMem_RawFree(parent); } else { - calculate->zip_path = joinpath2(calculate->prefix_macro, lib_python); + calculate->zip_path = joinpath2(calculate->prefix_macro, path); } if (calculate->zip_path == NULL) { - return _PyStatus_NO_MEMORY(); + res = _PyStatus_NO_MEMORY(); + goto done; } /* Replace "00" with version */ @@ -1312,7 +1331,11 @@ calculate_zip_path(PyCalculatePath *calculate) calculate->zip_path[len - 6] = VERSION[0]; calculate->zip_path[len - 5] = VERSION[2]; - return _PyStatus_OK(); + res = _PyStatus_OK(); + +done: + PyMem_RawFree(path); + return res; } @@ -1434,10 +1457,14 @@ calculate_init(PyCalculatePath *calculate, const PyConfig *config) if (!calculate->vpath_macro) { return DECODE_LOCALE_ERR("VPATH macro", len); } + calculate->platlibdir_macro = Py_DecodeLocale(PLATLIBDIR, &len); + if (!calculate->platlibdir_macro) { + return DECODE_LOCALE_ERR("PLATLIBDIR macro", len); + } - calculate->lib_python = Py_DecodeLocale("lib/python" VERSION, &len); + calculate->lib_python = Py_DecodeLocale(PLATLIBDIR "/python" VERSION, &len); if (!calculate->lib_python) { - return DECODE_LOCALE_ERR("EXEC_PREFIX macro", len); + return DECODE_LOCALE_ERR("VERSION macro", len); } calculate->warnings = config->pathconfig_warnings; @@ -1454,6 +1481,7 @@ calculate_free(PyCalculatePath *calculate) PyMem_RawFree(calculate->prefix_macro); PyMem_RawFree(calculate->exec_prefix_macro); PyMem_RawFree(calculate->vpath_macro); + PyMem_RawFree(calculate->platlibdir_macro); PyMem_RawFree(calculate->lib_python); PyMem_RawFree(calculate->path_env); PyMem_RawFree(calculate->zip_path); |