]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40947: getpath.c uses PyConfig.platlibdir (GH-20807)
authorVictor Stinner <vstinner@python.org>
Thu, 11 Jun 2020 15:28:52 +0000 (17:28 +0200)
committerGitHub <noreply@github.com>
Thu, 11 Jun 2020 15:28:52 +0000 (17:28 +0200)
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 <manisandro@gmail.com>
Lib/test/test_sys.py
Makefile.pre.in
Misc/NEWS.d/next/Core and Builtins/2020-06-11-16-06-49.bpo-40947.72cZcR.rst [new file with mode: 0644]
Modules/getpath.c

index 2f93eaae560db7e461b423bb085c8a7f55a9dd7b..194128e5c6bf27db0404da2972ced732e73b103e 100644 (file)
@@ -487,6 +487,7 @@ class SysModuleTest(unittest.TestCase):
         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)
index 9a82729aa0f210b34b691809bfc0203530b80793..5972dc7b4952263014e4a4035b2b0b18935dab54 100644 (file)
@@ -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
@@ -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
 
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-06-11-16-06-49.bpo-40947.72cZcR.rst b/Misc/NEWS.d/next/Core and Builtins/2020-06-11-16-06-49.bpo-40947.72cZcR.rst
new file mode 100644 (file)
index 0000000..e7dfe06
--- /dev/null
@@ -0,0 +1,2 @@
+The Python :ref:`Path Configuration <init-path-config>` now takes
+:c:member:`PyConfig.platlibdir` in account.
index 469c9ca010640f623d953df32ce5dcde3ef7b0c0..f7a6dd40443054b9ceb6991de5a4214c5912662d 100644 (file)
@@ -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? */
@@ -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) {
@@ -1296,8 +1296,10 @@ 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();
     }
@@ -1305,7 +1307,7 @@ calculate_zip_path(PyCalculatePath *calculate)
     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();
@@ -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);
@@ -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();
 }