comparison Python/sysmodule.c @ 40701:da30a26dfeb3 2.5

Backport trunk revision 53527: SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize When running the interpreter in an environment that would cause it to set stdout/stderr/stdin's encoding, having a sitecustomize that would replace them with something other than PyFile objects would crash the interpreter. Fix it by simply ignoring the encoding-setting for non-files. This could do with a test, but I can think of no maintainable and portable way to test this bug, short of adding a sitecustomize.py to the buildsystem and have it always run with it (hmmm....)
author Thomas Wouters <thomas@python.org>
date Tue, 23 Jan 2007 13:54:30 +0000
parents a1863833c4e6
children d67b5d953b45 31c92828aefb
comparison
equal deleted inserted replaced
40697:29b8b65bae3f 40701:da30a26dfeb3
1085 sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush); 1085 sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
1086 syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush); 1086 syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
1087 if (PyErr_Occurred()) 1087 if (PyErr_Occurred())
1088 return NULL; 1088 return NULL;
1089 #ifdef MS_WINDOWS 1089 #ifdef MS_WINDOWS
1090 if(isatty(_fileno(stdin))){ 1090 if(isatty(_fileno(stdin)) && PyFile_Check(sysin)) {
1091 sprintf(buf, "cp%d", GetConsoleCP()); 1091 sprintf(buf, "cp%d", GetConsoleCP());
1092 if (!PyFile_SetEncoding(sysin, buf)) 1092 if (!PyFile_SetEncoding(sysin, buf))
1093 return NULL; 1093 return NULL;
1094 } 1094 }
1095 if(isatty(_fileno(stdout))) { 1095 if(isatty(_fileno(stdout)) && PyFile_Check(sysout)) {
1096 sprintf(buf, "cp%d", GetConsoleOutputCP()); 1096 sprintf(buf, "cp%d", GetConsoleOutputCP());
1097 if (!PyFile_SetEncoding(sysout, buf)) 1097 if (!PyFile_SetEncoding(sysout, buf))
1098 return NULL; 1098 return NULL;
1099 } 1099 }
1100 if(isatty(_fileno(stderr))) { 1100 if(isatty(_fileno(stderr)) && PyFile_Check(syserr)) {
1101 sprintf(buf, "cp%d", GetConsoleOutputCP()); 1101 sprintf(buf, "cp%d", GetConsoleOutputCP());
1102 if (!PyFile_SetEncoding(syserr, buf)) 1102 if (!PyFile_SetEncoding(syserr, buf))
1103 return NULL; 1103 return NULL;
1104 } 1104 }
1105 #endif 1105 #endif