Skip to content

bpo-40947: getpath.c uses PyConfig.platlibdir #20807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ def test_attributes(self):
self.assertIsInstance(sys.platform, str)
self.assertIsInstance(sys.prefix, str)
self.assertIsInstance(sys.base_prefix, str)
self.assertIsInstance(sys.platlibdir, str)
self.assertIsInstance(sys.version, str)
vi = sys.version_info
self.assertIsInstance(vi[:], tuple)
Expand Down
2 changes: 0 additions & 2 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,6 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
-DEXEC_PREFIX='"$(exec_prefix)"' \
-DVERSION='"$(VERSION)"' \
-DVPATH='"$(VPATH)"' \
-DPLATLIBDIR='"$(PLATLIBDIR)"' \
-o $@ $(srcdir)/Modules/getpath.c

Programs/python.o: $(srcdir)/Programs/python.c
Expand Down Expand Up @@ -807,7 +806,6 @@ Python/dynload_hpux.o: $(srcdir)/Python/dynload_hpux.c Makefile
Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile $(srcdir)/Include/pydtrace.h
$(CC) -c $(PY_CORE_CFLAGS) \
-DABIFLAGS='"$(ABIFLAGS)"' \
-DPLATLIBDIR='"$(PLATLIBDIR)"' \
$(MULTIARCH_CPPFLAGS) \
-o $@ $(srcdir)/Python/sysmodule.c

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The Python :ref:`Path Configuration <init-path-config>` now takes
:c:member:`PyConfig.platlibdir` in account.
31 changes: 20 additions & 11 deletions Modules/getpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ typedef struct {
wchar_t *exec_prefix_macro; /* EXEC_PREFIX macro */
wchar_t *vpath_macro; /* VPATH macro */

wchar_t *lib_python; /* "lib/pythonX.Y" */
wchar_t *lib_python; /* <platlibdir> / "pythonX.Y" */

int prefix_found; /* found platform independent libraries? */
int exec_prefix_found; /* found the platform dependent libraries? */
Expand Down Expand Up @@ -810,7 +810,7 @@ calculate_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig)
"Could not find platform dependent libraries <exec_prefix>\n");
}

/* <PLATLIBDIR> / "lib-dynload" */
/* <platlibdir> / "lib-dynload" */
wchar_t *lib_dynload = joinpath2(calculate->platlibdir,
L"lib-dynload");
if (lib_dynload == NULL) {
Expand Down Expand Up @@ -1296,16 +1296,18 @@ calculate_zip_path(PyCalculatePath *calculate)
{
PyStatus res;

/* Path: <PLATLIBDIR> / "pythonXY.zip" */
wchar_t *path = joinpath2(calculate->platlibdir, L"python" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) L".zip");
/* Path: <platlibdir> / "pythonXY.zip" */
wchar_t *path = joinpath2(calculate->platlibdir,
L"python" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION)
L".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))> / <PLATLIBDIR> / "pythonXY.zip" */
Path: <basename(basename(prefix))> / <platlibdir> / "pythonXY.zip" */
wchar_t *parent = _PyMem_RawWcsdup(calculate->prefix);
if (parent == NULL) {
res = _PyStatus_NO_MEMORY();
Expand Down Expand Up @@ -1426,6 +1428,11 @@ static PyStatus
calculate_init(PyCalculatePath *calculate, const PyConfig *config)
{
size_t len;

calculate->warnings = config->pathconfig_warnings;
calculate->pythonpath_env = config->pythonpath_env;
calculate->platlibdir = config->platlibdir;

const char *path = getenv("PATH");
if (path) {
calculate->path_env = Py_DecodeLocale(path, &len);
Expand All @@ -1452,14 +1459,16 @@ calculate_init(PyCalculatePath *calculate, const PyConfig *config)
return DECODE_LOCALE_ERR("VPATH macro", len);
}

calculate->lib_python = Py_DecodeLocale(PLATLIBDIR "/python" VERSION, &len);
if (!calculate->lib_python) {
// <platlibdir> / "pythonX.Y"
wchar_t *pyversion = Py_DecodeLocale("python" VERSION, &len);
if (!pyversion) {
return DECODE_LOCALE_ERR("VERSION macro", len);
}

calculate->warnings = config->pathconfig_warnings;
calculate->pythonpath_env = config->pythonpath_env;
calculate->platlibdir = config->platlibdir;
calculate->lib_python = joinpath2(config->platlibdir, pyversion);
PyMem_RawFree(pyversion);
if (calculate->lib_python == NULL) {
return _PyStatus_NO_MEMORY();
}

return _PyStatus_OK();
}
Expand Down