diff Python/sysmodule.c @ 40702:6860ba88d67e 2.4

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 15:09:19 +0000
parents ab13576374b1
children
line wrap: on
line diff
--- a/Python/sysmodule.c	Thu Jan 11 20:26:05 2007 +0000
+++ b/Python/sysmodule.c	Tue Jan 23 15:09:19 2007 +0000
@@ -972,12 +972,12 @@
 	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;