133 lines
3.8 KiB
Diff
133 lines
3.8 KiB
Diff
From b31b52e48af3922d36429a53c390699a113ecb60 Mon Sep 17 00:00:00 2001
|
|
From: Christoph Reiter <reiter.christoph@gmail.com>
|
|
Date: Thu, 22 Sep 2022 17:51:33 +0200
|
|
Subject: [PATCH 074/N] Don't change os.sep with an empty MSYSTEM env var,
|
|
not just a missing one
|
|
|
|
Up until now this didn't really happen when calling from cygwin
|
|
because empty env vars were removed before Python would run.
|
|
|
|
But https://github.com/msys2/msys2-runtime/pull/101 changed that.
|
|
|
|
To avoid breaking users that did something like
|
|
|
|
MSYSTEM= python ...
|
|
|
|
not only check that MSYSTEM isn't set but also that it isn't empty
|
|
when deciding if os.sep/os.altsep should be switched.
|
|
|
|
Also, guard the msystem env check to execute only on MINGW
|
|
|
|
Co-authored-by: Naveen M K <naveen521kk@gmail.com>
|
|
---
|
|
Lib/importlib/_bootstrap_external.py | 2 +-
|
|
Lib/ntpath.py | 2 +-
|
|
Python/pathconfig.c | 20 +++++++++++---------
|
|
mingw_smoketests.py | 2 +-
|
|
4 files changed, 14 insertions(+), 12 deletions(-)
|
|
|
|
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
|
|
index 1fbbc55..a177fa7 100644
|
|
--- a/Lib/importlib/_bootstrap_external.py
|
|
+++ b/Lib/importlib/_bootstrap_external.py
|
|
@@ -43,7 +43,7 @@ if _MS_WINDOWS:
|
|
else:
|
|
path_separators = ['/']
|
|
|
|
-if 'MSYSTEM' in _os.environ:
|
|
+if _os.environ.get('MSYSTEM', ''):
|
|
path_separators = path_separators[::-1]
|
|
|
|
# Assumption made in _path_join()
|
|
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
|
|
index f1d3333..1323ac2 100644
|
|
--- a/Lib/ntpath.py
|
|
+++ b/Lib/ntpath.py
|
|
@@ -21,7 +21,7 @@ import stat
|
|
import genericpath
|
|
from genericpath import *
|
|
|
|
-if sys.platform == "win32" and "MSYSTEM" in os.environ:
|
|
+if sys.platform == "win32" and os.environ.get("MSYSTEM", ""):
|
|
sep = '/'
|
|
altsep = '\\'
|
|
else:
|
|
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
|
|
index 3d684d6..1195a04 100644
|
|
--- a/Python/pathconfig.c
|
|
+++ b/Python/pathconfig.c
|
|
@@ -2,7 +2,7 @@
|
|
|
|
#include "Python.h"
|
|
#include "marshal.h" // PyMarshal_ReadObjectFromString
|
|
-#include "osdefs.h" // DELIM
|
|
+#include "osdefs.h" // DELIM, SEP
|
|
#include "pycore_initconfig.h"
|
|
#include "pycore_fileutils.h"
|
|
#include "pycore_pathconfig.h"
|
|
@@ -50,7 +50,6 @@ Py_StartsWithW(const wchar_t * str, const wchar_t * prefix)
|
|
char
|
|
Py_GetSepA(const char *name)
|
|
{
|
|
- char* msystem = (char*)2; /* So that non Windows use / as sep */
|
|
static char sep = '\0';
|
|
#ifdef _WIN32
|
|
/* https://msdn.microsoft.com/en-gb/library/windows/desktop/aa365247%28v=vs.85%29.aspx
|
|
@@ -65,12 +64,14 @@ Py_GetSepA(const char *name)
|
|
if (sep != '\0')
|
|
return sep;
|
|
#if defined(__MINGW32__)
|
|
- msystem = Py_GETENV("MSYSTEM");
|
|
-#endif
|
|
- if (msystem != NULL)
|
|
+ char* msystem = getenv("MSYSTEM");
|
|
+ if (msystem != NULL && strcmp(msystem, "") != 0)
|
|
sep = '/';
|
|
else
|
|
sep = '\\';
|
|
+#else
|
|
+ sep = SEP;
|
|
+#endif
|
|
return sep;
|
|
}
|
|
|
|
@@ -103,7 +104,6 @@ Py_NormalizeSepsA(char *name)
|
|
wchar_t
|
|
Py_GetSepW(const wchar_t *name)
|
|
{
|
|
- char* msystem = (char*)2; /* So that non Windows use / as sep */
|
|
static wchar_t sep = L'\0';
|
|
#ifdef _WIN32
|
|
/* https://msdn.microsoft.com/en-gb/library/windows/desktop/aa365247%28v=vs.85%29.aspx
|
|
@@ -118,12 +118,14 @@ Py_GetSepW(const wchar_t *name)
|
|
if (sep != L'\0')
|
|
return sep;
|
|
#if defined(__MINGW32__)
|
|
- msystem = Py_GETENV("MSYSTEM");
|
|
-#endif
|
|
- if (msystem != NULL)
|
|
+ char* msystem = getenv("MSYSTEM");
|
|
+ if (msystem != NULL && strcmp(msystem, "") != 0)
|
|
sep = L'/';
|
|
else
|
|
sep = L'\\';
|
|
+#else
|
|
+ sep = SEP;
|
|
+#endif
|
|
return sep;
|
|
}
|
|
|
|
diff --git a/mingw_smoketests.py b/mingw_smoketests.py
|
|
index aa76659..2a8bd16 100644
|
|
--- a/mingw_smoketests.py
|
|
+++ b/mingw_smoketests.py
|
|
@@ -29,7 +29,7 @@ import os
|
|
import unittest
|
|
import sysconfig
|
|
|
|
-if "MSYSTEM" in os.environ:
|
|
+if os.environ.get("MSYSTEM", ""):
|
|
SEP = "/"
|
|
else:
|
|
SEP = "\\"
|