Skip to content

Commit d72b964

Browse files
vstinnermanisandro
andauthored
bpo-40947: getpath.c uses PyConfig.platlibdir (GH-20807)
Followup of bpo-40854, there is one remaining usage of PLATLIBDIR which should be replaced by config->platlibdir. test_sys checks that sys.platlibdir attribute exists and is a string. Update Makefile: getpath.c and sysmodule.c no longer need PLATLIBDIR macro, PyConfig.platlibdir member is used instead. Co-authored-by: Sandro Mani <[email protected]>
1 parent b2dca49 commit d72b964

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

Lib/test/test_sys.py

+1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ def test_attributes(self):
487487
self.assertIsInstance(sys.platform, str)
488488
self.assertIsInstance(sys.prefix, str)
489489
self.assertIsInstance(sys.base_prefix, str)
490+
self.assertIsInstance(sys.platlibdir, str)
490491
self.assertIsInstance(sys.version, str)
491492
vi = sys.version_info
492493
self.assertIsInstance(vi[:], tuple)

Makefile.pre.in

-2
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,6 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
775775
-DEXEC_PREFIX='"$(exec_prefix)"' \
776776
-DVERSION='"$(VERSION)"' \
777777
-DVPATH='"$(VPATH)"' \
778-
-DPLATLIBDIR='"$(PLATLIBDIR)"' \
779778
-o $@ $(srcdir)/Modules/getpath.c
780779

781780
Programs/python.o: $(srcdir)/Programs/python.c
@@ -807,7 +806,6 @@ Python/dynload_hpux.o: $(srcdir)/Python/dynload_hpux.c Makefile
807806
Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile $(srcdir)/Include/pydtrace.h
808807
$(CC) -c $(PY_CORE_CFLAGS) \
809808
-DABIFLAGS='"$(ABIFLAGS)"' \
810-
-DPLATLIBDIR='"$(PLATLIBDIR)"' \
811809
$(MULTIARCH_CPPFLAGS) \
812810
-o $@ $(srcdir)/Python/sysmodule.c
813811

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The Python :ref:`Path Configuration <init-path-config>` now takes
2+
:c:member:`PyConfig.platlibdir` in account.

Modules/getpath.c

+20-11
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ typedef struct {
130130
wchar_t *exec_prefix_macro; /* EXEC_PREFIX macro */
131131
wchar_t *vpath_macro; /* VPATH macro */
132132

133-
wchar_t *lib_python; /* "lib/pythonX.Y" */
133+
wchar_t *lib_python; /* <platlibdir> / "pythonX.Y" */
134134

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

813-
/* <PLATLIBDIR> / "lib-dynload" */
813+
/* <platlibdir> / "lib-dynload" */
814814
wchar_t *lib_dynload = joinpath2(calculate->platlibdir,
815815
L"lib-dynload");
816816
if (lib_dynload == NULL) {
@@ -1296,16 +1296,18 @@ calculate_zip_path(PyCalculatePath *calculate)
12961296
{
12971297
PyStatus res;
12981298

1299-
/* Path: <PLATLIBDIR> / "pythonXY.zip" */
1300-
wchar_t *path = joinpath2(calculate->platlibdir, L"python" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) L".zip");
1299+
/* Path: <platlibdir> / "pythonXY.zip" */
1300+
wchar_t *path = joinpath2(calculate->platlibdir,
1301+
L"python" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION)
1302+
L".zip");
13011303
if (path == NULL) {
13021304
return _PyStatus_NO_MEMORY();
13031305
}
13041306

13051307
if (calculate->prefix_found > 0) {
13061308
/* Use the reduced prefix returned by Py_GetPrefix()
13071309
1308-
Path: <basename(basename(prefix))> / <PLATLIBDIR> / "pythonXY.zip" */
1310+
Path: <basename(basename(prefix))> / <platlibdir> / "pythonXY.zip" */
13091311
wchar_t *parent = _PyMem_RawWcsdup(calculate->prefix);
13101312
if (parent == NULL) {
13111313
res = _PyStatus_NO_MEMORY();
@@ -1426,6 +1428,11 @@ static PyStatus
14261428
calculate_init(PyCalculatePath *calculate, const PyConfig *config)
14271429
{
14281430
size_t len;
1431+
1432+
calculate->warnings = config->pathconfig_warnings;
1433+
calculate->pythonpath_env = config->pythonpath_env;
1434+
calculate->platlibdir = config->platlibdir;
1435+
14291436
const char *path = getenv("PATH");
14301437
if (path) {
14311438
calculate->path_env = Py_DecodeLocale(path, &len);
@@ -1452,14 +1459,16 @@ calculate_init(PyCalculatePath *calculate, const PyConfig *config)
14521459
return DECODE_LOCALE_ERR("VPATH macro", len);
14531460
}
14541461

1455-
calculate->lib_python = Py_DecodeLocale(PLATLIBDIR "/python" VERSION, &len);
1456-
if (!calculate->lib_python) {
1462+
// <platlibdir> / "pythonX.Y"
1463+
wchar_t *pyversion = Py_DecodeLocale("python" VERSION, &len);
1464+
if (!pyversion) {
14571465
return DECODE_LOCALE_ERR("VERSION macro", len);
14581466
}
1459-
1460-
calculate->warnings = config->pathconfig_warnings;
1461-
calculate->pythonpath_env = config->pythonpath_env;
1462-
calculate->platlibdir = config->platlibdir;
1467+
calculate->lib_python = joinpath2(config->platlibdir, pyversion);
1468+
PyMem_RawFree(pyversion);
1469+
if (calculate->lib_python == NULL) {
1470+
return _PyStatus_NO_MEMORY();
1471+
}
14631472

14641473
return _PyStatus_OK();
14651474
}

0 commit comments

Comments
 (0)