Kaydet (Commit) be3e1d65 authored tarafından Michael Stahl's avatar Michael Stahl

tdf#82968: python3: fix stdio detection on WNT harder

Upgrade to the latest patch from http://bugs.python.org/issue17797
which appears to work even if you invoke from cmd.exe

Change-Id: I85f1cc5ad7d8c059d972ae2a6fd2be1bb5604c2c
üst 0aa2fd97
...@@ -4,59 +4,42 @@ http://connect.microsoft.com/VisualStudio/feedback/details/785119/ ...@@ -4,59 +4,42 @@ http://connect.microsoft.com/VisualStudio/feedback/details/785119/
Visual Studio 2012 changed return value for fileno function that breaks Visual Studio 2012 changed return value for fileno function that breaks
when python tries to check/setup stdin/out/err when python tries to check/setup stdin/out/err
GetStdHandle on Windows XP behaves contrary to the documentation... GetStdHandle on Windows XP behaves contrary to the documentation...
diff -ur python3.org/Python/pythonrun.c python3/Python/pythonrun.c
--- python3.org/Python/pythonrun.c 2014-05-24 16:36:20.361672900 +0200 diff --git a/Python/pythonrun.c b/Python/pythonrun.c
+++ python3/Python/pythonrun.c 2014-05-24 16:37:38.424159100 +0200 index 91d56b7..d28ffc7 100644
@@ -1036,7 +1036,15 @@ --- a/Python/pythonrun.c
int status = 0, fd; +++ b/Python/pythonrun.c
PyObject * encoding_attr; @@ -1015,13 +1015,28 @@ error:
char *encoding = NULL, *errors; static int
- is_valid_fd(int fd)
+#ifdef MS_WINDOWS {
+ OSVERSIONINFOEX osvi; - int dummy_fd;
+ BOOL bIsWindowsXP; if (fd < 0 || !_PyVerify_fd(fd))
return 0;
- dummy_fd = dup(fd);
- if (dummy_fd < 0)
- return 0;
- close(dummy_fd);
+ +
+ ZeroMemory(&osvi, sizeof(osvi)); +#if defined(MS_WINDOWS) && defined(HAVE_FSTAT)
+ osvi.dwOSVersionInfoSize = sizeof(osvi); + /* dup (DuplicateHandle) doesn't say fd is a valid *file* handle.
+ GetVersionEx(&osvi); + * It could be a current thread pseudo-handle.
+ bIsWindowsXP = (osvi.dwMajorVersion < 6); + */
+#endif + {
/* Hack to avoid a nasty recursion issue when Python is invoked + struct stat buf;
in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ + if (fstat(fd, &buf) < 0 && (errno == EBADF || errno == ENOENT))
if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) { + return 0;
@@ -1084,7 +1092,11 @@ + }
* and fileno() may point to an invalid file descriptor. For example
* GUI apps don't have valid standard streams by default.
*/
+#ifdef MS_WINDOWS
+ if (!is_valid_fd(fd) || GetStdHandle(STD_INPUT_HANDLE) == NULL || bIsWindowsXP) {
+#else +#else
if (!is_valid_fd(fd)) { + {
+ int dummy_fd;
+ dummy_fd = dup(fd);
+ if (dummy_fd < 0)
+ return 0;
+ close(dummy_fd);
+ }
+#endif +#endif
std = Py_None; +
Py_INCREF(std); return 1;
} }
@@ -1099,7 +1111,11 @@
/* Set sys.stdout */
fd = fileno(stdout);
+#ifdef MS_WINDOWS
+ if (!is_valid_fd(fd) || GetStdHandle(STD_OUTPUT_HANDLE) == NULL || bIsWindowsXP) {
+#else
if (!is_valid_fd(fd)) {
+#endif
std = Py_None;
Py_INCREF(std);
}
@@ -1115,7 +1131,11 @@
#if 1 /* Disable this if you have trouble debugging bootstrap stuff */
/* Set sys.stderr, replaces the preliminary stderr */
fd = fileno(stderr);
+#ifdef MS_WINDOWS
+ if (!is_valid_fd(fd) || GetStdHandle(STD_ERROR_HANDLE) == NULL || bIsWindowsXP) {
+#else
if (!is_valid_fd(fd)) {
+#endif
std = Py_None;
Py_INCREF(std);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment