summaryrefslogtreecommitdiff
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2007-01-23 13:42:00 +0000
committerThomas Wouters <thomas@python.org>2007-01-23 13:42:00 +0000
commitafea529088d6447b1fc46318bdeec7c5de875202 (patch)
tree45ea7de7b5a460a0badf6e67fdd2ee766cba3b7f /Python/sysmodule.c
parentd2e22903d353e8037b0e448a976052886f75f4df (diff)
downloadcpython-git-afea529088d6447b1fc46318bdeec7c5de875202.tar.gz
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....)
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 4970adff50..59f6cfc684 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1087,17 +1087,17 @@ _PySys_Init(void)
if (PyErr_Occurred())
return NULL;
#ifdef MS_WINDOWS
- if(isatty(_fileno(stdin))){
+ if(isatty(_fileno(stdin)) && PyFile_Check(sysin)) {
sprintf(buf, "cp%d", GetConsoleCP());
if (!PyFile_SetEncoding(sysin, buf))
return NULL;
}
- if(isatty(_fileno(stdout))) {
+ if(isatty(_fileno(stdout)) && PyFile_Check(sysout)) {
sprintf(buf, "cp%d", GetConsoleOutputCP());
if (!PyFile_SetEncoding(sysout, buf))
return NULL;
}
- if(isatty(_fileno(stderr))) {
+ if(isatty(_fileno(stderr)) && PyFile_Check(syserr)) {
sprintf(buf, "cp%d", GetConsoleOutputCP());
if (!PyFile_SetEncoding(syserr, buf))
return NULL;