blob: d4f7ab8a95ca129ae0530c29261cdc7c555f8347 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
http://bugs.python.org/issue17797
http://connect.microsoft.com/VisualStudio/feedback/details/785119/
Visual Studio 2012 changed return value for fileno function that breaks
when python tries to check/setup stdin/out/err
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
+++ python3/Python/pythonrun.c 2014-05-24 16:37:38.424159100 +0200
@@ -1036,7 +1036,15 @@
int status = 0, fd;
PyObject * encoding_attr;
char *encoding = NULL, *errors;
-
+#ifdef MS_WINDOWS
+ OSVERSIONINFOEX osvi;
+ BOOL bIsWindowsXP;
+
+ ZeroMemory(&osvi, sizeof(osvi));
+ osvi.dwOSVersionInfoSize = sizeof(osvi);
+ GetVersionEx(&osvi);
+ bIsWindowsXP = (osvi.dwMajorVersion < 6);
+#endif
/* Hack to avoid a nasty recursion issue when Python is invoked
in verbose mode: pre-import the Latin-1 and UTF-8 codecs */
if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) {
@@ -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
if (!is_valid_fd(fd)) {
+#endif
std = Py_None;
Py_INCREF(std);
}
@@ -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);
}
|